# How to select right triangles and non right triangles given their coordinates

I have a list of triangle coordinates in 2D-space:

Clear["Global*"];
lst = {{{3, 18}, {15, 0}, {16, 5}}, {{3, 18}, {15, 10}, {16,
5}}, {{-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}}, {{8,
17}, {15, 0}, {16, 5}}, {{8, 17}, {15, 10}, {16, 5}}};


Some of these entries represent right-angled triangles and others that do not. With each triangle, I tried:

a = lst[[1]][[1]];
b = lst[[1]][[2]];
c = lst[[1]][[3]];
VectorAngle[a - b, a - c]
VectorAngle[b - a, b - c]
VectorAngle[c - a, c - b]


How can I separate the right-angled triangles from the rest?

To separate the two types of triangles:

GroupBy[lst, ContainsAny[{π/2}]@*PolygonAngle@*Triangle]


To get the right-angled triangles:

rtris = Select[lst, ContainsAny[{π/2}]@*PolygonAngle@*Triangle]


or

Pick[lst, ContainsAny[{π/2}]@*PolygonAngle@*Triangle /@ lst]


{{{-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}}}

To pick the non right-angled triangles:

nrtris = Select[lst, ContainsNone[{π/2}]@*PolygonAngle@*Triangle]


To visualize:

Graphics /@
MapThread[{EdgeForm[Thin], Opacity[0.2], #1, #2} &, {RandomColor[
Length@rtris], Triangle /@ rtris}]


• How can I Pich non right triangles? Commented Apr 21 at 6:30
• Thanks for the accept. I have updated the answer.
– Syed
Commented Apr 21 at 6:33

Using GroupBy

f[u_] := Sort[MapThread[#1 . #2 &, {u, u}]] . {1, 1, -1};
s[{a_, b_, c_}] := f@(Subtract @@@ Subsets[{a, b, c}, {2}]) == 0
g = GroupBy[lst, s, Triangle /@ # &];
dis[con_, col_] :=
Graphics[{Point /@ lst, EdgeForm[col], FaceForm[None], #},
PlotLabel -> con] & /@ (con /. g);
anim = dis[True, Black]~Join~dis[False, Red];
`

Exporting as animated gif: