Hi,
I’m looking for a way to determine the 3x3 rotation matrix R needed to rotate a known TVector3 v1 to another known TVector3 v2, i.e. v2 = R*v1.
Is there some existing routine in ROOT?
Best regards and thanks,
Klaus
ROOT Version: 6.28/04
Hi,
I’m looking for a way to determine the 3x3 rotation matrix R needed to rotate a known TVector3 v1 to another known TVector3 v2, i.e. v2 = R*v1.
Is there some existing routine in ROOT?
Best regards and thanks,
Klaus
ROOT Version: 6.28/04
Hi @canigia,
thank you for reaching out! TVector3 is a legacy class, I recommend switching to DisplacementVector3D and the GenVector package.
In order to determine the rotation matrix R
such that v2 = R*v1
, you have to compute first the rotation axis v
and the angle a
. Given DisplacementVector3D v1
and v2
, the rotation axis is the cross product, and you can retrieve the angle computing its cosine fist, see the code snippet below.
auto v = v1.Cross(v2);
auto cosa = v1.Dot(v2) * 1./std::sqrt(v1.mag2()*v2.mag2());
auto a = std::acos( cosa );
AxisAngle arot(v,a);
Rotation3D rot(arot);
auto vrot = rot(v1);
Cheers,
Monica
Thanks for the quick answer!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.