Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find the angle between two points on a bezier curve?

Tags:

opengl

bezier

In my current OpenGL project I am trying to make the links of a chain hug the contours of a Bezier curve. How can I find the angle between two points on the curve so that I can position the links of the chain so that they follow the curve.

Here is a picture of the curve and chain, I need some way of rotating the links so that they follow the curve.

Does anybody here know how to do this?

like image 926
NeatRobot Avatar asked Jan 22 '26 21:01

NeatRobot


2 Answers

Maybe something like this is what you need.

How to calculate the tangent to a Bezier curve

This is hard to find online. It must be a secret closely held by those who know. Oh you can find the math formulae, but have fun interpreting them if you are not a mathematician. So what is a poor developer to do? Go back to school.

I spent a couple days bashing my skull over this one. I googled my brains out (which was easier once my skull was sufficiently bashed). Then one bright beautiful Saturday, I was holed up in my developer's dungeon resting my weary bones. I had the TV on in front of me and Wikipedia to the right and there I was lazily switching between watching them both.

Continue Reading...

like image 144
duffymo Avatar answered Jan 26 '26 02:01

duffymo


Let the points on your bezier curve be A and B. Normalize the Vector AB so it has length 1. Let this be AB_norm. Then use asin(AB_norm.y) or acos(AB_norm.x) to get the angle. An angle of 0 degrees is a horizontal vector to the right, then. C-style pseudocode follows:

 get_angle(Point A, Point B) {
   AB.x = B.x - A.x;
   AB.y = B.y - A.y;
   length = sqrt(AB.x * AB.x + AB.y * AB.y);

   AB_norm.y /= AB.y / length;
   angle = asin(AB_norm.y);
   // or
   // AB_norm.x /= AB.x / length;
   // angle = acos(AB_norm.x);
 }

 angle = get_angle(A, B);
 glRotatef(angle, 0.0f, 0.0f, 1.0f);
 // Draw the chain link here
like image 29
schnaader Avatar answered Jan 26 '26 02:01

schnaader