Calculate point and circle segment collision

你说的曾经没有我的故事 提交于 2020-01-02 10:33:33

问题


If I have calculated an intersection point between a line segment and a circle, how can I tell whether or not this intersection point lies on a segment of the circle?

I have the equations to tell whether or not a line segment intersects with the circle, and I also have the intersection point on that circle, but what I need to know is whether or not this collision point on the circle lies within the bounds of a specific arg segment of that circle. I have the end points of the arc segment, the circle's center & radius, and the point of collision.


回答1:


Transform the intersection point into polar coordinates around the center and compare the angles.




回答2:


As an alternative to Dario's idea (which should work as well), you can:

  1. Calculate the distances between the intersection point and the endpoints of the arc (referred to as intdist1 and intdist2).
  2. Calculate the distance between the endpoints of the arc (arcdist).
  3. If the arc is less than half of the circle (covers less than 180 degrees), then you know if the point is in the arc if intdist1 and intdist2 are both less than arcdist.
  4. Else, if the arc is greater than half the circle (covers more than 180 degrees), then you know if the point is in the arc if either intdist1 or intdist2 are greater than arcdist.

I'm guessing, since you haven't specified otherwise, that the arc between the endpoints goes the short way around. In that case, you don't need to worry about step 4 above.

The method fails though if you are using an arc that covers exactly 180 degrees of the circle. In that case you could break the 180 degrees arc into 90 degree arcs and check both of them I suppose.

Also, you can of course use the square of the distance for comparison of these distances to save yourself the square root. In addition, this method should be faster than calculating the angles because those involve using expensive inverse cosines.



来源:https://stackoverflow.com/questions/3712729/calculate-point-and-circle-segment-collision

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!