The geometry-engine package provides comprehensive geometric entities, mathematical operations, and transformations for 2D and 3D space. This package mimics AutoCAD ObjectARX's AcGe (Geometry) classes and provides the mathematical foundation for CAD operations.
This package consists of two main categories of classes:
Most math classes are adapted from THREE.js with modified class names to match AutoCAD ObjectARX conventions.
npm install @mlightcad/geometry-engine
import { AcGePoint3d, AcGeVector3d, AcGeMatrix3d } from '@mlightcad/geometry-engine';
// Create points and vectors
const point1 = new AcGePoint3d(0, 0, 0);
const point2 = new AcGePoint3d(10, 10, 10);
const vector = new AcGeVector3d(1, 0, 0);
// Calculate distance between points
const distance = point1.distanceTo(point2);
// Transform a point
const matrix = AcGeMatrix3d.translation(5, 5, 5);
const transformedPoint = point1.transformBy(matrix);
import { AcGeLine3d, AcGeCircArc3d, AcGePoint3d } from '@mlightcad/geometry-engine';
// Create a line
const startPoint = new AcGePoint3d(0, 0, 0);
const endPoint = new AcGePoint3d(10, 0, 0);
const line = new AcGeLine3d(startPoint, endPoint);
// Create a circular arc
const center = new AcGePoint3d(0, 0, 0);
const radius = 5;
const startAngle = 0;
const endAngle = Math.PI / 2;
const arc = new AcGeCircArc3d(center, radius, startAngle, endAngle);
// Get points along the curve
const param = 0.5;
const pointOnLine = line.evalPoint(param);
const pointOnArc = arc.evalPoint(param);
import { AcGeMatrix3d, AcGePoint3d } from '@mlightcad/geometry-engine';
// Create transformation matrices
const translation = AcGeMatrix3d.translation(10, 20, 30);
const rotation = AcGeMatrix3d.rotation(Math.PI / 4, AcGeVector3d.kZAxis);
const scale = AcGeMatrix3d.scaling(2, 2, 2);
// Combine transformations
const combined = translation.multiply(rotation).multiply(scale);
// Apply transformation to a point
const point = new AcGePoint3d(1, 1, 1);
const transformed = point.transformBy(combined);
import { AcGePolyline2d, AcGePoint2d } from '@mlightcad/geometry-engine';
// Create a polyline
const polyline = new AcGePolyline2d();
polyline.addVertexAt(0, new AcGePoint2d(0, 0));
polyline.addVertexAt(1, new AcGePoint2d(10, 0));
polyline.addVertexAt(2, new AcGePoint2d(10, 10));
polyline.addVertexAt(3, new AcGePoint2d(0, 10));
// Close the polyline
polyline.setClosed(true);
// Get polyline properties
const length = polyline.length();
const area = polyline.area();
const isClosed = polyline.isClosed();
import { AcGeGeometryUtil, AcGePoint3d, AcGeVector3d } from '@mlightcad/geometry-engine';
// Calculate intersection between lines
const line1 = new AcGeLine3d(new AcGePoint3d(0, 0, 0), new AcGeVector3d(1, 0, 0));
const line2 = new AcGeLine3d(new AcGePoint3d(0, 0, 0), new AcGeVector3d(0, 1, 0));
const intersection = AcGeGeometryUtil.intersect(line1, line2);
// Check if points are collinear
const points = [
new AcGePoint3d(0, 0, 0),
new AcGePoint3d(1, 1, 1),
new AcGePoint3d(2, 2, 2)
];
const areCollinear = AcGeGeometryUtil.areCollinear(points);
For detailed API documentation, visit the RealDWG-Web documentation.
This package is part of the RealDWG-Web monorepo. Please refer to the main project README for contribution guidelines.