Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JulienSansot/d394d210c772a48be067d7e3b856dd1e to your computer and use it in GitHub Desktop.
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
//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))
@vanowm
Copy link

vanowm commented May 27, 2023

and what are the other two points?

@JulienSansot
Copy link
Author

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.

@vanowm
Copy link

vanowm commented May 27, 2023

so basically, this is for right triangles only?

@JulienSansot
Copy link
Author

No, it's for any triangle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment