1
$\begingroup$

I have calculated the tangent for start point and end point of cubic bezier curve, but the calculated slope and coordinates of tangents are not continuous to the tangent lines (segment $P_0 P_1$ and $P_2 P_3$), as shown in this picture. $m_{start}$ and $m_{end}$ from calculated tangent (blue lines in picture) and tangents which are the subtraction of control points are different. Is there something wrong in my calculation?

The curve equation,

$ C(t) = (1-t)^3P_0 + 3t(1-t)^2P_1+3t^2(1-t)P_2 + t^3P_3 $

Control points are:

$$ P_0 = (14.89, 118.65) $$ $$ P_1 = (40.40, 130.86) $$ $$ P_2 = (65.91, 143.08) $$ $$ P_3 = (71.44, 124.94) $$

Derivative of curve, $$ C'(t) = -3(1-t)^2 P_0 + \left[3(1-t)^2 -6t(1-t)\right]P_1 + \left[6t(1-t)-3t^2\right]P_2 + 3t^2P_3 $$

Substituting the coordinate value of control points in C'(t), $$ x = -59.94t^2 + 76.53 $$ $$ y = -91.02t^2 - 0.06t + 36.66 $$

Tangent at $ t $: $$ T(t) = \frac {C'(t)} {\vert C'(t) \vert} = \frac {C'(t)_x, C'(t)_y} {\sqrt {\left[C'(t)_x\right]^2 + \left[C'(t)_y\right]^2}} $$

Tangent at end point, $ t=1 $: $$ T(1)_x = 0.29 $$ $$ T(1)_y = -0.95 $$

Tangent at start point, $ t = 0 $: $$ T(0)_x = 0.9 $$ $$ T(0)_y = -0.43 $$

Slope equation: $$ m = \frac {y-y_0} {x-x_0} $$

Slope for end tangent, t = 1: $$ m_{end} = \frac {P_{3y}-T(1)_y}{P_{3x}-T(1)_x} = 1.77 $$

Slope for start tangent, t = 0: $$ m_{start} = \frac {P_{0y}-T(0)_y}{P_{0x}-T(0)_x} = 8.45 $$

slope for segment $P_0P_1$,
$$ m_{start} = \frac {P_{0y}-P_{1y}}{P_{0x}-P_{1x}} = 0.47 $$

slope for segment $P_2P_3$,
$$ m_{end} = \frac {P_{2y}-P_{3y}}{P_{2x}-P_{3x}} = -3.28 $$

$\endgroup$
2
$\begingroup$

Tangent at $t=0$ should be $(0.902, 0.4320)$.

From $T(0)$ and $T(1)$, we can compute the slope as $0.432/0.902=0.478$ at $t=0$ and $-0.95/0.29=-3.27$, which matches your computation of slopes from $P_0P_1$ and $P_2P_3$

$\endgroup$
  • $\begingroup$ Tangent at t = 0 is typo error. For cubic bezier curve, $P_0P_1$ and $P_2P_3$ are tangent to start and end point and calculated T(1) and T(0) are supposed to be in a straight line to $P_0P_1$ and $P_2P_3$, but they are not. I have plotted T(1) and T(0) $T_1$ and $T_2$ here. $\endgroup$ – Toat Nov 11 '16 at 5:41
  • 1
    $\begingroup$ Don't know why did you draw T(0) and T(1) as lines connecting the origin and point P0 and P3 respectively. They are not the right way to draw the tangent vectors. $\endgroup$ – fang Nov 11 '16 at 5:59
  • $\begingroup$ I want to visualize and check the calculated result on graph. Is there some way to draw and check the result of calculations? $\endgroup$ – Toat Nov 11 '16 at 6:26
  • 1
    $\begingroup$ To visualize T(0), draw a line connecting P0 and a point P0+mT(0), where m is a magnitude big enough allowing you to see the line. To visualize T(1), draw a line connecting P3 and a point P3+mT(1). $\endgroup$ – fang Nov 11 '16 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.