Math 在给定三角形三条边的坐标平面上绘制三角形

Math 在给定三角形三条边的坐标平面上绘制三角形,math,html,graph,canvas,drawing,Math,Html,Graph,Canvas,Drawing,三角形三条边的长度,a,b和c将被给出,我需要找到顶点的坐标。中心(可能是外圆心)可以是原点或(x,y) 谁能给我指出正确的方向吗 将第一个顶点放置在原点(0,0)处。将第二个顶点放置在(a,0)处。要计算第三个顶点,请找到两个圆心(0,0)和(a,0)以及半径b和c的圆的顶点 更新:Lajos Arpad给出了计算中第三点位置的详细信息。它可以归结为(x,y),其中x=(b2+a2-c2)/2a和y=±sqrt(b2-x2)当绘制未知三角形时,通常最容易选择一侧(比如最长的一侧)并将其水平或垂

三角形三条边的长度,a,b和c将被给出,我需要找到顶点的坐标。中心(可能是外圆心)可以是原点或(x,y)


谁能给我指出正确的方向吗

将第一个顶点放置在原点(0,0)处。将第二个顶点放置在(a,0)处。要计算第三个顶点,请找到两个圆心(0,0)和(a,0)以及半径b和c的圆的顶点


更新:Lajos Arpad给出了计算中第三点位置的详细信息。它可以归结为(x,y),其中x=(b2+a2-c2)/2a和y=±sqrt(b2-x2)

当绘制未知三角形时,通常最容易选择一侧(比如最长的一侧)并将其水平或垂直放置。该边的端点构成三角形的两个顶点,您可以通过将三角形细分为两个直角三角形(另两条边为斜边)并使用正弦/余弦反函数计算缺少的角度来计算第三个顶点。通过细分成直角三角形,我的意思是看起来像这里的图像:你的第一面在那幅画中是AC


一旦你算出三角形,就可以很容易地计算出它的中心并进行平移,使它以你喜欢的任意中心点为中心。

首先检查三角形是否可行: a+b >= c b+c >= a c+a >= b a+b>=c b+c>=a c+a>=b 然后,如果是,求解两个圆的交点。基本顶点是 {0,0}, {a,0}, {x,y} {0,0},{a,0},{x,y} 哪里 x=(a^2-b^2+c^2)/(2a) y=sqrt(c^2-x^2)
从这一点来说,找到圆周中心是非常容易的。

我已经阅读了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))

这个问题和答案今天帮助我实现了这个目标。它将计算给定2个已知点(a,b)的圆交点的未知顶点“c”,以及到第三个未知顶点“c”的距离(ac_长度,bc_长度)。 下面是我为所有感兴趣的人设计的python实现

我还提到以下内容:

将django的geos模块用于
Point()
对象,该对象可以替换为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 
从数学导入sqrt
从django.contrib.gis.geos导入点
类CirclesSeparate(BaseException):
通过
类CircleContained(BaseException):
通过
def发现位置(点a、点b、ac长度、bc长度):
"""
找到给定的点c:
a点
b点
ac_长度
bc_长度
点d==与c成直角的点。
"""
ab_长度=点a距离(点b)
如果ab_长度>(ac_长度+bc_长度):
升起圆圈分离(“给定点不相交!”)
elif ab_长度获取x
c_x1=点x+h*(点y-点y)/ab长度
c_x2=点x-h*(点y-点y)/ab\u长度
#-->
c_y1=点y-h*(点x-a.x)/ab_长度
c_y2=点y+h*(点x-点x)/ab长度
点c1=点(c_x1,c_y1)
点_c2=点(c_x2,c_y2)
返回点c1,返回点c2

非常好的解决方案,我会投票给你,但我发现这个答案不完整,因为你没有写下细节。我拿了一张纸和一支笔,计算了一下你说的话,想和任何对这一主题感兴趣的人分享结果。@Lajos,我不确定需要证明什么。施工结果为长度为a、b、c的侧面。。。我会说这是显而易见的,为什么你会说这不是显而易见的?因为有人问了这个问题。我不知道这个解决方案,我必须检查一下。我是一个不可知论者,只相信我所看到的。你的帖子完全正确,我只是想进一步说明。而且,这个解决方案是一个解决方案,因为你可以使用旋转和平移技术将三角形放在你想要的任何地方。@Lajos,我不是说这个构造很明显,我是说一旦你有了它,三条边的长度就很明显了。不管怎么说,你把第三个顶点的细节说清楚是很有帮助的,我已经把它联系了起来。“我的意思是,一旦你有了它,三条边的长度是显而易见的。”对不起,一开始我误解了。你说得对。你从哪里得到了
x
y
的公式?公式不正确(试一下a,b,c=4,
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