问题描述
想象一个圆圈.想象一个馅饼.想象一下,试图返回一个布尔值来确定所提供的 X、Y 参数是否包含在其中一个饼图中.
我对弧线的了解:
我有 CenterX、CenterY、Radius、StartingAngle、EndingAngle、StartingPoint(圆周上的点)、EndingPoint(圆周上的点).
给定 X,Y 坐标,我想确定该坐标是否包含在饼图幻灯片中的任何位置.
我知道这个问题很老,但没有一个答案考虑圆弧的位置.
该算法认为所有角度都在 0 到 360 度之间,弧线沿数学正方向(逆时针)绘制
首先您可以转换为极坐标:半径 (R) 和角度 (A).注意:如果可用,请使用 Atan2 功能.
2) 如果 S > E 那么有两种可能的情况
- 如果 A > S
那么这个点就在切片里面
- 如果 A
那么这个点就在切片里面
在所有其他情况下,该点位于切片之外.
Imagine a circle. Imagine a pie. Imagine trying to return a bool that determines whether the provided parameters of X, Y are contained within one of those pie pieces.
What I know about the arc:
I have the CenterX, CenterY, Radius, StartingAngle, EndingAngle, StartingPoint (point on circumference), EndingPoint (point on circumference).
Given a coordinate of X,Y, I'd like to determine if this coordinate is contained anywhere within the pie slide.
I know this question is old but none of the answers consider the placement of the arc on the circle.
This algorithm considers that all angles are between 0 and 360, and the arcs are drawn in positive mathematical direction (counter-clockwise)
First you can transform to polar coordinates: radius (R) and angle (A). Note: use Atan2 function if available. wiki
R = sqrt ((X - CenterX)^2 + (Y - CenterY)^2)
A = atan2 (Y - CenterY, X - CenterX)
Now if R < Radius the point is inside the circle.
To check if the angle is between StartingAngle (S) and EndingAngle (E) you need to consider two possibilities:
1) if S < E then if S < A < E the point lies inside the slice
2) if S > E then there are 2 possible scenarios
- if A > S
then the point lies inside the slice
- if A < E
then the point lies inside the slice
In all other cases the point lies outside the slice.
这篇关于如何确定点 (X,Y) 是否包含在圆的弧段内(即饼图切片)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!