How to calculate coordinates of third point in a triangle (2D) knowing 2 points coordinates, all lenghts and all angles

26,146

Solution 1

  1. You know p1 and p2. You know the internal angles.
  2. Make a ray from p1 trough p2, and rotate it CW or CCW 30° around p1.
  3. Make a line trough p1 and p2, and rotate it 90° around p2.
  4. Calculate the intersections.

You get the points:

x3 = x2 + s*(y1 - y2)
y3 = y2 + s*(x2 - x1)

and

x3 = x2 + s*(y2 - y1)
y3 = y2 + s*(x1 - x2)

where s = 1/sqrt(3) ≈ 0.577350269

Solution 2

Here is the code to return points of full polygon if two points and number of sides are provided as input. This is written for Android(Java) and the logic can be re-used for other languages

private static final float angleBetweenPoints(PointF a, PointF b) {
    float deltaY = b.y - a.y;
    float deltaX = b.x - a.x;
    return (float) (Math.atan2(deltaY, deltaX));

}
private static PointF pullPointReferenceToLineWithAngle(PointF a, PointF b,
        float angle) {

    float angleBetween = angleBetweenPoints(b, a);
    float distance = (float) Math.hypot(b.x - a.x, b.y - a.y);
    float x = (float) (b.x + (distance * Math.cos((angleBetween + angle))));
    float y = (float) (b.y + (distance * Math.sin((angleBetween + angle))));
    return new PointF(x, y);
}

private static List<PointF> pullPolygonPointsFromBasePoints(PointF a,
        PointF b, int noOfSides) {
    List<PointF> points = new ArrayList<>();
    points.add(a);
    points.add(b);
    if (noOfSides < 3) {
        return points;
    }
    float angleBetweenTwoSides = (float) ((((noOfSides - 2) * 180) / noOfSides)
            * Math.PI / 180);
    for (int i = 3; i <= noOfSides; i++) {
        PointF nextPoint = pullPointReferenceToLineWithAngle(
                points.get(i - 3), points.get(i - 2), angleBetweenTwoSides);
        points.add(nextPoint);
    }
    return points;
}

Usage is onDraw method:

PointF a = new PointF(100, 600);
    PointF b = new PointF(300, 500);
    int noOfSides = 3;

    List<PointF> polygonPoints = pullPolygonPointsFromBasePoints(a, b,
            noOfSides);

    drawPolyPoints(canvas, noOfSides, polygonPoints);

Solution 3

In a 30-60-90 right triangle, smallest leg (the smallest side adjacent the 90 degree angle) has length of 1/2 of the hypotenuse (the side opposite to 90 degree angle), so since you have the side lengths, you can determine which leg is the line segment AB.

From that you deduce where do the angles go.

Then to compute the coordinate you just need to pick the point on the circle of the radius with the correct radius length at the correct angle.

Two solutions come from measuring the angle clock-wise or counter-clockwise, and result in symmetrical triangles, with the edge AB being the line of symmetry.

Since you already have given the angles, compute the length of AB via quadratic formula

L(AB) = Sqrt[(x1-x2)^2 + (y1-y2)^2].

Now, let x = L(AC) = 2*L(BC) so since it is the right triangle,

L(AC)^2 = L(BC)^2 + L(AB)^2,

x^2 = (0.5x)^2 + L(AB)^2, so L(AB) = x*Sqrt[3]/2, and since you already computed L(AB) you now have x.

The angle of the original AB is a = arctan([y2-y1]/[x2-x1]). Now you can measure 30 degrees up or down (use a+30 or a-30 as desired) and mark the point C on the circle (centered at A) of radius x (which we computed above) at the angle a +/- 30.

Then, C has coordinates

x3 = x1 + x*cos(a+30)

y3 = y1 + x*sin(a+30)

or you can use (a-30) to get the symmetrical triangle.

Share:
26,146
Daniel Dudas
Author by

Daniel Dudas

Updated on July 16, 2022

Comments

  • Daniel Dudas
    Daniel Dudas almost 2 years

    I have a triangle and I know the coordinates of two vertices: A=(x1,y1),B=(x2,y2) All the angles: ABC=90∘,CAB=30∘ and BCA=60∘ and all the edge lengths. How can I find the coordinates of the third vertex C=(x3,y3)?

    I know there are two solutions (I want both).

    • jrturton
      jrturton almost 12 years
      You know there are two solutions, but you dont know what they are?
    • QuantumMechanic
      QuantumMechanic almost 12 years
      Just draw a diagram. It's obvious there are two solutions. C can be either above or below the line between A and B.
    • barbiepylon
      barbiepylon almost 12 years
      Law of Sines should work. en.wikipedia.org/wiki/Law_of_sines
    • Daniel Dudas
      Daniel Dudas almost 12 years
      @user1454749 and how to get the coordonates as (x3,y3) using Law of Sines?
    • Phillip Schmidt
      Phillip Schmidt almost 12 years
      @user1454749 law of sines is useless here. she/he already knows all angles and side lengths
    • barbiepylon
      barbiepylon almost 12 years
      right...read the question wrong :)
    • QuantumMechanic
      QuantumMechanic almost 12 years
      Do you want a general solution (for any BAC and ABC?) or one specifically for a right triangle?
    • Pang
      Pang about 7 years
      I'm voting to close this question as off-topic because it is about Mathematics instead of programming or software development.
  • Daniel Dudas
    Daniel Dudas almost 12 years
    I know where the point is if I have to draw, but I want to know a formula for x3=... and y3 =... to determinate the exact coordinates of points. I need this in a program (code) not only for 1 problem
  • gt6989b
    gt6989b almost 12 years
    I misread the question, sorry. Have made the necessary edits.
  • gt6989b
    gt6989b almost 12 years
    just made some edits fixing typos and formatting.