Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Three-pointer! But what kind?

From http://en.wikipedia.org/wiki/Triangle: enter image description here


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 , 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

Answer*

Draft saved
Draft discarded
Cancel
2
  • \$\begingroup\$ I'm a mathematica rookie. Where can I download an interpreter/compiler, or try this online (for free, of course ;-))? \$\endgroup\$ Commented Jul 28, 2014 at 17:16
  • \$\begingroup\$ I've never used it, but Wolfram has a 'CDF Player' browser application which claims to run Mathematica files stored in the CDF format, but not regular notebooks. Found here: wolfram.com/cdf-player Beyond that, there's the main program, which I believe is free for 30 days. \$\endgroup\$ Commented Jul 28, 2014 at 19:58

AltStyle によって変換されたページ (->オリジナル) /