Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
AxisAngleXother.cxx
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Authors: W. Brown, M. Fischler, L. Moneta 2005
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2005 , LCG ROOT FNAL MathLib Team *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for multiplications of AxisAngle by a rotation
12//
13// Created by: Mark Fischler Tues July 5 2005
14//
15
17
18#include <cmath>
19
25
28
30
32
33namespace ROOT {
34
35namespace ROOT_MATH_ARCH {
36
38{
39 // combination with a Rotation3D
40 return operator*(Quaternion(r));
41}
42
44{
45 // combination with another AxisAngle
46 return operator*(Quaternion(a));
47}
48
50{
51 // combination with EulerAngles
52 return operator*(Quaternion(e));
53}
54
56{
57 // combination with RotationZYX
58 return operator*(Quaternion(r));
59}
60
62{
63 // combination with Quaternion
64 return AxisAngle(Quaternion(*this) * q);
65}
66
67#ifdef MOVE
68
70{
71 // combination with quaternion (not used)
72 const Scalar s1 = math_sin(fAngle / 2);
73 const Scalar au = math_cos(fAngle / 2);
74 const Scalar ai = s1 * fAxis.X();
75 const Scalar aj = s1 * fAxis.Y();
76 const Scalar ak = s1 * fAxis.Z();
77 Scalar aqu = au * q.U() - ai * q.I() - aj * q.J() - ak * q.K();
78 Scalar aqi = au * q.I() + ai * q.U() + aj * q.K() - ak * q.J();
79 Scalar aqj = au * q.J() - ai * q.K() + aj * q.U() + ak * q.I();
80 Scalar aqk = au * q.K() + ai * q.J() - aj * q.I() + ak * q.U();
81 Scalar r = math_sqrt(aqi * aqi + aqj * aqj + aqk * aqk);
82 if (r > 1)
83 r = 1;
84 if (aqu < 0) {
85 aqu = -aqu;
86 aqi = -aqi;
87 aqj = -aqj, aqk = -aqk;
88 }
89 const Scalar angle = 2 * math_asin(r);
91 if (r == 0) {
92 axis.SetCoordinates(0, 0, 1);
93 } else {
94 axis /= r;
95 }
96 return AxisAngle(axis, angle);
97}
98
99#endif
100
102{
103 // combination with RotationX
104
105 const Scalar s1 = math_sin(fAngle / 2);
106 const Scalar au = math_cos(fAngle / 2);
107 const Scalar ai = s1 * fAxis.X();
108 const Scalar aj = s1 * fAxis.Y();
109 const Scalar ak = s1 * fAxis.Z();
110 Scalar c = rx.CosAngle();
111 if (c > 1)
112 c = 1;
113 if (c < -1)
114 c = -1;
115 Scalar qu = math_sqrt(.5 * (1 + c));
116 Scalar qi = math_sqrt(.5 * (1 - c));
117 if (rx.SinAngle() < 0)
118 qi = -qi;
119 Scalar aqu = au * qu - ai * qi;
120 Scalar aqi = ai * qu + au * qi;
121 Scalar aqj = aj * qu + ak * qi;
122 Scalar aqk = ak * qu - aj * qi;
123 Scalar r = math_sqrt(aqi * aqi + aqj * aqj + aqk * aqk);
124 if (r > 1)
125 r = 1;
126 if (aqu < 0) {
127 aqu = -aqu;
128 aqi = -aqi;
129 aqj = -aqj, aqk = -aqk;
130 }
131 const Scalar angle = 2 * math_asin(r);
132 DisplacementVector3D<Cartesian3D<double>> axis(aqi, aqj, aqk);
133 if (r == 0) {
134 axis.SetCoordinates(0, 0, 1);
135 } else {
136 axis /= r;
137 }
138 return AxisAngle(axis, angle);
139}
140
142{
143 // combination with RotationY
144
145 const Scalar s1 = math_sin(fAngle / 2);
146 const Scalar au = math_cos(fAngle / 2);
147 const Scalar ai = s1 * fAxis.X();
148 const Scalar aj = s1 * fAxis.Y();
149 const Scalar ak = s1 * fAxis.Z();
150 Scalar c = ry.CosAngle();
151 if (c > 1)
152 c = 1;
153 if (c < -1)
154 c = -1;
155 Scalar qu = math_sqrt(.5 * (1 + c));
156 Scalar qj = math_sqrt(.5 * (1 - c));
157 if (ry.SinAngle() < 0)
158 qj = -qj;
159 Scalar aqu = au * qu - aj * qj;
160 Scalar aqi = ai * qu - ak * qj;
161 Scalar aqj = aj * qu + au * qj;
162 Scalar aqk = ak * qu + ai * qj;
163 Scalar r = math_sqrt(aqi * aqi + aqj * aqj + aqk * aqk);
164 if (r > 1)
165 r = 1;
166 if (aqu < 0) {
167 aqu = -aqu;
168 aqi = -aqi;
169 aqj = -aqj, aqk = -aqk;
170 }
171 const Scalar angle = 2 * math_asin(r);
172 DisplacementVector3D<Cartesian3D<double>> axis(aqi, aqj, aqk);
173 if (r == 0) {
174 axis.SetCoordinates(0, 0, 1);
175 } else {
176 axis /= r;
177 }
178 return AxisAngle(axis, angle);
179}
180
182{
183 // combination with RotationZ
184
185 const Scalar s1 = math_sin(fAngle / 2);
186 const Scalar au = math_cos(fAngle / 2);
187 const Scalar ai = s1 * fAxis.X();
188 const Scalar aj = s1 * fAxis.Y();
189 const Scalar ak = s1 * fAxis.Z();
190 Scalar c = rz.CosAngle();
191 if (c > 1)
192 c = 1;
193 if (c < -1)
194 c = -1;
195 Scalar qu = math_sqrt(.5 * (1 + c));
196 Scalar qk = math_sqrt(.5 * (1 - c));
197 if (rz.SinAngle() < 0)
198 qk = -qk;
199 Scalar aqu = au * qu - ak * qk;
200 Scalar aqi = ai * qu + aj * qk;
201 Scalar aqj = aj * qu - ai * qk;
202 Scalar aqk = ak * qu + au * qk;
203 Scalar r = math_sqrt(aqi * aqi + aqj * aqj + aqk * aqk);
204 if (r > 1)
205 r = 1;
206 if (aqu < 0) {
207 aqu = -aqu;
208 aqi = -aqi;
209 aqj = -aqj, aqk = -aqk;
210 }
211 const Scalar angle = 2 * math_asin(r);
212 DisplacementVector3D<Cartesian3D<double>> axis(aqi, aqj, aqk);
213 if (r == 0) {
214 axis.SetCoordinates(0, 0, 1);
215 } else {
216 axis /= r;
217 }
218 return AxisAngle(axis, angle);
219}
220
222{
223 return AxisAngle(r) * a; // TODO: improve performance
224}
225
227{
228 return AxisAngle(r) * a; // TODO: improve performance
229}
230
232{
233 return AxisAngle(r) * a; // TODO: improve performance
234}
235
236} // namespace ROOT_MATH_ARCH
237} // namespace ROOT
ROOT::R::TRInterface & r
Definition Object.C:4
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
#define s1(x)
Definition RSha256.hxx:91
#define e(i)
Definition RSha256.hxx:103
float * q
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition AxisAngle.h:46
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition AxisAngle.h:265
AxisAngle()
Default constructor (axis is z and angle is zero).
Definition AxisAngle.h:59
Class describing a generic displacement vector in 3 dimensions.
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
DisplacementVector3D< CoordSystem, Tag > & SetCoordinates(const Scalar src[])
Set internal data based on a C-style array of 3 Scalar numbers.
EulerAngles class describing rotation as three angles (Euler Angles).
Definition EulerAngles.h:50
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition Quaternion.h:52
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition Rotation3D.h:71
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition RotationX.h:45
Scalar SinAngle() const
Sine or Cosine of the rotation angle.
Definition RotationX.h:105
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Definition RotationY.h:45
Scalar SinAngle() const
Sine or Cosine of the rotation angle.
Definition RotationY.h:105
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Definition RotationZYX.h:64
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition RotationZ.h:45
Scalar SinAngle() const
Sine or Cosine of the rotation angle.
Definition RotationZ.h:105
Scalar math_cos(Scalar x)
Rotation3D::Scalar Scalar
Scalar math_sqrt(Scalar x)
Scalar math_asin(Scalar x)
AxisAngle operator*(RotationX const &r1, AxisAngle const &r2)
Multiplication of an axial rotation by an AxisAngle.
Scalar math_sin(Scalar x)