I’m working with STL based geometries, which work very well.
I have some geometries which are not centered.
I would like to rotate this object along it’s own arbitrary axis.
For objects already defined in the mother’s center, I do this via:
// Define Some arb axis
G4ThreeVector AxisOfRotation = G4ThreeVector(0.5,0.1,0.5).unit();
// Define RotationMatrix
G4RotationMatrix * RotMat = new G4RotationMatrix();
// rotate object 90deg w.r.t this axis
RotMat -> rotate(90.0 *deg, AxisOfRotation);
RotMat -> invert();`
new G4PVPlacement(G4Transform3D(*RotMat, TranslationVector), ...... );
However, now that my object is off-centered to begin with, I would need to translate the object to the center, THEN, rotate and translate back.
Is there a way to make this work? Or perhaps a better method?
I suggest using G4Transform3D, which is a typedef for CLHE::Tranforms3D.
CLHEP provides a consistent set of vectors, points, transforms, etc.
Thank you but I already use Transform3D to rotate in object’s frame of reference (see my snippet above), but the model is not in the object’s world center. So I still need to be able to translate first. Then apply the Transform3d.
So use G4Translate3D.
G4Transform3D t = G4Rotate3D(…axis…)*G4Translate3d(dx,dy,dz);
and if p is a G4Point3D (maybe even works for G4ThreeVector - not sure):
This is from memory so details may not be correct.
Ah, I wasn’t aware I could combine transforms with G4Transform3D like this. I’ll give this a try and update. Thanks a lot.
Update: Allison’s advice was spot on.
Instead of relying on the G4Transform3D construct i.e. [(*RotMat, Translation)], I made my own composite transformation as shown below:
Translation #1, followed by rotation followed by another translation #2:
G4Transform3D t = G4Translate3D(shift_2) * G4Rotate3D(angle,axis) * G4Translate3D(shift_1)
new G4PVPlacement( t , ...... );