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

Angles between vectors can be calculated with:

Areas

Multiple points can define a triangle, a quad or an arbitrary shape.

// This example calculate the areas of different shapes.
const maxon::Float triArea = maxon::GeometryUtilsInterface::CalculateTriangleArea (points[0], points[1], points[2]); const maxon::Float quadArea = maxon::GeometryUtilsInterface::CalculateQuadrangleArea (points[0], points[1], points[2], points[3]); const maxon::Float shapeArea = maxon::GeometryUtilsInterface::CalculateOutlineArea (points);

Barycentric Coordinates

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:

// This example calculates the barycentric coordinates for the given point.

// 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);

Interpolation

Bilinear interpolation allows to interpolate values in a two dimensional grid:

// This example performs bilinear interpolation between the given color values.

// 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);

Intersection

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:

// This example checks if the given segments and lines intersect.

// 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:

// This example checks the intersection of a line, half-line and a segment with a given plane.

// 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:

// This example checks the intersection of a line, half-line, and segment with a triangle.

// 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:

Points Inside

These functions are used to check if a given point is inside a given shape:

// This example tests if the given point is within the given triangle and // also calculates the winding number for the given points.

// 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);

Points on Lines

These functions check if a given point is on a line, half-line or within a segment:

// This example checks if the given point in on the given segment or half line and // calculates the position within the 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 );

Circumcenter

The circumcenter is the center of a circle containing all points of the given shape.

// This example calculates the circumcenter and radius for the given triangle. maxon::Vector center; maxon::Float radius { 0 }; const maxon::Bool foundCenter = maxon::GeometryUtilsInterface::CalculateCircumcenter (pointA, pointB, pointC, center, radius); if (foundCenter) DiagnosticOutput ( "Center at @, Radius: @" , center, radius);

Vertex Properties

The convexity of a given vertex can be checked with:

另请参阅 ConvexHull Manual .

Projection

Functions to project points:

杂项

Miscellaneous functions are:

// This example remaps the values of the given points // and calculates the circumcenter of the resulting triangle.

// 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); }

延伸阅读

maxon::GeometryUtilsInterface::IntersectLinePlane
static MAXON_METHOD Bool IntersectLinePlane(const Vector &linePoint, const Vector &lineDir, const Vector &planePoint, const Vector &planeNormal, Vector &intersectionPoint, Float tolerance=GeomConstants::EPSILON4)
maxon::GeometryUtilsInterface::IntersectLineTriangle
static MAXON_METHOD Bool IntersectLineTriangle(const Vector &linePoint, const Vector &lineDir, const Vector &a, const Vector &b, const Vector &c, Vector &intersectionPoint, Vector2d *barycCoords=nullptr, Float tolerance=GeomConstants::EPSILON4)
maxon::DONT_INITIALIZE
static const ENUM_DONT_INITIALIZE DONT_INITIALIZE
定义: apibase.h:542
maxon::GeometryUtilsInterface::IntersectSegments
static MAXON_METHOD Bool IntersectSegments(const Vector &segment1Point1, const Vector &segment1Point2, const Vector &segment2Point1, const Vector &segment2Point2, Vector &intersectionPoint, Float tolerance=GeomConstants::EPSILON4)
maxon::GeometryUtilsInterface::IntersectSegmentTriangle
static MAXON_METHOD Bool IntersectSegmentTriangle(const Vector &segmentPoint1, const Vector &segmentPoint2, const Vector &a, const Vector &b, const Vector &c, Vector &intersectionPoint, Vector *barycCoords=nullptr, Float tolerance=GeomConstants::EPSILON4)
maxon::GeometryUtilsInterface::CalculateCircumcenter
static MAXON_METHOD Bool CalculateCircumcenter(const Vector &a, const Vector &b, const Vector &c, Vector ¢er, Float &rad, Float tolerance=GeomConstants::EPSILON4)
maxon::GeometryUtilsInterface::LinearRemapToRange
static MAXON_METHOD Float LinearRemapToRange(Float value, Float from1, Float to1, Float from2, Float to2)
maxon::GeometryUtilsInterface::CalculateQuadrangleArea
static MAXON_METHOD Float CalculateQuadrangleArea(const Vector &a, const Vector &b, const Vector &c, const Vector &d)
maxon::Bool
bool Bool
boolean type, possible values are only false/true, 8 bit
定义: apibase.h:177
maxon::GeometryUtilsInterface::InterpolatePointOnSegment
static MAXON_METHOD Float InterpolatePointOnSegment(const Vector &segmentPoint1, const Vector &segmentPoint2, const Vector &point, Bool clamp=true)
maxon::GeometryUtilsInterface::IntersectHalfLinePlane
static MAXON_METHOD Bool IntersectHalfLinePlane(const Vector &halfLinePoint, const Vector &halfLineDir, const Vector &planePoint, const Vector &planeNormal, Vector &intersectionPoint, Float tolerance=GeomConstants::EPSILON4)
maxon::Float
Float64 Float
定义: apibase.h:193
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
定义: debugdiagnostics.h:166
maxon::GeometryUtilsInterface::GetPointInPolygonWindingNumber2D
static MAXON_METHOD Int GetPointInPolygonWindingNumber2D(Vector2d point, const Block< const Vector2d > &outline)
maxon::GeometryUtilsInterface::CalculateTriangleArea
static MAXON_METHOD Float CalculateTriangleArea(const Vector &a, const Vector &b, const Vector &c)
maxon::Vec3< Float, 1 >
maxon::Vec3::GetNormalized
constexpr Unstrided GetNormalized() const
Returns a normalized vector, so that GetLength(vector)==1.0.
定义: vec.h:417
maxon::Int
Int64 Int
signed 32/64 bit int, size depends on the platform
定义: apibase.h:184
maxon::GeometryUtilsInterface::PointInHalfLine
static MAXON_METHOD Bool PointInHalfLine(const Vector &point, const Vector &halfLineOrigin, const Vector &halfLineDir, Float tolerance=GeomConstants::EPSILON4)
maxon::Vec2< Float, 1 >
maxon::GeometryUtilsInterface::IntersectHalfLineTriangle
static MAXON_METHOD Bool IntersectHalfLineTriangle(const Vector &halfLineOrigin, const Vector &halfLineDir, const Vector &a, const Vector &b, const Vector &c, Vector &intersectionPoint, Vector2d *barycCoords=nullptr, Float tolerance=GeomConstants::EPSILON4)
ApplicationOutput
#define ApplicationOutput(formatString,...)
定义: debugdiagnostics.h:207
MAXON_LIKELY
#define MAXON_LIKELY(X)
定义: compilerdetection.h:481
maxon::GeometryUtilsInterface::IntersectLines
static MAXON_METHOD Bool IntersectLines(const Vector &line1Point, const Vector &line1Dir, const Vector &line2Point, const Vector &line2Dir, Vector &intersectionPoint, Float tolerance=GeomConstants::EPSILON4)
maxon::GeometryUtilsInterface::CalculateOutlineArea
static MAXON_METHOD Float CalculateOutlineArea(const Block< const Vector > &outlinePoints)
maxon::GeometryUtilsInterface::BilinearInterpolate
static MAXON_METHOD Vector BilinearInterpolate(const Vector &pa, const Vector &pb, const Vector &pc, const Vector &pd, const Float s, const Float t)
maxon::GeometryUtilsInterface::CalculateCircumcenter2D
static MAXON_METHOD Bool CalculateCircumcenter2D(const Vector2d &a, const Vector2d &b, const Vector2d &c, Vector2d ¢er, Float &sqrRad, Float tolerance=GeomConstants::EPSILON4)
maxon::Vector
Vec3< Float, 1 > Vector
定义: vector.h:58
maxon::GeometryUtilsInterface::PointInSegment
static MAXON_METHOD Bool PointInSegment(const Vector &point, const Vector &segmentPoint1, const Vector &segmentPoint2, Float tolerance=GeomConstants::EPSILON4)
maxon::GeometryUtilsInterface::PointInTriangle2D
static MAXON_METHOD Bool PointInTriangle2D(const Vector2d &point, const Vector2d &a, const Vector2d &b, const Vector2d &c)
maxon::GeometryUtilsInterface::CalculateBarycentricCoordinate3D
static MAXON_METHOD Vector CalculateBarycentricCoordinate3D(const Vector &point, const Vector &a, const Vector &b, const Vector &c)
maxon::GeometryUtilsInterface::IntersectSegmentPlane
static MAXON_METHOD Bool IntersectSegmentPlane(const Vector &segmentPoint1, const Vector &segmentPoint2, const Vector &planePoint, const Vector &planeNormal, Vector &intersectionPoint, Float tolerance=GeomConstants::EPSILON4)

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1