如何在贝塞尔曲线上找到两点之间的角度?

时间:2021-10-30 11:31:14

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.

在我目前的OpenGL项目中,我试图让链条的链接拥抱贝塞尔曲线的轮廓。如何找到曲线上两点之间的角度,以便我可以定位链的链接,使它们跟随曲线。

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?

这里有人知道怎么做吗?

3 个解决方案

#1


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...

#2


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:

让贝塞尔曲线上的点为A和B.将Vector AB归一化,使其长度为1.将其设为AB_norm。然后使用asin(AB_norm.y)或acos(AB_norm.x)来获取角度。然后,0度的角度是向右的水平向量。 C风格的伪代码如下:

 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

#3


You need some math here. You can find tangent, normal, and binormal vectors, and then you can find the angle. If you are still interested let me know, I have some details on this topic.

你需要一些数学。您可以找到切线,法线和副法线矢量,然后就可以找到角度。如果您仍然有兴趣让我知道,我有一些关于这个主题的细节。

#1


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...

#2


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:

让贝塞尔曲线上的点为A和B.将Vector AB归一化,使其长度为1.将其设为AB_norm。然后使用asin(AB_norm.y)或acos(AB_norm.x)来获取角度。然后,0度的角度是向右的水平向量。 C风格的伪代码如下:

 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

#3


You need some math here. You can find tangent, normal, and binormal vectors, and then you can find the angle. If you are still interested let me know, I have some details on this topic.

你需要一些数学。您可以找到切线,法线和副法线矢量,然后就可以找到角度。如果您仍然有兴趣让我知道,我有一些关于这个主题的细节。