问题描述
我正在寻找一种快速的方法来确定矩形和圆形之间的交叉区域(我需要进行数百万次这些计算)。
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:
Most of the points you'll need to use can be found by finding the intersection of a line and a circle
The areas you need to compute can be found by computing the area of a circular segment and computing the area of a triangle.
You can determine if a vertex is inside the circle by calculating if its distance from the center is less than the radius.
这篇关于圆和矩形之间的交叉区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!