Created
April 6, 2016 10:51
-
-
Save JulienSansot/d394d210c772a48be067d7e3b856dd1e to your computer and use it in GitHub Desktop.
Determine third point of triangle when two points and all sides are known
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//a,b,c are the sides of the triangle | |
function get_third_point_coordinates(a, b, c){ | |
var result = {x:0,y:0}; | |
if(a > 0){ | |
result.x = (c*c - b*b + a*a) / (2*a); | |
} | |
result.y = Math.sqrt(c*c - result.x*result.x); | |
return result; | |
} | |
var coordinates = get_third_point_coordinates(21, 17, 10); | |
document.write(JSON.stringify(coordinates)) |
Point 1 is {x:0, y:0}.
Point 2 is {x:0.001, y:a}.
The distance between point 1 and point 2 is a.
The distance between point 2 and point 3 is b.
The distance between point 1 and point 3 is c.
get_third_point_coordinates(a,b,c) gives the coordinates of Point 3.
so basically, this is for right triangles only?
No, it's for any triangle
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and what are the other two points?