0
$\begingroup$

I'm struggling to understand rotation/translation transforms as applied to things like spheres and ellipsoids. Take the following silly example.

Given this pair of random ellipsoids, how do I find a rotation/translation that aligns their centers and their long axes? (no matter that they differ in sizes, only care about their centers and long axes being aligned). Are the two possible geometric transformations equivalent? (Say, moving ellipsoid 1 to be aligned to the fixed ellipsoid 2, and vice versa?)

SeedRandom[1234];
twoRandomEllipsoids = 
  Table[{Ellipsoid[RandomReal[10, {3}], RandomReal[{1, 2}, 3]]}, {2}];
Graphics3D[{Opacity[0.2], twoRandomEllipsoids}, Axes -> True, 
 AxesLabel -> {x, y, z}]

enter image description here

Thanks!

$\endgroup$

2 Answers 2

1
$\begingroup$

We first create 2 ellipsoids with random center and random orientation.

center = {{x1, y1, z1}, {x2, y2, z2}} = 
   RandomInteger[{-10, 10}, {2, 3}];
axlen = RandomInteger[{1, 6}, {3, 2}] // Transpose
tr1 = AffineTransform[{rm1 = 
     RotationMatrix[RandomReal[{-1, 1}, {2, 3}]], center[[1]]}];
tr2 = AffineTransform[{rm2 = 
     RotationMatrix[RandomReal[{-1, 1}, {2, 3}]], center[[2]]}];


ax1 = (IdentityMatrix[3] axlen[[1]]) . Transpose@rm1;
ax2 = (IdentityMatrix[3] axlen[[2]]) . Transpose@rm2 ;


e1 = tr1[Ellipsoid[{0, 0, 0}, axlen[[1]]]];
e2 = tr2[Ellipsoid[{0, 0, 0}, axlen[[2]]]];
Graphics3D[{Opacity[0.5], e1, e2, 
  Line[{e1[[1]], e1[[1]] + #} & /@ ax1], 
  Line[{e2[[1]], e2[[1]] + #} & /@ ax2]}]

![enter image description here

Where center is a list of the 2 centers and ax1 and ax2 are lists of the half axes of the 2 ellipsoids.

If we normalize the axes, we get orthogonal rotation matrices that transforms the coordinate aligned axes to the actual orientations.

rot1 = Normalize /@ ax1;
rot2 = Normalize /@ ax2;

E.g. the coordinate aligned axes (axlen[[1]] IdentityMatrix[3]) would be rotated into ax1 by:

(axlen[[1]] IdentityMatrix[3]) . rot1 == ax1
(*True*)

Note that we multiply by the rotation matrix rot1 from the right, because we are working with row vectors.

On the other hand, the inverse of rot1, what is the same as the transposed, will transform ax1 back to the coordinated aligned half axes.

Therefore, to rotate half axes ax2 to the orientation of ax1 we can first rotate back to coordinates alignment by Transpose[r2] and in a second rotation to alignment with ax1 by: r1:

rot12=  Transpose[rot2] . rot1;
ax3= ax2 . rot12

With this we can now define the affine translation that maps ellipsoid e2 on the center and direction of ellipsoid e1:

tr3 = AffineTransform[{rot12, 
    center[[1]] - center[[2]] . Transpose[rot12]}];

Note that the center of e2 is rotated by r12 and we need to undo this rotation by Transpose[r12].

Now we can apply the transformation and draw the result:

e3 = tr3[e2];
Graphics3D[{Opacity[0.5], e1, e3, 
  Line[{e1[[1]], e1[[1]] + #} & /@ ax1], 
  Line[{e3[[1]], e3[[1]] + #} & /@ ax3]}]

![enter image description here

$\endgroup$
5
  • $\begingroup$ Thanks! This looks very cool. In the last image, however, aren't the major axes perpendicular to each other? I was meaning 'aligned' as both major axes would have the same 'direction', if that makes sense. Thanks! $\endgroup$ Commented Aug 18, 2021 at 14:47
  • 1
    $\begingroup$ Of course you are right. The major axes should be aligned. I had an error in the code and fixed it. Hope I got it right this time. $\endgroup$ Commented Aug 18, 2021 at 20:57
  • $\begingroup$ Hmmm. I see the major axes perpendicular (crossing each other at the center, in a right angle). Maybe my idea of 'aligned' is not clear? If the angle between the major angles disappeared in your final image, that'd be my idea of 'aligned'. Let me know if something is unclear. $\endgroup$ Commented Aug 19, 2021 at 0:05
  • 1
    $\begingroup$ As you can see from the code, the axes of both ellipses are drawn and they coincide. Therefore you can see only one pair of axes. I think this means "alignment". $\endgroup$ Commented Aug 19, 2021 at 15:47
  • $\begingroup$ You're right, that makes sense, thanks! $\endgroup$ Commented Aug 19, 2021 at 18:14
0
$\begingroup$

I'll just show the translation.

SeedRandom[1234];
theparameters = Table[{RandomReal[10, {3}], RandomReal[{1, 2}, 3]}, {2}];

shifted = 
 GeometricTransformation[twoRandomEllipsoids[[1]], 
  TranslationTransform[-theparameters[[1, 1]] + theparameters[[2, 1]]]];

Graphics3D[{Opacity[0.5], Red, shifted, Green, twoRandomEllipsoids[[2]]}]

enter image description here

The major axis is trivial since by your construction the major axis of each ellipsoid is aligned to a coordinate axis. Just find which terms are largest in each of your ellipsoids. If one is along x and the other along z, then simply rotate one by $\pi/2$ about the third axis ($y$) so as to align its $z$ axis with the other's $x$ axis.

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