This chapter introduces the basic geometry entities in WebCAD.
import { LineEnt, Point2D } from 'vjcad';
const line = new LineEnt(
new Point2D(0, 0), // Start point
new Point2D(100, 100) // End point
);
line.setDefaults();
// Property access
console.log('Start point:', line.startPoint);
console.log('End point:', line.endPoint);
console.log('Mid point:', line.midPoint);
console.log('Length:', line.Length);
console.log('Angle:', line.angle); // Radians
// Geometric transformations (supports shorthand syntax)
line.move([0, 0], [50, 50]); // Move
line.rotate([0, 0], Math.PI / 4); // Rotate 45 degrees
line.scale([0, 0], 2); // Scale up 2x
line.mirror([0, 0], [1, 0]); // Horizontal mirror
// Bounding box
const bbox = line.boundingBox();
console.log('Bounds:', bbox.pt1, bbox.pt2);
| Property | Type | Description |
|---|
startPoint | Point2D | Start point |
endPoint | Point2D | End point |
midPoint | Point2D | Mid point (read-only) |
Length | number | Length (read-only) |
angle | number | Angle (radians, read-only) |
import { CircleEnt, Point2D } from 'vjcad';
const circle = new CircleEnt(
new Point2D(50, 50), // Center
30 // Radius
);
circle.setDefaults();
// Modify properties
circle.center = new Point2D(100, 100);
circle.radius = 50;
| Property | Type | Description |
|---|
center | Point2D | Center |
radius | number | Radius |
import { ArcEnt, Point2D } from 'vjcad';
const arc = new ArcEnt();
arc.center = new Point2D(50, 50);
arc.radius = 30;
arc.startAngle = 0; // Start angle (radians)
arc.endAngle = Math.PI / 2; // End angle (radians)
arc.setDefaults();
| Property | Type | Description |
|---|
center | Point2D | Center |
radius | number | Radius |
startAngle | number | Start angle (radians) |
endAngle | number | End angle (radians) |
import { PolylineEnt, BulgePoint, BulgePoints, Point2D } from 'vjcad';
const pline = new PolylineEnt();
pline.setDefaults();
// Add vertices (BulgePoint constructor: new BulgePoint(Point2D, bulge))
pline.bulgePoints.add(new BulgePoint(new Point2D(0, 0), 0)); // Straight segment
pline.bulgePoints.add(new BulgePoint(new Point2D(100, 0), 0.5)); // Arc segment with bulge
pline.bulgePoints.add(new BulgePoint(new Point2D(100, 100), 0));
pline.bulgePoints.add(new BulgePoint(new Point2D(0, 100), 0));
pline.isClosed = true; // Closed polyline
// Set global width
pline.globalWidth = 5;
| Property | Type | Description |
|---|
bulgePoints | BulgePoints | Vertex collection |
isClosed | boolean | Whether closed |
globalWidth | number | Global width |
BulgePoint constructor: new BulgePoint(pointCoordinate: Point2D, bulgeValue: number)
point2d: Vertex coordinate (Point2D type)bulge: Bulge value bulge = 0: Straight line segmentbulge > 0: Counter-clockwise arcbulge < 0: Clockwise arcbulge = 1: Semicircle
import { EllipseEnt, Point2D } from 'vjcad';
const ellipse = new EllipseEnt();
ellipse.center = new Point2D(50, 50);
ellipse.majorRadius = 40;
ellipse.minorRadius = 20;
ellipse.rotation = 0;
ellipse.setDefaults();
import { HatchEnt, PolylineEnt, BulgePoints, BulgePoint, Point2D } from 'vjcad';
// Create boundary
const boundary = new PolylineEnt();
boundary.bulgePoints.add(new BulgePoint(new Point2D(0, 0), 0));
boundary.bulgePoints.add(new BulgePoint(new Point2D(100, 0), 0));
boundary.bulgePoints.add(new BulgePoint(new Point2D(100, 100), 0));
boundary.bulgePoints.add(new BulgePoint(new Point2D(0, 100), 0));
boundary.isClosed = true;
// Create hatch
const hatch = new HatchEnt();
hatch.setDefaults();
hatch.patternName = 'ANSI31'; // Pattern name
hatch.patternScale = 1;
hatch.patternAngle = 0;
hatch.addBoundary([boundary]);
| Pattern Name | Description |
|---|
SOLID | Solid fill |
ANSI31 | 45-degree diagonal lines |
ANSI32 | Cross lines |
ANSI33 | 45-degree cross |
ANSI34 | Horizontal lines |
ANSI35 | Vertical lines |
import { DotEnt, Point2D } from 'vjcad';
const dot = new DotEnt(new Point2D(50, 50));
dot.setDefaults();