Geometry Utility Manual
The geometryutils.h header file contains the maxon::GeometryUtilsInterface which includes various functions to handle vectors, lines, half-lines (rays), line segments and primitives like triangles and quads.
Angles between vectors can be calculated with:
Multiple points can define a triangle, a quad or an arbitrary shape.
Barycentric coordinates define the position of a point within a given triangle. The coordinates for a given point are calculated with:
The coordinates within a polygon are calculated with:
// triangle const maxon::Vector vertexA { 0, 0, 0 }; const maxon::Vector vertexB { 2, 0, 0 }; const maxon::Vector vertexC { 1, 2, 0 };
// point within the triangle const maxon::Vector point { 1, 1, 0 };
// get barycentrix coordinates const maxon::Vector res = maxon::GeometryUtilsInterface::CalculateBarycentricCoordinate3D (point, vertexA, vertexB, vertexC);
Bilinear interpolation allows to interpolate values in a two dimensional grid:
// color values const maxon::Vector red { 1.0, 0, 0 }; const maxon::Vector green { 0.0, 1.0, 0.0 }; const maxon::Vector blue { 0.0, 0.0, 1.0 }; const maxon::Vector white { 1.0 };
// get bilinear interpolation const maxon::Vector res = maxon::GeometryUtilsInterface::BilinearInterpolate (red, green, blue, white, s, t);
These functions allow to calculate the intersection of lines, half-lines, segments, triangles and quads.
Intersection of lines, half-lines, and sections with each other:
See also:
// check segment intersection maxon::Vector segIntersectPoint { maxon::DONT_INITIALIZE }; const maxon::Bool segementIntersection = maxon::GeometryUtilsInterface::IntersectSegments (pointA, pointB, pointC, pointD, segIntersectPoint); if (segementIntersection) DiagnosticOutput ( "Segments intersect at @" , segIntersectPoint);
// check line intersection maxon::Vector lineIntersectPoint { maxon::DONT_INITIALIZE }; const maxon::Bool lineIntersection = maxon::GeometryUtilsInterface::IntersectLines (pointA, pointB, pointC, pointD, lineIntersectPoint); if (lineIntersection) DiagnosticOutput ( "Line intersection at @" , lineIntersectPoint);
Intersection of lines, half-lines, and segments with planes:
// check line/plane intersection maxon::Vector linePlaneIntersectionPoint { maxon::DONT_INITIALIZE }; const maxon::Bool linePlaneIntersect = maxon::GeometryUtilsInterface::IntersectLinePlane (startPoint, lineDir, planePoint, planeNormal, linePlaneIntersectionPoint); if (linePlaneIntersect) DiagnosticOutput ( "Line intersects plane at @" , linePlaneIntersectionPoint);
// check half-line/plane intersection maxon::Vector halfLinePlaneIntersectPoint { maxon::DONT_INITIALIZE }; const maxon::Bool halfLinePlaneIntersect = maxon::GeometryUtilsInterface::IntersectHalfLinePlane (startPoint, lineDir, planePoint, planeNormal, halfLinePlaneIntersectPoint); if (halfLinePlaneIntersect) DiagnosticOutput ( "Half-line intersects plane at @" , halfLinePlaneIntersectPoint);
// check segment/plane intersection maxon::Vector segmentPlaneIntersectPoint { maxon::DONT_INITIALIZE }; const maxon::Bool segmentPlaneIntersect = maxon::GeometryUtilsInterface::IntersectSegmentPlane (startPoint, endPoint, planePoint, planeNormal, segmentPlaneIntersectPoint); if (segmentPlaneIntersect) DiagnosticOutput ( "Segments intersects plane at @" , segmentPlaneIntersectPoint);
Intersections of lines, half-lines and segments with triangles and quadrangles:
// check line/triangle intersection maxon::Vector lineTriIntersectPoint { maxon::DONT_INITIALIZE }; const maxon::Bool lineTriIntersect = maxon::GeometryUtilsInterface::IntersectLineTriangle (startPoint, lineDir, pointA, pointB, pointC, lineTriIntersectPoint); if (lineTriIntersect) DiagnosticOutput ( "Line intersects with triangle at @" , lineTriIntersectPoint);
// check half-line/triangle intersection maxon::Vector halfLineTriIntersectPoint { maxon::DONT_INITIALIZE }; const maxon::Bool halfLineTriIntersect = maxon::GeometryUtilsInterface::IntersectHalfLineTriangle (startPoint, lineDir, pointA, pointB, pointC, halfLineTriIntersectPoint); if (halfLineTriIntersect) DiagnosticOutput ( "Half-line intersects triangle at @" , halfLineTriIntersectPoint);
// check segment/triangle intersection maxon::Vector segmentTriIntersectPoint { maxon::DONT_INITIALIZE }; const maxon::Bool segmentTriIntersect = maxon::GeometryUtilsInterface::IntersectSegmentTriangle (startPoint, endPoint, pointA, pointB, pointC, segmentTriIntersectPoint); if (segmentTriIntersect) DiagnosticOutput ( "Segment intersects triangle at @" , segmentTriIntersectPoint);
Intersection of triangles, quadrangles and planes:
These functions are used to check if a given point is inside a given shape:
// point within the triangle const maxon::Vector2d point { 0.5, 0.25 };
// check if inside the triangle const maxon::Bool inside = maxon::GeometryUtilsInterface::PointInTriangle2D (point, points[0], points[1], points[2]); // calculate winding number const maxon::Int windingNumber = maxon::GeometryUtilsInterface::GetPointInPolygonWindingNumber2D (point, points);
These functions check if a given point is on a line, half-line or within a segment:
// get direction vector const maxon::Vector direction = maxon::Vector (segmentEnd - segmentStart). GetNormalized ();
// check on half-line const maxon::Bool pointInHalfLine = maxon::GeometryUtilsInterface::PointInHalfLine (point, segmentStart, direction);
// check on segment const maxon::Bool pointInSegment = maxon::GeometryUtilsInterface::PointInSegment (point, segmentStart, segmentEnd);
// position const maxon::Float value = maxon::GeometryUtilsInterface::InterpolatePointOnSegment (segmentStart, segmentEnd, point, false );
The circumcenter is the center of a circle containing all points of the given shape.
The convexity of a given vertex can be checked with:
另请参阅 ConvexHull Manual .
Functions to project points:
Miscellaneous functions are:
// change range of values const maxon::Float sourceMin = 0.0; const maxon::Float sourceMax = 10.0; const maxon::Float destMin = 0.0; const maxon::Float destMax = 1.0; for ( maxon::Vector2d & point : points) { point.x = maxon::GeometryUtilsInterface::LinearRemapToRange (point.x, sourceMin, sourceMax, destMin, destMax); point.y = maxon::GeometryUtilsInterface::LinearRemapToRange (point.y, sourceMin, sourceMax, destMin, destMax); }
// find circumcenter maxon::Vector2d center; maxon::Float radius; const maxon::Bool res = maxon::GeometryUtilsInterface::CalculateCircumcenter2D (points[0], points[1], points[2], center, radius); if ( MAXON_LIKELY (res)) { ApplicationOutput ( "Center: @, Radius: @" , center, radius); }