Giter Club home page Giter Club logo

geometry2d's Introduction

Geometry 2D

A 2D geometry library supporting the following basic 2D primitive shapes:

Circles, Triangles, Infinite Lines, Line Segments, Quads, Polygons

All shapes are structs so there is little heap allocation except for Polygon type which uses a list.

Polymorphism is supported via interfaces. And intersections for each shape is also supported. Each shape also supports a variety of helpful functions.

Note: Naming convention does not follow standard C# convention. This is because I wrote a lot of this originally in HLSL and converted it to C#.

Demo

shapes.mp4

Functions supported

All geometry objects have the following functions:

  • Tangent -> Get the tangent vector nearest to the point
  • Normal -> Get the normal vector nearest to the point
  • Translate -> Move the position of the object
  • SetPosition -> Set the position of the object
  • Scale -> (Not including infinite lines)
  • Rotate -> Rotate the object
  • CalculateBounds -> Get the AABB bounds of the shape
  • OverlapsEdge -> Check if point overlaps an edge
  • SnapTo -> Snap a point to the nearest edge
  • CalculatePerimeter -> Calculate the perimeter of the line/shape
Lines have the following additional functions:
  • Lerp -> Interpolate along the line
  • InverseLerp -> Get the parameterised value from a point
  • IsBetween -> Is a point between the two end points of the line
  • Split -> Split the line into 2 lines
  • Slice -> Slice the line into multiple lines
  • Truncate -> Shorten the line
  • IsLeft -> Is a point left of the line
2DShapes have the following additional functions:
  • CalculateArea -> Calculate area of the shape
  • Overlaps -> Check if a point overlaps the shape

geometry2d's People

Contributors

davethecelt avatar thecelticguy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.