AutoCAD允许将样条实体存储在仅由拟合点定义的DXF文件中,问题是样条定义具有无限的数值正确解,Autodesk不提供从给定的拟合点计算所需参数所需的信息。
tl;dr -缺失的信息是估计的开始和结束切线的方向和大小输入切线的全局B样条插值的末端导数,谁能帮助计算这个值吗?
我使用BricsCAD进行测试,但是"Trueview 2020“显示了相同的结果。
1.设想情况
只给出拟合点,使用不受任何约束的全局曲线插值,得到由控制顶点定义的样条:
# First spline defined by control vertices interpolated from given fit points
s = global_bspline_interpolation(points, degree=3)
msp.add_spline(dxfattribs={'color': 4, 'layer': 'Global Interpolation'}).apply_construction_tool(s)
# Second spline defined only by fit points as reference
spline = msp.add_spline(points, degree=3, dxfattribs={'layer': 'BricsCAD B-spline', 'color': 2})
doc.saveas(DIR / 'fit-points-only.dxf')
由BricsCAD从拟合点插值的样条与插值控制顶点定义的样条不匹配:
2.设想情况
除了fit点,我还在DXF文件中存储开始和结束切线值。插值由带端导数的全局曲线插值完成(Piegl & Tiller:“NURBS图书”-第9.2.2章)。
我选择了一个任意的角度(100度)作为开始和结束切线,切线大小是由“总弦长”方法估计的。
m1, m2 = estimate_end_tangent_magnitude(points, method='chord')
start_tangent = Vector.from_deg_angle(100) * m1
end_tangent = Vector.from_deg_angle(-100) * m2
# First spline defined by control vertices interpolated from given fit points and end-tangents
s = global_bspline_interpolation(points, degree=3, tangents=(start_tangent, end_tangent))
msp.add_spline(dxfattribs={'color': 4, 'layer': 'Global Interpolation'}).apply_construction_tool(s)
# Result matches the BricsCAD interpolation if fit points, start- and end
# tangents are stored explicit in the DXF file.
# Second spline defined by fit points as reference
spline = msp.add_spline(points, degree=3, dxfattribs={'layer': 'BricsCAD B-spline', 'color': 2})
# set explicit start- and end tangent as unit vectors
spline.dxf.start_tangent = Vector.from_deg_angle(100)
spline.dxf.end_tangent = Vector.from_deg_angle(-100)
doc.saveas(DIR / 'fit-points-and-tangents.dxf')
由BricsCAD插值的样条现在与插值控制顶点定义的样条完全匹配:
现在我知道插值方法是正确的,我只需要从拟合点绘制同样的样条,就像BricsCAD一样,就是从拟合点推断出的方向和大小的结束切线。
3.设想情况
我需要控制顶点来呈现B样条,但是开始切线和结束切线不像场景1中那样存储在DXF文件中。需要估计开始和结束切线,最好的方法是:“NURBS Book”、Piegl & Tiller中的"5点插值“。
tangents = estimate_tangents(points, method='5-points')
# Estimated tangent angles: (108.43494882292201, -108.43494882292201) degree
m1, m2 = estimate_end_tangent_magnitude(points, method='chord')
start_tangent = tangents[0].normalize(m1)
end_tangent = tangents[-1].normalize(m2)
# First spline defined by control vertices interpolated from given fit points and end-tangents
s = global_bspline_interpolation(points, degree=3, tangents=(start_tangent, end_tangent))
msp.add_spline(dxfattribs={'color': 4, 'layer': 'Global Interpolation'}).apply_construction_tool(s)
# Second spline defined by fit points as reference, but without explicit start- and end
# tangents to see if my estimations are correct.
msp.add_spline(points, degree=3, dxfattribs={'layer': 'BricsCAD B-spline', 'color': 2})
doc.saveas(DIR / 'tangents-estimated.dxf')
令人惊讶的是,估计是不正确的,BricsCAD样条的切线角为101.0035408517495和-101.0035408517495度。
最烦人的是,如果我用BricsCAD角度作为输入,样条仍然不匹配,所以我假设切线幅度估计与场景2不同。
4.理论检验
从BricsCAD和样条“方法”保存的DXF文件中计算出以下值,该方法从“适合点”切换到“控制顶点”。根据这些数据,我计算了切线角和震级,tangent vector = 2nd control vertex - 1st control vertex
。
required_angle = 101.0035408517495 # angle of tangent vector in degrees
required_magnitude = m1 * 1.3097943444804256 # magnitude of tangent vector
start_tangent = Vector.from_deg_angle(required_angle, required_magnitude)
end_tangent = Vector.from_deg_angle(-required_angle, required_magnitude)
s = global_bspline_interpolation(points, degree=3, tangents=(start_tangent, end_tangent))
msp.add_spline(dxfattribs={'color': 4, 'layer': 'Global Interpolation'}).apply_construction_tool(s)
msp.add_spline(points, degree=3, dxfattribs={'layer': 'BricsCAD B-spline', 'color': 2})
doc.saveas(DIR / 'theory-check.dxf')
现在,样条又匹配了:
m1*1.3097943444804256
,但是它不是一个常数因子。最大的问题是:如何估计仅由拟合点定义的样条在方向和幅度上的开始和结束切线(如AutoCAD或BricsCAD )?
提前谢谢你,
曼弗雷德
发布于 2021-02-24 20:50:43
第三种情况似乎已经解决:样条实体从拟合点没有给定的端点切线。
应用三次Bézier曲线插值似乎是解决方案:
BricsCAD/AutoCAD与ezdxf样条之间没有视觉差异。
在这里上描述了三次Bèzier曲线到三次样条的转换,并在ezdxf v0.16中实现了这里,三次Bézier曲线插值的源代码是这里。
这只适用于三次B样条(最常用的B样条),而BricsCAD/AutoCAD只允许对只由拟合点定义的样条实体的度为2或3。唯一缺少的是二次B样条曲线作为二次Bézier曲线的插值.
进一步的研究表明,用拟合点定义的二次B样条作为三次B样条加载到BricsCAD/AutoCAD中。除上述声明外:
对于仅由拟合点定义的样条实体,BricsCAD和AutoCAD只使用3度。
B样条无给定端切的解是一种三次Bèzier插值,不需要进行端切计算。
更新:不是解决方案
可悲的是,所有这些都只适用于小的简单B样条:
全局曲线插值是比Bèzier曲线插值更好的解决方案。它在B样条开始时发散,其中Bèzier曲线插值完全失败。
AutoCAD端点切线的搜索仍在继续.
发布于 2020-09-01 23:48:51
样条实体可以有可选的群代码12,22,32表示起始切线x,y,z,13,23,33表示端点切线x,y,z。我检查了netDxf项目的源代码,如果只使用拟合点来定义样条,那么开始和结束切值将被指定为。
来自AutoCAD 2012样条实体的DXF参考:
12开始切线-可以省略(在WCS中) DXF: x值;APP: 3D点 22,32 DXF: y和z的起始切线值可以省略(在WCS中) 13端切线-可省略( WCS) DXF: x值;APP: 3D点 23,33 DXF: y和z值可省略(在WCS中)
昨天,我们和我的同事在Autocad 2020中创建了一些DXF文件,包括适合点的样条。输出到DXF后,样条由控制点和节点定义。因此,我猜测,适合点是一些过时的东西或用户界面。
https://stackoverflow.com/questions/62472305
复制