0
$\begingroup$
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}]

enter image description here

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

2 Answers 2

2
$\begingroup$

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}*)
$\endgroup$
1
  • 2
    $\begingroup$ 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. $\endgroup$
    – Goofy
    Commented Apr 21 at 12:33
2
$\begingroup$
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.