后面解释,先上代码:
double lineOffset=10;
Curve copyCurve = curve.CreateOffset(lineOffset, getNormal(curve));
/// <summary>
/// 传入一根线,根据右手定则,返回可以得到负z轴偏移方向的向量。!!注意,我的线是在xy平面,
/// 想把线往负z轴偏移,所以这样做。根据需求自己改方法体
/// </summary>
/// <param name="geometryCurve"></param>
/// <returns></returns>
private XYZ getNormal(Curve curve)
{
XYZ sPoint = curve.GetEndPoint(0);
XYZ ePoint = curve.GetEndPoint(1);
double res = 1;//这个是下面外扩的长度,随便取正数即可
//往curve第一个端点外扩展2个点,简单的几何比例
XYZ p0 = new XYZ(sPoint.X - (ePoint.Y - sPoint.Y) * (res / curve.ApproximateLength), sPoint.Y + (ePoint.X - sPoint.X) * (res / curve.ApproximateLength), sPoint.Z);
XYZ p1 = new XYZ(sPoint.X + (ePoint.Y - sPoint.Y) * (res / curve.ApproximateLength), sPoint.Y - (ePoint.X - sPoint.X) * (res / curve.ApproximateLength), sPoint.Z);
return Line.CreateBound(p0, p1).Direction;
}
CreateOffset的原型是这样:
public Curve CreateOffset(double offsetDist, XYZ normal);
API手册里面对于normal参数解释是“The normal of the plane defining the offset direction.
”,翻译过来是“定义偏移方向的平面的法线。”。反正我是有点难理解的。。自己动手测试验证到底是什么样。
比如我有这样一根curve:

我在上面的getNormal方法代码里面,构造了一根这样的线p0->p1:

就是p0指向p1的Line。就返回这个的Direction。
那,偏移方向是这样的:

2020.10.19发现了线偏移的另一种方法:
int hight = 100;
Transform tsf = Transform.CreateTranslation(new XYZ(0, 0, 1).Multiply(hight));
Curve newCurve = oldCurve.CreateTransformed(tsf);
本文详细介绍了在三维空间中如何使用右手定则确定曲线偏移方向,通过构造特定向量来实现曲线沿指定方向的偏移。同时,探讨了不同偏移方法,包括利用平面法线和坐标变换实现曲线的精准移动。
7792

被折叠的 条评论
为什么被折叠?



