4
$\begingroup$

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
$\endgroup$
4
  • $\begingroup$ Hack: Equal @@ (tris /. Triangle[x__] :> Triangle[Sort[x]]) $\endgroup$
    – Syed
    Aug 3, 2023 at 12:20
  • $\begingroup$ @Syed Check my update, thanks. $\endgroup$
    – yode
    Aug 3, 2023 at 12:30
  • $\begingroup$ Please see the screenshot. I am on v12.2.0 on Win7-x64. $\endgroup$
    – Syed
    Aug 3, 2023 at 12:41
  • $\begingroup$ "They are in every sense the same triangle" isn't true! The orientation (normal vector) is different I think. $\endgroup$ Aug 4, 2023 at 7:35

3 Answers 3

10
$\begingroup$

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 *)
$\endgroup$
2
  • $\begingroup$ Thanks, check my update. Maybe the RegionEqual have a bug. $\endgroup$
    – yode
    Aug 3, 2023 at 12:30
  • 5
    $\begingroup$ @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. $\endgroup$ Aug 3, 2023 at 12:42
4
$\begingroup$

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
$\endgroup$
1
$\begingroup$

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

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