简体   繁体   中英

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:

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?

Thank you.

EDIT: Answer to @MBo: Yes, although not sure I am applying it correctly. As soon as I derivate, I loose 1 dim, so I'm not sure what to do with the 4 points. 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

Also tried with 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

So MBo you were right, my LUT was wrong, I figured it out, I'm now using

 3 0 0
-6 6 0
 3 -6 3

and it is working perfectly! Thanks for pointing what was wrong!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM