本章介绍 WebCAD 的基本几何实体。
import { LineEnt, Point2D } from 'vjcad';
const line = new LineEnt(
new Point2D(0, 0), // 起点
new Point2D(100, 100) // 终点
);
line.setDefaults();
// 属性访问
console.log('起点:', line.startPoint);
console.log('终点:', line.endPoint);
console.log('中点:', line.midPoint);
console.log('长度:', line.Length);
console.log('角度:', line.angle); // 弧度
// 几何变换(支持简化写法)
line.move([0, 0], [50, 50]); // 移动
line.rotate([0, 0], Math.PI / 4); // 旋转45度
line.scale([0, 0], 2); // 放大2倍
line.mirror([0, 0], [1, 0]); // 水平镜像
// 边界框
const bbox = line.boundingBox();
console.log('边界:', bbox.pt1, bbox.pt2);
| 属性 | 类型 | 说明 |
|---|
startPoint | Point2D | 起点 |
endPoint | Point2D | 终点 |
midPoint | Point2D | 中点(只读) |
Length | number | 长度(只读) |
angle | number | 角度(弧度,只读) |
import { CircleEnt, Point2D } from 'vjcad';
const circle = new CircleEnt(
new Point2D(50, 50), // 圆心
30 // 半径
);
circle.setDefaults();
// 修改属性
circle.center = new Point2D(100, 100);
circle.radius = 50;
| 属性 | 类型 | 说明 |
|---|
center | Point2D | 圆心 |
radius | number | 半径 |
import { ArcEnt, Point2D } from 'vjcad';
const arc = new ArcEnt();
arc.center = new Point2D(50, 50);
arc.radius = 30;
arc.startAngle = 0; // 起始角度(弧度)
arc.endAngle = Math.PI / 2; // 终止角度(弧度)
arc.setDefaults();
| 属性 | 类型 | 说明 |
|---|
center | Point2D | 圆心 |
radius | number | 半径 |
startAngle | number | 起始角度(弧度) |
endAngle | number | 终止角度(弧度) |
import { PolylineEnt, BulgePoint, BulgePoints, Point2D } from 'vjcad';
const pline = new PolylineEnt();
pline.setDefaults();
// 添加顶点 (BulgePoint构造: new BulgePoint(Point2D, bulge))
pline.bulgePoints.add(new BulgePoint(new Point2D(0, 0), 0)); // 直线段
pline.bulgePoints.add(new BulgePoint(new Point2D(100, 0), 0.5)); // 带凸度的弧段
pline.bulgePoints.add(new BulgePoint(new Point2D(100, 100), 0));
pline.bulgePoints.add(new BulgePoint(new Point2D(0, 100), 0));
pline.isClosed = true; // 闭合多段线
// 设置全局宽度
pline.globalWidth = 5;
| 属性 | 类型 | 说明 |
|---|
bulgePoints | BulgePoints | 顶点集合 |
isClosed | boolean | 是否闭合 |
globalWidth | number | 全局宽度 |
BulgePoint 构造函数:new BulgePoint(pointCoordinate: Point2D, bulgeValue: number)
point2d:顶点坐标 (Point2D 类型)bulge:凸度值 bulge = 0:直线段bulge > 0:逆时针圆弧bulge < 0:顺时针圆弧bulge = 1:半圆
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';
// 创建边界
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;
// 创建填充
const hatch = new HatchEnt();
hatch.setDefaults();
hatch.patternName = 'ANSI31'; // 图案名
hatch.patternScale = 1;
hatch.patternAngle = 0;
hatch.addBoundary([boundary]);
| 图案名 | 说明 |
|---|
SOLID | 实心填充 |
ANSI31 | 45度斜线 |
ANSI32 | 交叉线 |
ANSI33 | 45度交叉 |
ANSI34 | 水平线 |
ANSI35 | 垂直线 |
import { DotEnt, Point2D } from 'vjcad';
const dot = new DotEnt(new Point2D(50, 50));
dot.setDefaults();