AutoCAD如何计算仅由拟合点定义的样条线的最终切线? [英] How does AutoCAD calculate end tangents for splines defined only by fit points?

查看:175
本文介绍了AutoCAD如何计算仅由拟合点定义的样条线的最终切线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AutoCAD允许将SPLINE实体存储在仅由以下对象定义的DXF文件中: 拟合点,问题是,这样的样条曲线定义具有无限 数值正确的解决方案,而Autodesk没有提供必要的 信息以根据给定的拟合点计算所需的参数.

AutoCAD allows to store SPLINE entities in the DXF files defined only by fit points, the problem is, that such a spline definition has infinite numerical correct solutions and Autodesk does not provide the necessary information to calculate the required parameters from the given fit points.

tl; dr-缺少的信息是估计的开始和结束切线 整体B样条的输入切线的方向和大小 用最终导数进行插值,任何人都可以帮助计算该值吗?

tl;dr - The missing information are the estimated start- and end tangents in direction and magnitude for the input tangents to the global B-spline interpolation with end derivatives, can anyone help to calculate this values?

在github上完整源代码.

我使用BricsCAD进行测试,但"Trueview 2020"显示了相同的结果.

I use BricsCAD for testing, but "Trueview 2020" shows the same results.

仅使用全局曲线插值给出拟合点,而对 得到由控制顶点定义的样条线:

Only fit points are given, using the global curve interpolation without any constraints to get a spline defined by control vertices:

# 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从拟合点插值的样条线与插值定义的样条线不匹配 控制顶点:

The Spline interpolated by BricsCAD from fit points does not match the spline defined by the interpolated control vertices:

除了拟合点之外,我还将起点和终点切线值存储在DXF文件中. 插值是通过使用最终导数的全局曲线插值完成的 (Piegl& Tiller:"NURBS书" –第9.2.2章).

Beside the fit points I store also the start- and end tangent values in the DXF file. The interpolation is done by global curve interpolation with end derivatives (Piegl & Tiller: "The NURBS Book" - chapter 9.2.2).

我选择了任意角度(100度)作为开始和结束切线,即切线 幅度是通过总弦长"方法估算的.

I chose an arbitrary angle (100 degrees) as start- and end tangents, the tangent magnitude is estimated by the "Total chord length" method.

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内插的样条线现在与由 内插控制顶点:

The Spline interpolated by BricsCAD now matches exactly the spline defined by the interpolated control vertices:

现在我知道插值方法是正确的,我需要从拟合点渲染相同的样条曲线 因为BricsCAD是从拟合点推断出的方向和大小的切线.

Now I know the interpolation method is correct, all I need to render the same spline from fit points as BricsCAD are the end-tangents in direction and magnitude inferred from the fit points.

我需要控制顶点来渲染B样条曲线,但是开始和 像方案1一样,最终切线未存储在DXF文件中. 需要估计开始和结束切线,最好的结果是: 皮耶尔(Piegl&)的"The NURBS Book"中的"5点插值"分iller

I need the control vertices to render the B-spline, but start- and end tangents are not stored in the DXF file like in scenario 1. Estimation of start- and end tangents is required, best result by: "5 Point Interpolation" from "The NURBS Book", Piegl & Tiller

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度.

And surprise the estimations are not correct, BricsCAD spline has tangent angles of 101.0035408517495 and -101.0035408517495 degrees.

真正令人讨厌的部分是,如果我使用BricsCAD角度作为输入, 花键仍然不匹配,所以我认为切线大小 估计与方案2不同.

And the really annoying part is, if I use the BricsCAD angles as input, the splines still does not match, so I assumed that the tangent magnitude estimation is different from scenario 2.

以下值是从BricsCAD保存的DXF文件中计算得出的 SPLINE的方法"从拟合点"切换为控制顶点". 根据这些数据,我计算出了切线角和幅度, tangent vector = 2nd control vertex - 1st control vertex

Following values are calculated from a DXF file saved by BricsCAD and SPLINE "Method" switched from "fit points" to "control vertices". From this data I calculated the tangent angles and also the magnitudes, 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')

现在花键再次匹配:

  1. 如果给出切线(存储在DXF中),则切线的输入切线的大小 插值功能是总弦长".
  2. 没有给定的切线,其大小是不同的,在此示例中:m1*1.3097943444804256, 但这不是一个恒定因素.
  1. If tangents are given (stored in DXF) the magnitude of the input tangents for the interpolation function is "total chord length".
  2. Without given tangents the magnitude is different, in this example: m1*1.3097943444804256, but it is not a constant factor.

最大的问题是:如何估计方向和大小上的起点和终点切线 像AutoCAD或BricsCAD那样仅由拟合点定义的样条线?

The big question is: How to estimate the start- and end tangents in direction and magnitude like AutoCAD or BricsCAD for splines defined only by fit points?

预先感谢

Manfred

推荐答案

SPLINE实体的起始切线x,y,z和13,23可以具有可选组代码12,22,32,终点切线x,y,z为33.我检查了netDxf项目的源代码,然后得出的结论是,如果仅将拟合点用于定义样条线,则将指定开始和结束切线值 .

The SPLINE entity can have optional group codes 12,22,32 for start tangent x,y,z and 13,23,33 for end tangent x,y,z. I've checked source code of netDxf project, and it follows that if fit points only are used to define the spline, then start and end tangent values are to be specified.

摘自AutoCAD 2012 DXF SPLINE实体参考:

From AutoCAD 2012 DXF Reference for SPLINE entity:

12起始切线-可以省略(在WCS中)DXF:X值; APP:3D点

12 Start tangent—may be omitted (in WCS) DXF: X value; APP: 3D point

22、32 DXF:起始切线的Y和Z值-可以省略(在WCS中)

22, 32 DXF: Y and Z values of start tangent—may be omitted (in WCS)

13结束切线-可以省略(在WCS中)DXF:X值; APP:3D点

13 End tangent—may be omitted (in WCS) DXF: X value; APP: 3D point

23、33 DXF:端切线的Y和Z值-可以省略(在WCS中)

23, 33 DXF: Y and Z values of end tangent—may be omitted (in WCS)

昨天,我们与我的同事在Autocad 2020中创建了一些DXF文件,包括拟合点样条线.导出到DXF后,样条线由控制点和结点定义.因此,我猜测拟合点已过时或仅用于UI.

We created a few DXF files yesterday with my colleague in Autocad 2020, including fit-point splines. After export to DXF, the splines were defined by control points and knots. So I have a guess that fit points is something obsolete or UI-only.

这篇关于AutoCAD如何计算仅由拟合点定义的样条线的最终切线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆