Considering the image above, I want to manually increase the length of a bezier curve control point (C3
to newC3
) by a certain value (say 0.5f) while preserving it’s original direction. How can I do this?
\$\begingroup\$
\$\endgroup\$
1
-
1\$\begingroup\$ Don't forget to search for existing Q&A that might cover your needs \$\endgroup\$– DMGregory ♦Commented Oct 4, 2018 at 13:33
Add a comment
|
1 Answer
\$\begingroup\$
\$\endgroup\$
0
You normalize the vector "C4_C3" and multiply it by the new length it should have. Subtracting the coordinates of C4 with the coordinates of C3 (or the other way around) gives you the gradient between those two points. Normalizing it scales this gradient down so its length is 1. Multiplying with the new length results in a new gradient that you can add to your C4 coordinates.
normalization:
l = sqrt(x²+y²)
x = x / l;
y = y / l;
so in total:
x = c4.x - c3.x;
y = c4.y - c3.y;
l = sqrt(x²+y²)
x = c4.x + (x / l) * newLength;
y = c4.y + (y / l) * newLength;