5
$\begingroup$

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?

$\endgroup$

2 Answers 2

4
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ How can I Pich non right triangles? $\endgroup$ Apr 21 at 6:30
  • 2
    $\begingroup$ Thanks for the accept. I have updated the answer. $\endgroup$
    – Syed
    Apr 21 at 6:33
5
$\begingroup$

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:

enter image description here

$\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.