Circles, spheres and capsules. Most circle and sphere operations are just point operations with a bias to the distance, which is why relevant
"point" functions are included in this file.
typedef struct {
vec3 center;
float r;
} Sphere;
typedef struct {
vec3 a, b; // the two centroids
float r; // radius
} Capsule;
Not all distance and intersection functions have systematic names yet. In general, functions are named in the pattern
[operation][lesser]N[greater]N(l, g, [args], out*) where operation is something like dist or intersect, lesser is the argument with fewer
dimensions, greater is the argument with more dimensions, and N is the number of dimensions if otherwise unclear (lines and triangles can exist in
2 or 3 dimensions, for example, but spheres and circles imply their dimensionality). Functions with "T" in the name return a normalized value
along with whatever other results.
Primitives
- Line: An infinite line, unless otherwise specified, with no implied direction.
- Ray: A line with a start location that extends inifinitely in some specified direction.
- Rect: An axis-aligned rectangle defined by two opposing corners.
- Quad: An arbitrary quadrilateral in 2 or 3 dimensions defined by a loop of consecutive corners. May or may not need to be
planar or rectangular (right angles) depending on the function.
- Circle: A circle defined by a center and a radius in 2 dimensions.
- Plane: An infinite plane in 3 dimensions defined by a normal vector and a distance from the origin.
- PlaneP: An infinite plane in 3 dimensions defined by a normal vector and a point on the plane.
- Sphere: A sphere in 3 dimensions defined by a center and a radius.
- Capsule: A pill-shaped 3D object defined by the center points of the two connected end spheres and a radius.
Operation Stubs
- dist: Shortest distance between the two objects.
- intersect: Determines if the two objects intersect.
- findIntersect: Finds the point (or line) of intersection between two objects. Unless otherwise specified, it's the closest
point of intersection if there are multiple.
- proj: Projects the first object onto the second, whatever that means for the objects involved.
Functions
float distPoint2Triangle2(vec2 a, vec2 tri[3])
Two dimensional closest distance between a point a triangle.
int intersectPoint2Rect2(vec2 a, Quad2 q)
Must be a rectangle, not an arbitrary quadrilateral. Returns C3DLAS_INTERSECT or C3DLAS_DISJOINT.
float distPoint2Rect2(vec2 a, Quad2 q)
Quad must be a rectangle, and the vertices must be ordered in a loop
float distTPointRay3(vec3 p, Ray3 r, float* T)
float dist2TPointRay3(vec3 p, Ray3 r, float* T)
float distPoint2Line2(vec2 p, Line2 ls)
float distTPoint2Line2(vec2 p, Line2 ls)
float distPoint3Line3(vec3 p, Line3 ls)
float distTPoint3Line3(vec3 p, Line3 ls)
int intersectRay2Circle(Ray2 a, vec2 center, float radius, vec2 out[2])
Returns the number of intersecting points, [0-2], in both directions of the ray.
int intersectVec2Circle(vec2 lorigin, vec2 ldir, vec2 center, float radius, vec2 out[2])
Returns the number of intersecting points, [0-2], in both directions of the ray.
// circle utilities
int findCircleTangents(Vector2 c, float r, Vector2 p, Vector2 out[2]);
// returns the radius
float circleFromPoints(vec2 a, vec2 b, vec2 c, vec2* center);
// returns C3DLAS_INTERSECT or C3DLAS_DISJOINT
int pointInsideCircleFromPoints(vec2 p1, vec2 p2, vec2 p3, vec2 test);