在CNC上,通常不仅有2D图像,还有速度、工具角度、每个轴运动学的多个执行器等等。为此,我通常使用参数化立方曲线,参数为t=<0.0,1.0>
。因此,我将路径转换为一组立方曲线,这些曲线可以在任何维度中轻松计算。完成此步骤后,您有三种常规的栅格化方式:
constant dt
step
parametric cubics are usually nonlinear so in order to move to another pixel (or whatever) you need to increase parameter t
with smaller step than your resolution is something like:
dt < 1.0 / curve_length
the less dt
is the better chances are you will not miss a pixel but of coarse will have many more duplicate positions.
search next dt
step
using binary search you can find what is the next t
so the distance to current position is single pixel. This is much more precise but also slower up to a point...
convert to lines
you can sample your cubic curve into set of lines (how many depends on size of the curve) and rasterize lines as usuall using DDA or Bresenham. This is simplest but the result will not be exactly a curve.
立方体是这样的:
P(t) = a0 + a1*t + a2*t^2 + a3*t^3
t = <0.0,1.0>
其中P(t)
表示位置,a0,a1,a2,a3
是向量的系数,其中每个轴都有自己的标量系数。
请参见如何生成多点线性插值?以及如何使用/计算它们的子链接。
无论如何,如果您坚持假设为圆弧插值:
P(t) = ( Rotation_matrix(t) * (P0 - Pcenter) ) + Pcenter
t = <0.0,2*PI>
Rotation_matrix
是旋转矩阵,它可以将你的点围绕(0,0,0,...,0)
以曲线方向旋转t [rad]
,P0
是起点,Pcenter
是弧线的中心。
如果旋转轴不与坐标轴对齐,则可以使用Rodrigues_rotation_formula。
然而,在ND中,最好使用homogenous transform matrices,只需扩大矩阵大小即可: