Drawing a triangle in a coordinate plane given its

2019-03-30 08:15发布

The length of three sides of the triangle, a, b and c will be given, and I need to find the coordinates of the vertices. The center (probably the circumcenter) can either be the origin or (x,y).

Can anyone point me in the right direction?

5条回答
孤傲高冷的网名
2楼-- · 2019-03-30 08:23

I've read brainjam's answer and checked whether his answer is true and he is right. Calculation: O(0;0), A(a;0) and B(x;y) are the three points of the triangle. C1 is the circle around A and r1 = c; C2 is the circle around O and r2 = b. B(X;Y) is the intersection of C1 and C2, which means that the point is on both of the circles.

alt text

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)))

查看更多
女痞
3楼-- · 2019-03-30 08:28

First check the that the triangle is possible:

    a+b >= c
    b+c >= a
    c+a >= b
Then, if it is, solve for the intersection of the two circles. The basic vertices are
    {0,0}, {a,0}, {x,y}
where
    x = (a^2-b^2+c^2)/(2a)
    y = sqrt(c^2-x^2)
Finding the circumcenter is pretty easy from this point.

查看更多
Anthone
4楼-- · 2019-03-30 08:30

When drawing an unknown triangle, it's usually easiest to pick one side (say, the longest) and place it horizontally or vertically. The endpoints of that side make up two of the triangle's vertices, and you can calculate the third by subdividing the triangle into two right triangles (the other two sides are the hypotenuses) and using the inverse sine/cosine functions to figure out the missing angles. By subdividing into right triangles, I mean something that looks like the image here: http://en.wikipedia.org/wiki/File:Triangle.TrigArea.svg Your first side would be AC in that drawing.

Once you have the triangle figured out, it should be easy to calculate it's center and translate it so that it is centered on whatever arbitrary center point you like.

查看更多
疯言疯语
5楼-- · 2019-03-30 08:34

enter image description here

This question and the answers helped me out today in implementing this. It will calculate the unknown vertices, "c" of circle intersections given 2 known points (a, b) and the distances (ac_length, bc_length) to the 3rd unknown vertex, "c". Here is my resulting python implementation for anyone interested.

I also referenced the following:

http://mathworld.wolfram.com/RadicalLine.html

http://mathworld.wolfram.com/Circle-CircleIntersection.html

Using django's geos module for the Point() object, which could be replaced with shapely, or point objects removed altogether really.

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 
查看更多
SAY GOODBYE
6楼-- · 2019-03-30 08:47

Place the first vertex at the origin (0,0). Place the second vertex at (a,0). To compute the third vertex, find the intersection of the two circles with centers (0,0) and (a,0) and radii b and c.

Update: Lajos Arpad has given the details of computing the location of the third point in this answer. It boils down to (x,y) where x = (b2+a2-c2)/2a and y=±sqrt(b2-x2)

查看更多
登录 后发表回答