Placing a rotated geometry at a specific point defined by its ends

I have a very basic Geant4 question, given I have a rectangular box (G4SubtractionBox with 1 mm walls) I want to rotate and then place at a specific point that is defined by the edge of box rather than the center. My box has the dimensions (165,14,6)*mm and is supposed to be rotated by an angle of -25. and placed so that it ends at (-25,8.8,0)*mm. For this purpose I do:

		G4ThreeVector zp = G4ThreeVector(0, 0, 1);
  		G4ThreeVector xp = G4ThreeVector(std::cos(phi),std::sin(phi),0);
  		G4ThreeVector yp = G4ThreeVector(-std::sin(phi), std::cos(phi),0);
  		G4RotationMatrix rotm1  = G4RotationMatrix(xp, yp, zp);

After which I try to come up with the offset to put the box at the right place. In this case,

G4ThreeVector offset=G4ThreeVector(std::cos(phi)*((-25-165/2)*mm),(8.8-sin(phi)*(165/2))*mm,0)

However this is not right as if I place a beam at the end of this hollowed out box by using 8.8-sin(phi)*(165))*mm, I see that my beam is off the desired point in y by >0.5mm. I am sure I am missing something very trivial here but I can’t seem to put my finger on it. Any help will be highly appreciated

To better control the transformation of objects, I suggest to use G4Transform3D. As far as I understand, the position of the beam is related to the box. In this case, it might be easier to specify it in the local coordinates of the box, and then transform it along with the box.

So, the code will look like the following:

G4Point3D local_beam_position(...);
G4Trasform3D tranformation = G4Translate3D(...)*G4RotateZ3D(phi); 
G4ThreeVector beam_position = transformation*local_beam_position;

To place the box in the World you apply G4PVPlacement with G4Transform3D.

1 Like

Thank you so MUCH! That solved the issue. I was not aware that you could do it this way. Had to do a bit more of arithmetic to get the correct offset for the center of the box instead of the end but it works!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.