# Is there a better method and more efficient way to determine the type of triangle based on the coordinates of its three vertices?

list={{{-2, -7}, {3, 18}, {8, 17}}, {{-2, -7}, {8, 17}, {15,
0}}, {{-2, -7}, {8, 17}, {15, 10}}, {{-2, -7}, {8, 17}, {16,
5}}, {{-2, 17}, {3, -8}, {8, -7}}, {{-2, 17}, {3,
18}, {8, -7}}, {{-2, 17}, {8, -7}, {15, 0}}, {{-2,
17}, {8, -7}, {15, 10}}, {{-2, 17}, {8, -7}, {16, 5}}}


Given the coordinates of the three vertices of a triangle, how can one identify whether the triangle is an acute triangle, a right triangle, or an obtuse triangle based on these coordinates?

triangles = {{{-2, -7}, {3, 18}, {8, 17}}, {{-2, -7}, {8, 17}, {15, 0}}, {{-2, -7}, {8, 17}, {15, 10}}, {{-2, -7}, {8, 17}, {16, 5}}, {{-2, 17}, {3, -8}, {8, -7}}, {{-2, 17}, {3, 18}, {8, -7}}, {{-2, 17}, {8, -7}, {15, 0}}, {{-2, 17}, {8, -7}, {15, 10}}, {{-2, 17}, {8, -7}, {16, 5}}};

triangleType[triangle_] := Module[
{a, b, c, sides},
sides = Map[EuclideanDistance @@ # &, Partition[Flatten[triangle], 2]];
{a, b, c} = Sort[sides];
If[a^2 + b^2 == c^2, "Right triangle", If[a^2 + b^2 > c^2, "Acute triangle", "Obtuse triangle"]]]

triangleTypes = triangleType /@ triangles


Update:

according to Daniel Huber

triangles = Polygon[{{{0, 0}, {8, 0}, {16, 75}}}]
PolygonAngle[triangles] // FullSimplify
Graphics[{FaceForm[], EdgeForm[Black], triangles}]


• – Syed
Commented Apr 21 at 2:08
• What have you tried? Commented Apr 21 at 2:20
• Then what's the question now? Commented Apr 21 at 2:41
• Then what do you mean by "better"? Commented Apr 21 at 2:46
• Then what do you mean by "to the point"? Commented Apr 21 at 2:52

Try

Map[Sign[Cross[#[[2]] - #[[1]]] . (#[[3]] - #[[1]])] &, triangles]
(*{-1, -1, -1, -1, 1, -1, 1, 1, 1}*)


Positive sign gives counterclockwise orientation, negative sign clockwise orientation!

Or

Map[PositivelyOrientedPoints, triangles]
(*{False, False, False, False, True, False, True, True, True}*)

• The code does what you say -- no problem there. But the question is not a binary or true/false question about orientation. It's about the maximum angle and has three possible answers. The upvotes are inexplicable. Commented Apr 21 at 12:33
triangleType[tri : {Repeated[{_, _}, {3}]}] :=
With[
{maxangle = Max[PolygonAngle[Triangle[tri]]]},
Which[
maxangle < Pi/2, "acute",
maxangle > Pi/2, "obtuse",
True, "right"]];

triangleType /@ triangles
(* {"right", "right", "right", "right", "right", "right", "right", "right", "right"} *)


The argument pattern is more to communicate the expected form of the input rather than to actually protect against bad input.