椭圆实体 (EllipseEnt)
大约 1 分钟
椭圆实体 (EllipseEnt)
EllipseEnt 表示 CAD 中的椭圆实体,由中心点、长轴、短轴和旋转角度确定。
概述
椭圆是二次曲线的一种,在工程设计中广泛使用。EllipseEnt 支持完整椭圆和椭圆弧。
构造函数
import { EllipseEnt, Point2D } from 'vjcad';
// 简化写法(推荐)
const ellipse1 = new EllipseEnt([100, 100], 50, 30, 0);
// Point2D 写法
const ellipse2 = new EllipseEnt(new Point2D(100, 100), 50, 30, 0);
ellipse1.setDefaults();简化写法
构造函数和 center 属性都支持 [x, y] 数组形式的坐标,避免每次都写 new Point2D(...)。
属性
| 属性 | 类型 | 说明 |
|---|---|---|
center | Point2D | 椭圆中心点 |
majorRadius | number | 长轴半径 |
minorRadius | number | 短轴半径 |
rotation | number | 旋转角度(弧度) |
startAngle | number | 起始角度(椭圆弧,弧度) |
endAngle | number | 结束角度(椭圆弧,弧度) |
isEllipse | boolean | 是否为完整椭圆(只读) |
示例
完整椭圆
import { Engine, EllipseEnt } from 'vjcad';
// 创建椭圆(支持 [x, y] 数组形式)
const ellipse = new EllipseEnt([50, 50], 40, 20, 0); // 圆心、长半径、短半径、旋转角度
ellipse.setDefaults();
Engine.addEntities(ellipse);
console.log('中心:', ellipse.center);
console.log('长半径:', ellipse.majorRadius);
console.log('短半径:', ellipse.minorRadius);椭圆弧
import { Engine, EllipseEnt } from 'vjcad';
// 创建椭圆弧(上半部分)
const ellipseArc = new EllipseEnt([50, 80], 40, 20, 0);
ellipseArc.startAngle = 0;
ellipseArc.endAngle = Math.PI; // 180度
ellipseArc.setDefaults();
Engine.addEntities(ellipseArc);
// 旋转的椭圆弧
const rotatedArc = new EllipseEnt([150, 80], 40, 20, Math.PI / 6); // 旋转30度
rotatedArc.startAngle = Math.PI / 4;
rotatedArc.endAngle = Math.PI * 5 / 4; // 从45度到225度
rotatedArc.setDefaults();
Engine.addEntities(rotatedArc);