云线生成
大约 2 分钟
云线生成
从路径坐标生成类似 AutoCAD REVCLOUD 风格的云线(修订云线),结果为带有半圆弧凸度的多段线。
在线示例
在线演示{target="_blank"}
功能概述
云线(Revision Cloud)是 CAD 中常用的标注方式,用于标记图纸中需要修改或关注的区域。算法将路径上每条线段按指定弧长等分,每个子段赋予半圆弧凸度值(bulge = 1),产生连续的半圆弧轮廓。
典型应用场景:
- 图纸审阅标注
- 变更区域标记
- 区域高亮提示
使用方式
方式一:命令面板
在菜单栏 创建 → 云线 或 Ribbon 绘图 分组中点击 云线 按钮,或输入命令 REVCLOUD(别名 RC)。
方式二:代码调用
const { PolylineEnt, Engine, generateRevcloudBulgePoints } = vjcad;
// 定义路径
const path = [[0, 0], [200, 0], [200, 100], [0, 100]];
// 生成云线凸度点
const bulgePoints = generateRevcloudBulgePoints(path, {
arcLength: 30, // 每段弧的弦长
isClosed: true, // 闭合路径
});
// 创建多段线实体
const cloud = new PolylineEnt(bulgePoints);
cloud.isClosed = true;
cloud.setDefaults();
Engine.addEntities(cloud);API 参考
generateRevcloudBulgePoints
function generateRevcloudBulgePoints(
pathPoints: PointInput[],
options?: RevcloudOptions
): BulgePoints从路径顶点数组生成云线风格的 BulgePoints,可直接传给 new PolylineEnt(bulgePoints)。
参数
| 参数 | 类型 | 说明 |
|---|---|---|
pathPoints | PointInput[] | 路径顶点数组,至少 2 个点。支持 [x, y]、Point2D 等格式 |
options | RevcloudOptions | 可选配置 |
RevcloudOptions
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
arcLength | number | 50 | 每段弧的弦长 |
bulge | number | 1 | 凸度值。1 = 半圆弧,0.5 ≈ 90° 弧,负值翻转弧方向 |
isClosed | boolean | false | 路径是否闭合。闭合时最后一个顶点自动连接到第一个顶点 |
返回值
BulgePoints — 带凸度的点集合,可直接用于构造 PolylineEnt。
算法说明
输入: 路径点数组 + 弧长参数
↓
对每对相邻路径点:
↓
1. 计算两点距离 d
↓
2. 弧段数量 n = max(1, round(d / arcLength))
↓
3. 将线段等分为 n 段
↓
4. 每个分割点设置 bulge = 1 (半圆弧)
↓
拼接所有分割点 (去除相邻段接合处的重复点)
↓
输出: BulgePoints (可构造 PolylineEnt)凸度 (Bulge) 与弧形
凸度值决定弧段的弯曲程度:
| bulge | 弧形 | 扫过角度 |
|---|---|---|
0 | 直线 | 0° |
0.5 | 较浅弧 | ≈ 90° |
1 | 半圆弧 | 180° |
-1 | 反向半圆 | 180° (反方向) |
提示
云线默认使用 bulge = 1(半圆弧),这与 AutoCAD REVCLOUD 的效果一致。 可以通过调整 bulge 参数改变弧的弯曲程度。
示例
闭合矩形云线
const path = [[0, 0], [200, 0], [200, 100], [0, 100]];
const bp = generateRevcloudBulgePoints(path, {
arcLength: 20,
isClosed: true,
});
const cloud = new PolylineEnt(bp);
cloud.isClosed = true;
cloud.setDefaults();
Engine.addEntities(cloud);开放路径云线
const path = [[0, 0], [80, 30], [160, 0], [240, 30]];
const bp = generateRevcloudBulgePoints(path, {
arcLength: 15,
isClosed: false,
});
const cloud = new PolylineEnt(bp);
cloud.setDefaults();
Engine.addEntities(cloud);不同弧长效果对比
[10, 25, 50].forEach((arcLen, i) => {
const bp = generateRevcloudBulgePoints(
[[0, i * 40], [300, i * 40]],
{ arcLength: arcLen }
);
const pline = new PolylineEnt(bp);
pline.setDefaults();
pline.color = i + 1;
Engine.addEntities(pline);
});