【发布时间】:2011-04-29 10:52:23
【问题描述】:
三角形三个边的长度,a,b,c 会给出,我需要找到顶点的坐标。中心(可能是外心)可以是原点或 (x,y)。
谁能指出我正确的方向?
【问题讨论】:
标签: math html graph canvas drawing
三角形三个边的长度,a,b,c 会给出,我需要找到顶点的坐标。中心(可能是外心)可以是原点或 (x,y)。
谁能指出我正确的方向?
【问题讨论】:
标签: math html graph canvas drawing
这个问题和答案帮助我今天实现了这一点。它将在给定 2 个已知点 (a, b) 和到第三个未知顶点“c”的距离 (ac_length, bc_length) 的情况下计算圆形交点的未知顶点“c”。 这是我为任何感兴趣的人生成的 Python 实现。
我还引用了以下内容:
http://mathworld.wolfram.com/RadicalLine.html
http://mathworld.wolfram.com/Circle-CircleIntersection.html
对Point() 对象使用django 的geos 模块,可以将其替换为shapely,或者完全删除点对象。
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
【讨论】:
将第一个顶点放在原点 (0,0)。将第二个顶点放置在 (a,0) 处。要计算第三个顶点,请找到中心为 (0,0) 和 (a,0) 且半径为 b 和 c 的两个圆的intersection。
更新: Lajos Arpad 给出了计算this answer 中第三个点位置的详细信息。它归结为 (x,y) 其中 x = (b2+a2-c2)/2a 和 y=±sqrt (b2-x2)
【讨论】:
我已经阅读了 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 * a)))
【讨论】:
首先检查三角形是否可能:
a+b >= c b+c >= a c+a >= b 然后,如果是,求解两个圆的交点。基本顶点是
{0,0}, {a,0}, {x,y}
在哪里
x = (a^2-b^2+c^2)/(2a)
y = sqrt(c^2-x^2)
从这一点来看,找到外心非常容易。
【讨论】:
x 和y 的公式?
绘制未知三角形时,通常最容易选择一侧(例如最长的一侧)并将其水平或垂直放置。该边的端点构成了三角形的两个顶点,您可以通过将三角形细分为两个直角三角形(另外两个边是斜边)并使用反正弦/余弦函数计算出缺失的角度来计算第三个顶点.通过细分为直角三角形,我的意思是看起来像这里的图像:http://en.wikipedia.org/wiki/File:Triangle.TrigArea.svg 您的第一面将是该图中的 AC。
一旦确定了三角形,就应该很容易计算它的中心并对其进行平移,以便它以您喜欢的任意中心点为中心。
【讨论】: