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.

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

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


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


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

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


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:

See also ConvexHull Manual.


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

Further Reading

static MAXON_METHOD Bool IntersectLinePlane(const Vector &linePoint, const Vector &lineDir, const Vector &planePoint, const Vector &planeNormal, Vector &intersectionPoint, Float tolerance=GeomConstants::EPSILON4)
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)
Definition: apibase.h:577
static MAXON_METHOD Bool IntersectSegments(const Vector &segment1Point1, const Vector &segment1Point2, const Vector &segment2Point1, const Vector &segment2Point2, Vector &intersectionPoint, Float tolerance=GeomConstants::EPSILON4)
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)
static MAXON_METHOD Bool CalculateCircumcenter(const Vector &a, const Vector &b, const Vector &c, Vector &center, Float &rad, Float tolerance=GeomConstants::EPSILON4)
static MAXON_METHOD Float LinearRemapToRange(Float value, Float from1, Float to1, Float from2, Float to2)
static MAXON_METHOD Float CalculateQuadrangleArea(const Vector &a, const Vector &b, const Vector &c, const Vector &d)
bool Bool
boolean type, possible values are only false/true, 8 bit
Definition: apibase.h:179
static MAXON_METHOD Float InterpolatePointOnSegment(const Vector &segmentPoint1, const Vector &segmentPoint2, const Vector &point, Bool clamp=true)
static MAXON_METHOD Bool IntersectHalfLinePlane(const Vector &halfLinePoint, const Vector &halfLineDir, const Vector &planePoint, const Vector &planeNormal, Vector &intersectionPoint, Float tolerance=GeomConstants::EPSILON4)
Float64 Float
Definition: apibase.h:195
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:167
static MAXON_METHOD Int GetPointInPolygonWindingNumber2D(Vector2d point, const Block< const Vector2d > &outline)
static MAXON_METHOD Float CalculateTriangleArea(const Vector &a, const Vector &b, const Vector &c)
maxon::Vec3< Float, 1 >
constexpr Unstrided GetNormalized() const
Returns a normalized vector, so that GetLength(vector)==1.0.
Definition: vec.h:455
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:186
static MAXON_METHOD Bool PointInHalfLine(const Vector &point, const Vector &halfLineOrigin, const Vector &halfLineDir, Float tolerance=GeomConstants::EPSILON4)
maxon::Vec2< Float, 1 >
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)
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:208
Definition: compilerdetection.h:479
static MAXON_METHOD Bool IntersectLines(const Vector &line1Point, const Vector &line1Dir, const Vector &line2Point, const Vector &line2Dir, Vector &intersectionPoint, Float tolerance=GeomConstants::EPSILON4)
static MAXON_METHOD Float CalculateOutlineArea(const Block< const Vector > &outlinePoints)
static MAXON_METHOD Vector BilinearInterpolate(const Vector &pa, const Vector &pb, const Vector &pc, const Vector &pd, const Float s, const Float t)
static MAXON_METHOD Bool CalculateCircumcenter2D(const Vector2d &a, const Vector2d &b, const Vector2d &c, Vector2d &center, Float &sqrRad, Float tolerance=GeomConstants::EPSILON4)
Vec3< Float, 1 > Vector
Definition: vector.h:56
static MAXON_METHOD Bool PointInSegment(const Vector &point, const Vector &segmentPoint1, const Vector &segmentPoint2, Float tolerance=GeomConstants::EPSILON4)
static MAXON_METHOD Bool PointInTriangle2D(const Vector2d &point, const Vector2d &a, const Vector2d &b, const Vector2d &c)
static MAXON_METHOD Vector CalculateBarycentricCoordinate3D(const Vector &point, const Vector &a, const Vector &b, const Vector &c)
static MAXON_METHOD Bool IntersectSegmentPlane(const Vector &segmentPoint1, const Vector &segmentPoint2, const Vector &planePoint, const Vector &planeNormal, Vector &intersectionPoint, Float tolerance=GeomConstants::EPSILON4)