Geometry Calculations
About 2 min
Geometry Calculations
Geometry utility functions for distance, angles, intersections, area, and more.
Online Examples
| Example | Description | Link |
|---|---|---|
| Distance Calculation | Usage of the distance function | Online Demo{target="_blank"} |
| Angle Calculation | Usage of getAngleBetweenPoints | Online Demo{target="_blank"} |
| Midpoint Calculation | Usage of getMidPoint | Online Demo{target="_blank"} |
| Intersection Calculation | Usage of GeometryCalculator | Online Demo{target="_blank"} |
| Bounding Box | Usage of boundingBox | Online Demo{target="_blank"} |
| Point-to-Line Side Test | Usage of GeometryCalculator.witchSidePointToLine | Online Demo{target="_blank"} |
| Area Calculation | Usage of calculatePolygonArea | Online Demo{target="_blank"} |
| Point in Polygon | Ray-casting method | Online Demo{target="_blank"} |
| Spatial Index | Usage of SpatialIndex | Online Demo{target="_blank"} |
| Offset Algorithm | Offset lines, arcs, circles, and polylines | Online Demo{target="_blank"} |
| Trim Algorithm | Entity trimming based on intersections | Online Demo{target="_blank"} |
| Extend Algorithm | Extend entities to a boundary | Online Demo{target="_blank"} |
| Advanced Intersection Calculation | Intersections across multiple entity types | Online Demo{target="_blank"} |
| Foot of Perpendicular | Perpendicular foot from a point to a line | Online Demo{target="_blank"} |
| Bounding Box Merge | Merge multiple bounding boxes | Online Demo{target="_blank"} |
| Break Segment | Break an entity at a specified point | Online Demo{target="_blank"} |
| Geometric Transformations | Translate, rotate, scale, mirror | Online Demo{target="_blank"} |
| Centerline Extraction | Extract centerlines from double lines (parallel lines) | Online Demo{target="_blank"} |
| Revision Cloud Generation | Generate revision clouds with generateRevcloudBulgePoints | Online Demo{target="_blank"} |
| Smart Block Recognition | Detect repeated patterns and convert to blocks | Online Demo{target="_blank"} |
| Text Width / Height | measureTextLocal / measureTexts laid-out sizes | Online Demo{target="_blank"} |
Core APIs
Distance Calculation
const { Point2D, distance } = vjcad;
const p1 = new Point2D(0, 0);
const p2 = new Point2D(100, 100);
const dist = distance(p1, p2); // 141.42...Angle Calculation
const { getAngleBetweenPoints } = vjcad;
const angle = getAngleBetweenPoints(p1, p2); // radians
const angleDeg = angle * 180 / Math.PI;Intersection Calculation
const { GeometryCalculator } = vjcad;
const intersection = GeometryCalculator.lineLineIntersection(
line1.startPoint, line1.endPoint,
line2.startPoint, line2.endPoint
);Bounding Box
const bbox = entity.boundingBox();
console.log(bbox.minX, bbox.minY, bbox.maxX, bbox.maxY);
const merged = BoundingBox.merge([bbox1, bbox2, bbox3]);Text Width / Height
Measure laid-out text size with local WASM or server ODA before auto-layout:
const { measureTextLocal, measureTexts } = vjcad;
const local = measureTextLocal({ type: 'TEXT', text: 'Sample', height: 3 });
const batch = await measureTexts(
[{ text: 'Wrap', height: 2.5, width: 40, type: 'MTEXT' }],
{ mode: 'local' }
);See Text Width / Height Measurement for full options and server routing.