[英]Derivative of a Bezier curve in matrix form
I'm working with some bezier curves.我正在处理一些贝塞尔曲线。 I get my position at parameter using directly matrices, no decasteljau involved, I find it more elegant:我直接使用矩阵在参数处得到我的 position,不涉及 decasteljau,我觉得它更优雅:
v_t = np.array([1, t, t**2, t**3])
cubic = np.array([
[ 1., 0., 0., 0.],
[-3., 3., 0., 0.],
[ 3., -6., 3., 0.],
[-1., 3., -3., 1.]
])
pos_at_param = np.dot(np.dot(v_t, cubic), control_points)
Works just fine.工作得很好。 But I would like to compute my tangents using the same logic但我想使用相同的逻辑计算我的切线
Whether I start from无论我从
(1-t)**3 +
3(1-t)**2t +
3(1-t)t**2 +
t**3
Gets all those derivatives, and recreate a matrix out of it,获取所有这些导数,并从中重新创建一个矩阵,
Or start from the derivative I found online或者从我在网上找到的导数开始
3(1-t)(1-t) * (p1 - p0) +
6t(1-t) * (p2 - p1) +
3tt * (p3 - p2)
Giving me给我
[ 3., 0., 0.]
[-6., 6., 0.]
[ 3., -5., 3.]
None of those seem to give me the actual derivative / tangent vector on my curve at the given param.这些似乎都没有给我在给定参数的曲线上的实际导数/切线向量。 Am I doing something wrong?难道我做错了什么? Is it simply impossible to compute the tangent of a curve using the same logic than the position?是否根本不可能使用与 position 相同的逻辑来计算曲线的正切?
Thank you.谢谢你。
EDIT: Answer to @MBo: Yes, although not sure I am applying it correctly.编辑:回答@MBo:是的,虽然不确定我是否正确应用它。 As soon as I derivate, I loose 1 dim, so I'm not sure what to do with the 4 points.一旦我推导,我就失去了 1 个点,所以我不确定如何处理 4 个点。 I tried this:我试过这个:
LUT = np.array([
[3., 0., 0.],
[-6.,6., 0.],
[3.,-5., 3.],
])
t = 0.5
v_params = np.array([1, t, t**2])
P0 = np.array([0., 40., 0.])
P1 = np.array([0., 80., 0.])
P2 = np.array([100., 80., 0.])
P3 = np.array([100., 40., 0.])
points = np.array([
P1-P0,
P2-P1,
P3-P2
])
out = np.dot(np.dot(v_params, LUT), points)
out /= np.linalg.norm(out)
But doesn't work after 0.5但在 0.5 之后不起作用
Also tried with 4d也尝试过 4d
LUT = np.array([
[3., 0., 0., 0.],
[-6.,6., 0., 0.],
[3.,-5., 3., 0.],
[0., 0., 0., 0.]
])
v_params = np.array([1, t, t**2, t**3])
Assuming t^3 will be cancelled by my last 0. row, but doesn't work neither假设 t^3 将被我的最后 0. 行取消,但也不起作用
So MBo you were right, my LUT was wrong, I figured it out, I'm now using所以MBo你是对的,我的LUT错了,我想通了,我现在正在使用
3 0 0
-6 6 0
3 -6 3
and it is working perfectly!它运行良好! Thanks for pointing what was wrong!感谢您指出问题所在!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.