24
2
From http://en.wikipedia.org/wiki/Triangle:
Write a program that takes three 2d coordinate tuples (Cartesian), and classifies what shape these three points describe.
In almost all cases these points will describe a triangle of varying types. In some degenerate cases, the points will either describe a singular point or a straight line. The program will determine which of the following tags apply to the described shape:
- Point (3 points are co-incident)
- Line (3 points lie on a straight line - no more than 2 points may be co-incident)
- Equilateral (3 sides equal, 3 angles equal)
- Isosceles (2 sides equal, 2 angles equal)
- Scalene (0 sides equal, 0 angles equal)
- Right (1 angle exactly π/2 (or 90°))
- Oblique (0 angles exactly π/2 (or 90°))
- Obtuse (1 angle > π/2 (or 90°))
- Acute (3 angles < π/2 (or 90°))
Note that for some described shapes, more than one of the above tags will apply. For example, any right-angled will also either be isosceles or scalene.
Input
- The program may read the 3 input coordinates from STDIN, command-line, environment variables or whatever method is convenient for your language of choice.
- The input co-ordinates my be formatted however is convenient for your language of choice. It can be assumed that all input numbers are well-formed with respect to the datatypes you end up using.
- Nothing can be assumed about the ordering of the input coordinates.
Output
- The program will output to STDOUT, dialog box or whatever display method is convenient for your language of choice.
- The output will display all the tags applicable to the shape described by the input coordinates.
- Tags may be output in any order.
Other Rules
- Your language's trigonometric libraries/APIs are allowed, but any APIs that specifically calculate triangle types are banned.
- When determining equality of angles or lengths of sides, you will likely end up comparing floating-point values. Two such values are to be considered "equal" if one is within 1% of the other.
- Standard “loopholes” which are no longer funny
- This is code-golf, so the shortest answer in bytes wins.
Examples
Input Output
(1,2) (1,2) (1,2) Point
(1,2) (3,4) (5,6) Line
(0,0) (1,1) (2,0) Isosceles Right
(0,0) (2,1) (10,1) Scalene Oblique Obtuse
4I was going to entitle this "Triangle Tag" but it fell short of the 15-character minimum. – Digital Trauma – 2014-07-24T23:36:06.547
What if two points are identical? – Ypnypn – 2014-07-24T23:51:10.543
@Ypnypn In that case it is a line. – Digital Trauma – 2014-07-24T23:52:50.100
Triangle Tag – Derek 朕會功夫 – 2014-07-24T23:57:24.227
(Minimum character counts is for loser :v) – Derek 朕會功夫 – 2014-07-24T23:58:26.643
2There is a problem with "Acute" definition ? it's impossible that all angles are greater than PI/2 ? – Arnaud – 2014-07-25T01:29:48.043
@SuperChafouin Oops - good catch! I've fixed it now. – Digital Trauma – 2014-07-25T01:31:43.507
Does it matter how we treat invalid inputs? (i.e. a word, 2 or 4 coordinates, etc.) – NinjaBearMonkey – 2014-07-25T19:43:26.600
@hsl No you don't need to worry about invalid inputs. I think the 2nd part of the input rules explains this. – Digital Trauma – 2014-07-25T19:59:29.070
For any equilateral triangle, should it also output "isosceles"? It technically satisfies the conditions – Kyle McCormick – 2014-07-27T20:30:50.783
@KyleMcCormick I'd prefer that equilateral and isosceles are mutually exclusive. But since the original spec was a bit ambiguous in this respect, I will accept it either way. – Digital Trauma – 2014-07-28T17:13:13.063