Triangle Formula for alternative Points

With this formula I tried to calculate the third point in a triangle:

https://math.stackexchange.com/a/1553606/126977

I know the length between the two point points and the angles at this corners:

enter image description here

Known points are:

 point1 = { x: 4925.707458496093, y: 281.38922119140636}
 point2 = { x: 5065.31622314453,  y: 423.47991943359386}

The known angles are:

angle1 = 137.76476741527148
angle2 = 40.725761857792335

I wrote a javascript programm to test it:

var oo = ( Math.atan2(point2.y - point1.y, point2.x - point1.x));
    oo = oo + toRadians(winkel1);

var d = (get_Distance(point1, point2)  * Math.sin(toRadians(angle1))    )  / Math.sin(toRadians(180) - toRadians(angle1) - toRadians(angle2));

Then I calculate the points with:

var x = (point1.x + d  * Math.cos(oo));
var y = (point1.y + d  * Math.sin(oo));

But somehow I don't get 0,0 as output I get: 5250.0599801529925, 5204.454252468392

Even after changing some variables, I cant figure out the correct result What do I wrong? Thanks

Here you can run the code:http://jsfiddle.net/hacjk7yr/


Although I do not know JavaScript (but do know multiple other languages), I see two errors in your code.

  1. In lines 12 and 13 in your linked code, you swapped Angle1 and Angle2. Strangely, you have it correct in your question above. You should have

    angle1 = 137.76476741527148

    angle2 = 40.725761857792335

angle1 must be the given angle at point p1, and angle2 for p2, where p1 is the "base point" and p2 is the other given point.

  1. In line 19 in your code, where you calculate d, the length of the side opposite point p2, the angle in the numerator should be angle2, but you have angle1.

There are other points to be careful of. Make sure the atan2 function in JavaScript takes the $y$-coordinate before the $x$-coordinate. I believe it does, but some languages have $x$ before $y$.


With those changes, and me emulating the code both in Geogebra and in my graphing calculator, the correct answer appears. Make those changes and see if the problem is resolved for you.


I should probably point out that there are two triangles that satisfy your conditions. The algorithm I gave you and the code you wrote find the one where the three vertices, in the order First-Second-Unknown are in counter-clockwise order as seen from above the Cartesian plane. To get the other triangle, in clockwise order, you can either (a) call the same code again, switching the two points, or (b) in the line where you add the angle at the base point (angle1 in your code) instead subtract that angle.

Also note that your code has no error-checking and has some other weak coding practices. It should still work if the data is good, however.