简体   繁体   English

如何找到圆中多边形无点的圆和多边形的交点

[英]How can we find intersection of circle and polygon for no point of polygon in circle

Suppose i have one polygon and one circle of google drawingmanager (google maps). 假设我有一个多边形和一个圆圈的Google Drawingmanager(谷歌地图)。 The scenario is that no point of polygon is in the circle but still intersecting. 场景是多边形中没有点,但仍然相交。 How can i check the intersection in this case? 在这种情况下,如何检查路口? ![Circle and Polygon are intersecting and there is no point of polygon inside the circle][1] ![圆和多边形相交,并且圆内没有多边形点] [1]

Check each point of polygon for this condition: 检查多边形的每个点是否满足以下条件:

dx^2+dy^2 < r^2

where dx = px[i] - cx, dy = py[i] - cy,
px[i], py[i] - i-point of polygon, cx,cy - circle center, r - radius

If its true for at least one i, then intersection have place. 如果对于至少一个i为真,则交点存在。

Update: 更新:

In case if no point is directly in circle, it's getting harder. 如果没有点直接在圆周上,它会变得越来越难。 You'll need to check each line against circle for intersections. 您需要对照圆检查每条线的交点。

To detect intersection of line with circle, use following check: 要检测直线与圆的交点,请使用以下检查:

line equation is l(t) = [lx(t), ly(t)]
where lx = x0 + t*(x1-x0), ly = y0 + t*(y1-y0), and t here is variable between 0 and 1

if line intersects circle, there will be such value of t (say, t0), with which
l0x = lx(t0), l0y = ly(t0) fills condition

(l0x - cx)^2 + (l0y - cy)^2 < r^2

we need to find t0, and check if it's in range 0..1, here how we do it:

(x0 + t0*(x1-x0) - cx)^2 + (y0 + t0*(y1-y0) - cy)^2 = r^2

by solving this quadratic equation we will find 0, 1 or 2 solutions of t0
if it's 0 solutions - circle never intersects line
if it's 1 solution - circle touches line in 1 point
if it's 2 solution (t0a, t0b) - circle intersects line in 2 points, and additional check will be needed to check if range [t0a, t0b] intersects with range [0, 1]

to solve this equation we need normalize it:
(x0 + t0*(x1-x0) - cx)^2 + (y0 + t0*(y1-y0) - cy)^2 = r^2       equal to
((x0-cx) + t0*(x1-x0))^2 + ((y0 - cy) + t0*(y1-y0))^2 - r^2 = 0      equal to
(x0-cx)^2 + (t0*(x1-x0))^2 + 2*t0*(x1-x0)*(x0-cx) + (y0-cy)^2 + (t0*(y1-y0))^2 + 2*t0*(y1-y0)*(y0-cy) - r^2 = 0    equal to

t0^2 * A + t0 * B + C = 0, where
A = (x1-x0)^2 + (y1-y0)^2
B = 2*(x1-x0)*(x0-cx) + 2*(y1-y0)*(y0-cy)
C = (x0-cx)^2 + (y0-cy)^2 - r^2

I will not write here how to solve such standart quadratic equation, it's offtopic. 我不会在这里写如何解决这样的标准二次方程式,这是题外话。

If you will have a solution with 2 values, say t0a and t0b, then you need to check it against range [0, 1]. 如果您有一个包含2个值的解决方案,例如t0a和t0b,则需要对照范围[0,1]进行检查。

For example: 例如:

t0a = -3.4, t1a = 2.1 - intersection occurs, 
t0a = -3.4, t1a = -2.1 - intersection not occurs, 
t0a = 0, t1a = 0.5 - intersection occurs 

Yeah, and probably you will need to sort t0a and t0b, there is no guaranty that t0a < t0b 是的,可能您需要对t0a和t0b进行排序,因此无法保证t0a <t0b

You will need to run this check for each line of polygon. 您将需要为多边形的每条线运行此检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM