|
|
Triangles are exclusively represented by three points, in 2 or 3 dimensions. There is no struct for them in c3dlas because triangles are usually stored
in specialized formats in real code.
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.
float distLine2Triangle2(Line2 a, vec2 tri[3])
// returns the *signed* area of a triangle. useful for determining winding
// positive values mean a clockwise triangle
float triArea2p(Vector2* a, Vector2* b, Vector2* c);
// determines if a point is inside a triangle
int triPointInside2p(Vector2* p, Vector2* a, Vector2* b, Vector2* c);
int triPointInside2(Vector2 p, Vector2 a, Vector2 b, Vector2 c);
// https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
// returns _INTERSECT or _DISJOINT
int rayTriangleIntersect(
Vector3* a, Vector3* b, Vector3* c, // triangle
Vector3* ray_origin, Vector3* ray_dir, // ray
float* u, float* v, float* t // barycentric out coords, t of intersection point along ray
);
Vector3 triangleClosestPoint(
Vector3* a, Vector3* b, Vector3* c, // triangle
Vector3* p, // test point
float* out_u, float* out_v // barycentric out coords of closest point
);
Vector3 triangleClosestPoint_Reference(
Vector3* a, Vector3* b, Vector3* c, // triangle
Vector3* p, // test point
float* out_u, float* out_v // barycentric out coords of closest point
);
Vector3 baryCoords2(Vector2 p, Vector2 a, Vector2 b, Vector2 c);
// C3DLAS_COPLANAR, _INTERSECT, or _DISJOINT
int triPlaneTestIntersect3p(Vector3* pTri, Plane* pl);
// C3DLAS_COPLANAR, _INTERSECT, or _DISJOINT
int triPlaneClip3p(
Vector3* pTri,
Plane* pl,
Vector3* aboveOut,
Vector3* belowOut,
int* aboveCnt,
int* belowCnt
);
void vTriFaceNormal3p(Vector3* a, Vector3* b, Vector3* c, Vector3* out); // returns a normalized face normal for the given triangle
Vector3 vTriFaceNormal3(Vector3 a, Vector3 b, Vector3 c);
void vpTriFaceNormal3p(Vector3* tri, Vector3* out); // returns a normalized face normal for the given triangle
Vector3 vTriFaceNormalArea3(Vector3 a, Vector3 b, Vector3 c, float* area); // also provides that triangle's area as a side product
|