Laj*_*pad 11
我已经阅读了brainjam的答案,并检查他的答案是否正确,他是对的.计算:O(0; 0),A(a; 0)和B(x; y)是三角形的三个点.C1是A周围的圆,r1 = c; C2是O周围的圆,r2 = b.B(X; Y)是C1和C2的交点,这意味着该点位于两个圆上.
C1:(x-a)*(x-a)+ y*y = c*c
C2:x*x + y*y = b*b
y*y = b*b - x*x
(x-a)*(x-a)+ b*b-x*x = c*c
x*x - 2*a*x + a*a + b*b - x*x - c*c = 0
2*a*x =(a*a + b*b - c*c)
x =(a*a + b*b - c*c)/(2*a)
y*y = b*b - ((a*a + b*b - c*c)/(2*a))*((a*a + b*b - c*c)/(2*a) )
y = + - sqrt(b*b - ((a*a + b*b - c*c)/(2*a))*((a*a + b*b - c*c)/(2*一个)))
今天这个问题和答案帮助我实现了这个目标.它将计算未知顶点,给出2个已知点(a,b)的圆交点的"c"和到第3个未知顶点的距离(ac_length,bc_length),"c".这是我感兴趣的任何人的python实现.
我还引用了以下内容:
http://mathworld.wolfram.com/RadicalLine.html
http://mathworld.wolfram.com/Circle-CircleIntersection.html
使用django的地理模块作为Point()
对象,可以用形状替换,或者完全删除点对象.
from math import sqrt
from django.contrib.gis.geos import Point
class CirclesSeparate(BaseException):
pass
class CircleContained(BaseException):
pass
def discover_location(point_a, point_b, ac_length, bc_length):
"""
Find point_c given:
point_a
point_b
ac_length
bc_length
point_d == point at which the right-angle to c is formed.
"""
ab_length = point_a.distance(point_b)
if ab_length > (ac_length + bc_length):
raise CirclesSeparate("Given points do not intersect!")
elif ab_length < abs(ac_length - bc_length):
raise CircleContained("The circle of the points do not intersect")
# get the length to the vertex of the right triangle formed,
# by the intersection formed by circles a and b
ad_length = (ab_length**2 + ac_length**2 - bc_length**2)/(2.0 * ab_length)
# get the height of the line at a right angle from a_length
h = sqrt(abs(ac_length**2 - ad_length**2))
# Calculate the mid point (point_d), needed to calculate point_c(1|2)
d_x = point_a.x + ad_length * (point_b.x - point_a.x)/ab_length
d_y = point_a.y + ad_length * (point_b.y - point_a.y)/ab_length
point_d = Point(d_x, d_y)
# get point_c location
# --> get x
c_x1 = point_d.x + h * (point_b.y - point_a.y)/ab_length
c_x2 = point_d.x - h * (point_b.y - point_a.y)/ab_length
# --> get y
c_y1 = point_d.y - h * (point_b.x - point_a.x)/ab_length
c_y2 = point_d.y + h * (point_b.x - point_a.x)/ab_length
point_c1 = Point(c_x1, c_y1)
point_c2 = Point(c_x2, c_y2)
return point_c1, point_c2
Run Code Online (Sandbox Code Playgroud)