4

I have $6$ triangle:

tris = Triangle/@Permutations[{{0,0,0},{1,0,0},{0,1,1}}]

They are in every sense the same triangle. But how to check that these triangles are exactly the same triangle? And I note Equal @@ tris and SameQ @@ tris both cannot do this.


Furthermore, none of the current methods (comments and answers) seem to be able to tell if the following six triangles(tris2) are the same triangle:

Clear["`*"]
sol = Solve[{x1^2/16 + 9 y1^2 == 1, x2^2/16 + 9 y2^2 == 1, 
    x3^2/16 + 9 y3^2 == 
     1, (x1 - x2)^2 + (y1 - y2)^2 == (x1 - x3)^2 + (y1 - 
        y3)^2 == (x2 - x3)^2 + (y2 - y3)^2, (143 Sin[1/2])/1299 == 
     1/3 (y1 + y2 + y3), 572/147 Cos[1/2] == 1/3 (x1 + x2 + x3)}, {x1,
     y1, x2, y2, x3, y3}];
tris2 = Triangle[{{x1, y1}, {x2, y2}, {x3, y3}}] /. sol
yode
  • 26,686
  • 4
  • 62
  • 167

3 Answers3

10

Use RegionEqual.

RegionEqual @@ tris
(* True *)

If triangle coordinates are complicated symbolic expressions for which Mathematica cannot determine the equality, you can numericize them.

RegionEqual @@ N[tris2]
(* True *)
Domen
  • 23,608
  • 1
  • 27
  • 45
  • Thanks, check my update. Maybe the RegionEqual have a bug. – yode Aug 03 '23 at 12:30
  • 5
    @yode There's no bug, the expressions are just too complicated for Equal to check that they are actually equal. If you use N to get approximations you'll see RegionEqual works. – Najib Idrissi Aug 03 '23 at 12:42
4

We may define a helper function that calculates the length of the sides:

sides[tri_] := 
 Norm /@ {tri[[1, 1]] - tri[[1, 2]], tri[[1, 2]] - tri[[1, 3]], 
   tri[[1, 3]] - tri[[1, 1]]}

With this we may define a check function that checks for equality:

check[triangles_] := AllTrue[Sort /@ sides /@ N@triangles, Equal]

For a test:

check[tris]

True

And

check[tris2]

True

Daniel Huber
  • 51,463
  • 1
  • 23
  • 57
1

I have voted for other answers.

Just a visualization:

f[x_, y_] := x^2/16 + 9 y^2 - 1
cp = ContourPlot[f[x, y] == 0, {x, -5, 5}, {y, -1, 1}];

Using sol from OP:

tr = Triangle[{{x1, y1}, {x2, y2}, {x3, y3}}] /. sol // N;
rad = (Sqrt[(x1 - x2)^2 + (y1 - y2)^2] /. sol // N)[[1]];
circ = {Red, Circle[{x1, y1}, rad]} /. sol // N;

The three circle intersections define a unique triangle. The last constraints in the Solve provide the radius.

Show[cp, Graphics[{tr, circ}], AspectRatio -> Automatic]

enter image description here

ubpdqn
  • 60,617
  • 3
  • 59
  • 148