Compute the area of intersection between a circle and a triangle?

后端 未结 11 1022
礼貌的吻别
礼貌的吻别 2020-12-02 17:38

How does one compute the area of intersection between a triangle (specified as three (X,Y) pairs) and a circle (X,Y,R)? I\'ve done some searching to no avail. This is for

相关标签:
11条回答
  • 2020-12-02 18:16

    How exact do you need to be? If you can approximate the circle with simpler shapes, you can simplify the problem. It wouldn't be hard to model a circle as a set of very narrow triangles meeting at the center, for example.

    0 讨论(0)
  • 2020-12-02 18:17

    I'm almost a year and a half late, but I thought maybe people will be interested in code here that I wrote which I think does this correctly. Look in function IntersectionArea near the bottom. The general approach is to pick off the convex polygon circumscribed by the circle, and then deal with the little circular caps.

    0 讨论(0)
  • Assuming you're talking integer pixels, not real, the naive implementation would be to loop through every pixel of the triangle and check the distance from the circle's center against its radius.

    It's not a cute formula, or particularly fast, but it does get the job done.

    0 讨论(0)
  • 2020-12-02 18:20

    If just one of the triangle's line segments intersects the circle, the pure math solution isn't too hard. Once you know when the two points of intersection are, you can use the distance formula to find the chord length.

    According to these equations:

    ϑ = 2 sin⁻¹(0.5 c / r)
    A = 0.5 r² (ϑ - sin(ϑ))
    

    where c is the chord length, r is the radius, ϑ becomes the angle through the center, and A is the area. Note that this solution breaks if more than half the circle is cut off.

    It's probably not worth the effort if you just need an approximation, since it makes several assumptions about what the actual intersection looks like.

    0 讨论(0)
  • 2020-12-02 18:27

    try computational geometry

    Note: this is not a trivial problem, I hope it's not homework ;-)

    0 讨论(0)
提交回复
热议问题