Logo

The Data Daily

The ‘Reorient’ transformation | R-bloggers

The ‘Reorient’ transformation | R-bloggers

The ‘Reorient’ transformation
Posted on September 14, 2022 by Stéphane Laurent in R bloggers | 0 Comments
[This article was first published on Saturn Elephant , and kindly contributed to R-bloggers ]. (You can report issue about the content on this page here )
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Share Tweet
If you follow my youtube channel then you have certainly seen the “ball” of twenty Hopf tori. Sometimes I call it the “Hopf flower”. How is it done?
Well, firstly, I take twenty points on a ball: the twenty vertices of the compound of five tetrahedra . Then, I construct one Hopf torus, and for each of the twenty points I reorient it towards this point and I translate it to this point. This post is about the transformation used to reorient.
POV-Ray
I discovered this transformation in the file transforms.inc of the POV-Ray distribution. You can find it here . Below is the POV-Ray macro which runs the transformation.
#macro Reorient_Trans(Axis1, Axis2) #local vX1 = vnormalize(Axis1); #local vX2 = vnormalize(Axis2); #local Y = vcross(vX1, vX2); #if(vlength(Y) > 0) #local vY = vnormalize(Y); #local vZ1 = vnormalize(vcross(vX1, vY)); #local vZ2 = vnormalize(vcross(vX2, vY)); transform { matrix < vX1.x, vY.x, vZ1.x, vX1.y, vY.y, vZ1.y, vX1.z, vY.z, vZ1.z, 0, 0, 0 > matrix < vX2.x, vX2.y, vX2.z, vY.x, vY.y, vY.z, vZ2.x, vZ2.y, vZ2.z, 0, 0, 0 > } #else #if (vlength(vX1-vX2)=0) transform {} #else #local vZ = VPerp_To_Vector(vX2); transform { Axis_Rotate_Trans(vZ,180) } #end #end #end
Axis1 is the vector to be rotated and Axis2 is the vector to be rotated towards. Usually, Axis1 is the \(x\), \(y\), or \(z\) direction, that depends on the software used.
Haskell
I also did the ball of twenty Hopf tori in Haskell, with the OpenGL library. The full code is available in this Github repository . Below are the relevant parts of the code.
import Data.Foldable (toList) import Linear translateAndReorient :: (Real a, Floating a) => V3 a -> V3 a -> [a] translateAndReorient axis vector = concatMap toList (toList (mkTransformationMat m vector)) where vx1 = axis ^/ (norm axis) vx2 = vector ^/ (norm vector) y' = cross vx1 vx2 y = y' ^/ norm y' z1' = cross vx1 y z1 = z1' ^/ norm z1' z2' = cross vx2 y z2 = z2' ^/ norm z2' m1 = transpose $ V3 vx1 y z1 m2 = V3 vx2 y z2 m = transpose $ m1 !*! m2
import Graphics.Rendering.OpenGL.GL ...... tmatrices :: [[GLfloat]] tmatrices = map (translateAndReorient (V3 0 0 1)) points ...... forM_ tmatrices $ \tmatrix -> preservingMatrix $ do m

Images Powered by Shutterstock