问题描述
我正在尝试以编程方式在dxf文件中创建样条曲线.我需要使用拟合点,因为曲线需要通过指定的点.我了解我也需要使用控制点.有没有公式可以计算出这些值?这是一个有四个拟合点的闭合样条线.
I'm trying to create a spline curve programmatically in a dxf file. I need to use fit points as the curve needs to pass through the specified points. I understand I also need to use control points. Is there a formula to calculate what these should be? It is a closed spline with four fit points.
提前谢谢!
推荐答案
我认为这不是一件容易的事.除了控制点之外,您还需要确定结点.有一个DXF阅读器/查看器此处(用C ++编写)声称支持样条线.也许您可以通过阅读代码找到一些信息.
I think this is not an easy task. In addition to the control points, you will also need to determine the knots. There is a DXF reader/viewer here (written in C++) which claims to support spline. May be you can find some information by reading the code.
AutoCAD使用的NURBS是近似曲线(曲线仅通过第一个点和最后一个点).在用户界面中,将插入样条曲线(曲线通过拟合点),因此在读取/写入DXF文件时会进行平移.如果您创建一个包含4个拟合点的封闭点,您将在DXF文件中看到7个控制点:
AutoCAD uses NURBS which are approximated curves (the curve pass only by the first and last points). In the user interface, splines are interpolated (the curve pass by the fit points), so there is a translation which is done when reading/writing a DXF file. If you create a closed point with 4 fit points, you will see there is 7 controls points in the DXF file:
使用多段线来逼近样条线会更容易.这是一条折线的样例(L形从0,0-> 100,0-> 100,50开始)
Using a polyline to approximate your spline will be easier. Here is a sample of a polyline (L shape starting from 0,0 -> 100, 0 -> 100, 50)
0
LWPOLYLINE
5
D5
330
70
100
AcDbEntity
8
0
100
AcDbPolyline
90
3
70
0
43
0.0
10
0.0
20
0.0
10
100.0
20
0.0
10
100.0
20
50.0
要从拟合点计算控制点的位置,可以查阅此页面( §24和§25).实际上,您需要反转Casteljau的算法(对于Bezier曲线;我不知道它对NURBS的工作原理).
To compute the position of the control points from the fit points, you can consult this page (§24 & §25). In fact you need to reverse the Casteljau's algorithm (for Bezier curves; I don't know how it works for NURBS).
这篇关于如何使用拟合点创建dxf样条曲线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!