Geometry Calculations
About 1 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"} |
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; // Convert to degreesIntersection Calculation
const { GeometryCalculator } = vjcad;
// Intersection of two lines
const intersection = GeometryCalculator.lineLineIntersection(
line1.startPoint, line1.endPoint,
line2.startPoint, line2.endPoint
);Bounding Boxes
// Get entity bounding box
const bbox = entity.boundingBox();
console.log(bbox.minX, bbox.minY, bbox.maxX, bbox.maxY);
// Merge multiple bounding boxes
const merged = BoundingBox.merge([bbox1, bbox2, bbox3]);