圆与矩形的交点面积 [英] Area of intersection between circle and rectangle

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

问题描述

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

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).

一个特定的属性是,在所有情况下,圆和矩形总是有 2 个交点.

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

推荐答案

给定 2 个交点:

0 个顶点在圆内:圆段的面积一个>

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个顶点在圆内:一个圆弧和一个三角形的面积之和.

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个顶点在圆内:两个三角形和一个圆线段的面积之和

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个顶点在圆内:矩形的面积减去三角形的面积加上圆弧的面积

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

要计算这些面积:

你需要计算的面积可以通过计算一个圆弧的面积计算三角形的面积.

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.

这篇关于圆与矩形的交点面积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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