圆和矩形之间的交叉区域 [英] Area of intersection between circle and rectangle

查看:169
本文介绍了圆和矩形之间的交叉区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种快速的方法来确定矩形和圆形之间的交叉区域(我需要进行数百万次这些计算)。



A具体属性是,在所有情况下,圆和矩形总是有2个交点。

解决方案

给定2个交点: / p>

0顶点位于圆圈内:循环细分

  XXXXX ------------ ------- 
XXXX圆形段
XX XX XX
+ -X ------- X - + XXXXXXXX
| X X |
| XXXXX |

1个顶点位于圆圈内:a的区域总和圆形段和三角形。

  XXXXX XXXXXXXXX 
XX三角形 - > X _-X
XXX _- X
X + - X - + X _- X< - 圆形段
X | X | X- XXX
XXXXX | XXXX
| |

2个顶点位于圆圈内:两个区域的总和三角形和圆形线段

  XXXXX + ------------ X 
XX | _--'/'X
X + - X --- Triangle-> | _-- / X
X | X | _-- / XX< - 圆形段
X + -X ---- + ------- XX
XXXXX三角形^

3个顶点在圆圈内:矩形的面积减去三角形的面积加上圆形的面积分段

  XXXXX 
X + - X + XXX
X | X ------- XXX ----- +< -
X |以外的三角形| X Rect''。 XXX |
X + --- + X''。 XX |
X X''。 X< -
内的圆形段X X ^ | X
X X | X
XXXXX

计算这些区域:




I'm looking for a fast way to determine the area of intersection between a rectangle and a circle (I need to do millions of these calculations).

A specific property is that in all cases the circle and rectangle always have 2 points of intersection.

解决方案

Given 2 points of intersection:

0 vertices is inside the circle: The area of a circular segment

    XXXXX              -------------------
   X     X               X            X Circular segment
  X       X               XX        XX 
+-X-------X--+              XXXXXXXX 
|  X     X   |
|   XXXXX    |

1 vertex is inside the circle: The sum of the areas of a circular segment and a triangle.

    XXXXX                   XXXXXXXXX
   X     X       Triangle ->X     _-X
  X       X                 X   _-  X 
  X    +--X--+              X _-   X <- Circular segment 
   X   | X   |              X-  XXX 
    XXXXX    |              XXXX
       |     | 

2 vertices are inside the circle: The sum of the area of two triangles and a circular segment

    XXXXX                   +------------X
   X     X                  |      _--'/'X 
  X    +--X---    Triangle->|   _--   / X
  X    |  X                 |_--     /XX <- Circular segment
   X   +-X----              +-------XX
    XXXXX                 Triangle^

3 vertices are inside the circle: The area of the rectangle minus the area of a triangle plus the area of a circular segment

    XXXXX
   X  +--X+             XXX
  X   |   X         -------XXX-----+ <- Triangle outside
 X    |   |X        Rect ''.  XXX  |
 X    +---+X                ''.  XX|  
 X         X                   ''. X <- Circular segment inside 
  X       X                       ^|X 
   X     X                         | X 
    XXXXX

To calculate these areas:

这篇关于圆和矩形之间的交叉区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆