Circles and squares have a single, definite center point. However, the notion of the center of a triangle has long been discussed. Four different centers were known to the Ancient Greeks:
- Incenter: The intersection of the angle bisectors of the triangle
- Centroid: The intersection of the lines from each vertex of the triangle to the middle of its opposite side
- Circumcenter: The intersection of the perpendicular bisectors of the sides
- Orthocenter: The intersection of the altitudes of the triangle
Euler later proved that the centroid, circumcenter and orthocenter are collinear in any triangle. The line that these three points are on in a triangle is called the Euler Line. It is defined for every triangle except an equilateral triangle, where all the points coincide.
Your challenge is to create the shortest program or function that, when given two inputs, outputs a specific center or the Euler Line of the triangle. The first specifies the coordinates of each vertex of a triangle. The second is an integer from 1 to 5, determining what to output.
1 - Incenter
2 - Centroid
3 - Circumcenter
4 - Orthocenter
5 - Equation of Euler Line
(if the Euler Line is vertical, output the `x` value of the line
(e.g. output `5` if the equation of the line is `x = 5`))
You may assume that the given vertices will never be collinear, and that they will always be integer coordinates (this also excludes the possibility of having an equilateral triangle as an input, as per @R.Kap's comment).
The input array should be a valid nested array in your language, and input should be in any reasonable format. Any float values should be displayed to at least 3 decimal places, but no less. An outputted point should be a valid array in your language, matching with the input format.
Test cases:
Input: [(-2, 0), (1, 0), (0, 1)] 1
Output: (-0.089, 0.451)
Input: [(-2, 0), (1, 0), (0, 1)] 2
Output: (-0.333, 0.333)
Input: [(-2, 0), (1, 0), (0, 1)] 3
Output: (-0.5, -0.5)
Input: [(-2, 0), (1, 0), (0, 1)] 4
Output: (0, 2)
Input: [(-2, 0), (1, 0), (0, 1)] 5
Output: 5x + 2
Clarification: The input can either be from stdin, either space or new-line separated, or as the arguments to a function. The output, however, must be written to stdout.
y=f(x)
. \$\endgroup\$(if the triangle is equilateral, output the point at which the centers meet)
as it is not possible to create an equilateral triangle on the coordinate plane using only integer coordinates. \$\endgroup\$