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, points, 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

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

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

# 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;
const maxon::Bool foundCenter = maxon::GeometryUtilsInterface::CalculateCircumcenter(pointA, pointB, pointC, center, radius);
if (foundCenter)

# Vertex Properties

The convexity of a given vertex can be checked with:

# Projection

Functions to project points:

# Miscellaneous

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