9
0
Try to write the shortest program or function you can that prints or returns the calculated orthocenter of a triangle.
The orthocenter of a triangle is the intersection point of the three altitudes of a triangle. The altitude of a triangle is a perpendicular segment from the vertex of the triangle to the opposite side.
Input:
- Three points in 2D space correponding to the triangle's vertices
Output:
- The calculated orthocenter of the triangle
A sample input would be
A(0,0)
B(3,6)
C(6,0)
and a sample output would be:
Calculated Othocenter (3, 1.5)
One formula for orthocenter can be written as
(x, y) = ((ax*tan(α) + bx*tan(β) + cx*tan(γ))/(tan(α) + tan(β) + tan(γ),
(ay*tan(α) + by*tan(β) + cy*tan(γ))/(tan(α) + tan(β) + tan(γ))
Shortest program in bytes wins.
I added a description, and yes, the use of global's as a function was a slip up on my part, I copy and pasted from the wrong notepad file I had open without realizing it. The use of arrays is purely optional, it is just a habit of mine to do so, vs a naming convention like Ax, Ay, Bx... – Roberto Duran – 2015-06-27T05:33:36.630
Welcome to PPCG. Language specific challenges are frowned on here, because they limit participation and are frequently homework questions in disguise. I will cast a reopen vote if the language restriction is removed (and I say this despite the fact that most of my answers are in C.) – Level River St – 2015-06-27T09:33:45.910
3I cleaned this whole thing up for you, but you need to specify how the points are to be supplied to the function or program and what exactly the points are (angles, coordinates?) – Beta Decay – 2015-06-27T10:00:33.350
@BetaDecay it was fairly clear to me that the given points and required orthocentre are x.y coordinates. See 3rd comment from the top. – Level River St – 2015-06-27T10:04:06.417
4This question would benefit greatly from a good set of test cases; and, as with all questions involving floating point numbers, the spec isn't complete without a carefully thought out constraint on numerical accuracy. – Peter Taylor – 2015-06-27T11:09:36.570
For a triangle or any shape? My attempt but it's really ugly and I don't know if I should really post it as an answer
– Downgoat – 2015-06-27T13:19:26.950Since your input is defined as "several points", what's the definition of the orthocenter for more than 3 points? What if there are less than 3 points in the input? – Reto Koradi – 2015-06-27T16:05:26.083
3 points is a mandatory input, cases in which there is a missing point are out of the scope of this challenge, or course, one could write a program to find that missing side. – Roberto Duran – 2015-06-27T20:19:41.767
Is web scraping allowed? – rp.beltran – 2015-06-30T18:03:00.047
As in using an online resource to do it for you?(Example -curl and an online calculator?)No – Roberto Duran – 2015-06-30T20:36:37.510