简体   繁体   English

从圆上的点计算切线?

[英]Calculating tangent from a point on a circle?

I'm trying to create an algorithm to find the tangent on a circle so that I can calculate the angle of reflection for that circle when it collides with an object. 我正在尝试创建一个算法来查找圆上的切线,以便我可以计算该圆与物体碰撞时的反射角。 I know the x and y values of the centre of the circle and the radius. 我知道圆心和半径的x和y值。 I also have the x and y values for the point of impact with the other object. 我还有与另一个对象的影响点的x和y值。 Any help with how to calculate the tangent perhaps using a Java library would be great, or if anyone has any recommendations on how to calculate the angle of reflection another way would be appreciated. 任何有关如何使用Java库计算切线的帮助都会很棒,或者如果有人对如何计算反射角有任何建议,那么另一种方法将会受到重视。 Thanks. 谢谢。

From what I understand, you actually want to calculate the angle of incidence for the circle. 据我所知,你实际上想要计算圆的入射角。 For this, you need to know the angle of the circle's movement and the angle of the surface it is bouncing off; 为此,您需要知道圆的运动角度和它反弹的表面角度; the point of collision will not be enough since it is the same no matter the angle the circle collides at. 碰撞点是不够的,因为无论圆碰撞的角度是什么,它都是相同的。 If you have this angle, then the circle's new angle is given by (360 - circle's angle + (surface's angle * 2)) % 360 . 如果你有这个角度,那么圆的新角度由(360 - circle's angle + (surface's angle * 2)) % 360 I doubt you keep track of the circle's angle of movement, though you may already have two variables describing its movement, perhaps something along the lines of: "for every update, move circle dx units right and dy units up". 我怀疑你是否记录了圆的运动角度,尽管你可能已经有两个变量来描述它的运动,可能是这样的:“对于每次更新,将圆圈dx单位向右移动, dy向上运动”。 If you have this you can compute the circle's angle in degrees with (180 / π) * arctan(dy / dx) . 如果你有这个,你可以用(180 / π) * arctan(dy / dx)计算圆的角度。 This formula works because dy / dx gives the slope of the line created by the movement of the circle across the plane. 此公式有效,因为dy / dx给出了圆在平面上移动所产生的直线的斜率。 Once we have the slope, we take the inverse tangent (arctan) of it which gives its angle in radians. 一旦我们得到了斜率,我们就得到它的反正切(arctan),它以弧度给出它的角度。 Finally we convert that angle to degrees with the 180 / π part. 最后,我们将该角度转换为180 / π ° 180 / π部分的角度。

This also works if we use the slope of the surface. 如果我们使用表面的斜率,这也有效。 Say the surface is a line starting at point (x1, y1) and ending at point (x2, y2) . 假设曲面是从点(x1, y1)并在点(x2, y2)结束的线。 The surface's slope is found with (y1 - y2) / (x1 - x2) . 表面的斜率为(y1 - y2) / (x1 - x2) Then we can apply the formula as before, substituting the slope of the surface, like so: (180 / π) * arctan((y1 - y2) / (x1 - x2)) . 然后我们可以像以前一样应用公式,代替表面的斜率,如下所示: (180 / π) * arctan((y1 - y2) / (x1 - x2))

Now you have both the circle and the surface in terms of degrees and can apply the first formula above. 现在,您可以根据度数获得圆和曲面,并且可以应用上面的第一个公式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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