简体   繁体   English

查找两个弧之间的交点

[英]find point of intersection between two arc

I'm creating a game for kids. 我正在为孩子们制作游戏。 It's creating a triangle using 3 lines. 它使用3条线创建一个三角形。 How I approached this is I create two arcs(semi circle) from two end points of a base line. 我是如何从基线的两个端点创建两个圆弧(半圆)的。 But I couldn't figure how to find the point of intersection of those two arc. 但是我不知道如何找到这两个弧的交点。 I've search about it but only found point of intersection between two straight lines. 我已经搜索过了,但是只找到两条直线之间的交点。 Is there any method to find this point of intersection? 有什么方法可以找到这个交点? Below is the figure of two arcs drawn from each end of the baseline. 下图是从基线的两端绘制的两个弧线的图。

在此处输入图片说明

While you have not stated clearly, I assume that you have points with coordinates (AX, AY) and (BX, BY) and lengths of two sides LenA and LenB and need to find coordinates of point C. 尽管您没有明确说明,但我假设您的点的坐标为(AX, AY)(BX, BY)且两边的长度为LenALenB并且需要查找点C的坐标。

So you can make equation system exploiting circle equation: 因此,您可以利用圆形方程式建立方程式系统:

(C.X - A.X)^2 + (C.Y - A.Y)^2 = LenA^2
(C.X - B.X)^2 + (C.Y - B.Y)^2 = LenB^2

and solve it for unknowns CX, CY 并解决未知的CX,CY

Not that it is worth to subtract A coordinates from all others, make and solve simpler system (the first equation becomes C'.X^2 + C'.Y^2 = LenA^2 ), then add A coordinates again 从所有其他坐标中减去A坐标,制造并求解更简单的系统(第一个方程变为C'.X^2 + C'.Y^2 = LenA^2 ),然后再次添加A坐标, C'.X^2 + C'.Y^2 = LenA^2

Assume centers of the circle are ( x1 , y1 ) and ( x2 , y2 ), radii are R1 and R2 . 假设圆的中心为( x1y1 )和( x2y2 ),半径为R1R2 Let the ends of the base be A and B and the target point be T . 设底端为AB ,目标点为T We know that AT = R1 and BT = R2 . 我们知道AT = R1BT = R2 IMHO the simplest trick to find T is to notice that difference of the squares of the distances is a known constant (R1^2 - R2^2) . 恕我直言,找到T的最简单技巧是注意到距离的平方差是一个已知的常数(R1^2 - R2^2) And it is easy to see that the line the contains points meeting this condition is actually a straight line perpendicular to the base. 可以很容易地看到,满足此条件的包含点的线实际上是垂直于底线的直线。 Circles equations: 圆方程:

(x - x1)^2 + (y-y1)^2 = R1^2    
(x - x2)^2 + (y-y2)^2 = R2^2

If we subtract one from another we'll get: 如果我们一个减去另一个,我们将得到:

(x2 - x1)(2*x - x1 - x2) + (y2 - y1)(2*y - y1 - y2) = R1^2 - R2^2

Let's x0 = (x1 + x2)/2 and y0 = (y1 + y2)/2 - the coordinates of the center. x0 = (x1 + x2)/2y0 = (y1 + y2)/2中心的坐标。 Let also the length of the base be L and its projections dx = x2 - x1 and dy = y2 - y1 (ie L^2 = dx^2 + dy^2 ). 还要使底边的长度为L并且其投影dx = x2 - x1dy = y2 - y1 (即L^2 = dx^2 + dy^2 )。 And let's Q = R1^2 - R2^2 So we can see that Q = R1^2 - R2^2这样我们可以看到

2 * (dx * (x-x0) + dy*(y-y0)) = Q

So the line for all (x,y) pairs with R1^2 - R2^2 = Q = const is a straight line orthogonal to the base (because coefficients are exactly dx and dy ). 因此,所有(x,y)对的线都具有R1^2 - R2^2 = Q = const的直线是与底正交的直线(因为系数恰好是dxdy )。

Let's find the point C on the base that is the intersection with that line. 让我们在与该线的交点找到基点C It is easy - it splits the base so that difference of the squares of the lengths is Q . 这很容易-分割底数,使长度平方的差为Q It is easy to find out that it is the point on a distance L/2 + Q/(2*L) from A and L/2 - Q/(2*L) from B . 这是很容易地发现,它是在一个距离的点L/2 + Q/(2*L)AL/2 - Q/(2*L)B So now we can find that 所以现在我们可以找到

  TC^2 = R1^2 - (L/2 + Q/(2*L))^2

Substituting back Q and simplifying a bit we can find that 代入Q并简化一点,我们可以发现

  TC^2 = (2*L^2*R1^2 + 2*L^2*R2^2 + 2*R1^2*R2^2 - L^4 - R1^4 - R2^4) / (4*L^2)

So let's 那么我们

 a = (R1^2 - R2^2)/(2*L)
 b = sqrt(2*L^2*R1^2 + 2*L^2*R2^2 + 2*R1^2*R2^2 - L^4 - R1^4 - R2^4) / (2*L)

Note that formula for b can also be written in a different form: 请注意, b公式也可以用其他形式编写:

 b = sqrt[(R1+R2+L)*(-R1+R2+L)*(R1-R2+L)*(R1+R2-L)] / (2*L)

which looks quite similar to the Heron's formula . 看起来很像苍鹭的公式 And this is not a surprise because b is effectively the length of the height to the base AB from T in the triangle ABT so its length is 2*S/L where S is the area of the triangle. 这并不奇怪,因为b实际上是三角形ABTT到底部AB的高度的长度,因此b的长度为2*S/L ,其中S是三角形的面积。 And the triangle ABT obviously has sides of lengths L , R1 and R2 respectively. 三角形ABT显然具有分别为LR1R2

To find the target T we need to move a along the base and b in a perpendicular direction. 为了找到目标T我们需要沿底部沿垂直方向移动a ,使b垂直移动。 So coordinates of T calculated from the middle of the segment are: 因此,从线段中间计算出的T坐标为:

 Xt = x0 + a * dx/L ± b * dy / L
 Yt = y0 + a * dy/L ± b * dx / L

Here ± means that there are two solutions: one on either side of the base line. 这里的±表示有两种解决方案:一种在基线的两侧。

Partial case: if R1 = R2 = R , then a = 0 and b = sqrt(R^2 - (L/2)^2) which makes obvious sense: T lies on the segment bisector on a length of sqrt(R^2 - (L/2)^2) from the middle of the segment. 部分情况:如果R1 = R2 = R ,则a = 0b = sqrt(R^2 - (L/2)^2)这很明显: T位于sqrt(R^2 - (L/2)^2)从片段的中间开始。

Hope this helps. 希望这可以帮助。

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

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