27 #ifndef RL_MATH_TRANSFORMADDONS_H
28 #define RL_MATH_TRANSFORMADDONS_H
30 template<
typename Scalar,
int Dim,
int Mode,
int Options>
33 distance(
const Transform<Scalar, Dim, Mode, Options>& other,
const Scalar& weight = 1)
const
35 Quaternion<Scalar> q1(rotation());
36 Quaternion<Scalar> q2(other.rotation());
39 ::
std::pow(other(0, 3) - (*
this)(0, 3), 2) +
40 ::
std::pow(other(1, 3) - (*
this)(1, 3), 2) +
41 ::
std::pow(other(2, 3) - (*
this)(2, 3), 2) +
42 weight * ::
std::pow(q1.angularDistance(q2), 2)
54 template<
typename Scalar,
int Dim,
int Mode,
int Options>
57 fromDelta(
const Transform<Scalar, Dim, Mode, Options>& other,
const Matrix<Scalar, 6, 1>& delta,
const bool& useApproximation =
false)
61 (*this)(0, 0) = other(0, 0) - delta(5) * other(1, 0) + delta(4) * other(2, 0);
62 (*this)(0, 1) = other(0, 1) - delta(5) * other(1, 1) + delta(4) * other(2, 1);
63 (*this)(0, 2) = other(0, 2) - delta(5) * other(1, 2) + delta(4) * other(2, 2);
64 (*this)(0, 3) = other(0, 3) + delta(0);
65 (*this)(1, 0) = other(1, 0) + delta(5) * other(0, 0) - delta(3) * other(2, 0);
66 (*this)(1, 1) = other(1, 1) + delta(5) * other(0, 1) - delta(3) * other(2, 1);
67 (*this)(1, 2) = other(1, 2) + delta(5) * other(0, 2) - delta(3) * other(2, 2);
68 (*this)(1, 3) = other(1, 3) + delta(1);
69 (*this)(2, 0) = other(2, 0) - delta(4) * other(0, 0) + delta(3) * other(1, 0);
70 (*this)(2, 1) = other(2, 1) - delta(4) * other(0, 1) + delta(3) * other(1, 1);
71 (*this)(2, 2) = other(2, 2) - delta(4) * other(0, 2) + delta(3) * other(1, 2);
72 (*this)(2, 3) = other(2, 3) + delta(2);
80 Transform<Scalar, Dim, Mode, Options> t;
81 t.linear() = (AngleAxis<Scalar>(delta.segment(3, 3).norm(), delta.segment(3, 3).normalized())).toRotationMatrix();
82 t.translation() = t.linear() * delta.segment(0, 3);
91 Scalar cosAlpha = ::std::cos(alpha);
92 Scalar cosTheta = ::std::cos(theta);
93 Scalar sinAlpha = ::std::sin(alpha);
94 Scalar sinTheta = ::std::sin(theta);
96 (*this)(0, 0) = cosTheta;
97 (*this)(1, 0) = sinTheta;
98 (*this)(2, 0) = Scalar(0);
99 (*this)(3, 0) = Scalar(0);
100 (*this)(0, 1) = -cosAlpha * sinTheta;
101 (*this)(1, 1) = cosAlpha * cosTheta;
102 (*this)(2, 1) = sinAlpha;
103 (*this)(3, 1) = Scalar(0);
104 (*this)(0, 2) = sinAlpha * sinTheta;
105 (*this)(1, 2) = -sinAlpha * cosTheta;
106 (*this)(2, 2) = cosAlpha;
107 (*this)(3, 2) = Scalar(0);
108 (*this)(0, 3) = a * cosTheta;
109 (*this)(1, 3) = a * sinTheta;
111 (*this)(3, 3) = Scalar(1);
114 template<
typename Scalar>
119 Matrix<Scalar, 6, 1> res;
121 res(0) = (*this)(0, 3);
122 res(1) = (*this)(1, 3);
123 res(2) = (*this)(2, 3);
124 res(3) = ((*this)(2, 1) - (*
this)(1, 2)) / 2.0f;
125 res(4) = ((*this)(0, 2) - (*
this)(2, 0)) / 2.0f;
126 res(5) = ((*this)(1, 0) - (*
this)(0, 1)) / 2.0f;
131 template<
typename Scalar>
137 (*this)(0, 1) = -delta(5);
138 (*this)(0, 2) = delta(4);
139 (*this)(0, 3) = delta(0);
140 (*this)(1, 0) = delta(5);
142 (*this)(1, 2) = -delta(3);
143 (*this)(1, 3) = delta(1);
144 (*this)(2, 0) = -delta(4);
145 (*this)(2, 1) = delta(3);
147 (*this)(2, 3) = delta(2);
163 template<
typename Scalar,
int Dim,
int Mode,
int Options>
166 toDelta(
const Transform<Scalar, Dim, Mode, Options>& other,
const bool& useApproximation =
false)
const
168 Matrix<Scalar, 6, 1> res;
170 res(0) = other(0, 3) - (*this)(0, 3);
171 res(1) = other(1, 3) - (*this)(1, 3);
172 res(2) = other(2, 3) - (*this)(2, 3);
174 if (useApproximation)
176 res(3) = ((*this)(1, 0) * other(2, 0) - (*this)(2, 0) * other(1, 0) + (*this)(1, 1) * other(2, 1) - (*this)(2, 1) * other(1, 1) + (*this)(1, 2) * other(2, 2) - (*this)(2, 2) * other(1, 2)) / 2.0f;
177 res(4) = ((*this)(2, 0) * other(0, 0) - (*this)(0, 0) * other(2, 0) + (*this)(2, 1) * other(0, 1) - (*this)(0, 1) * other(2, 1) + (*this)(2, 2) * other(0, 2) - (*this)(0, 2) * other(2, 2)) / 2.0f;
178 res(5) = ((*this)(0, 0) * other(1, 0) - (*this)(1, 0) * other(0, 0) + (*this)(0, 1) * other(1, 1) - (*this)(1, 1) * other(0, 1) + (*this)(0, 2) * other(1, 2) - (*this)(1, 2) * other(0, 2)) / 2.0f;
182 AngleAxis<Scalar> r(Matrix<Scalar, 3, 3>(other.linear() * linear().transpose()));
183 res.segment(3, 3) = r.angle() * r.axis();
193 assert(::std::abs((*
this)(2, 0)) <= ::std::numeric_limits<Scalar>::epsilon());
197 theta = ::std::atan2((*
this)(1, 0), (*
this)(0, 0));
199 if (::std::abs((*
this)(0, 0)) <= ::std::numeric_limits<Scalar>::epsilon())
201 a = (*this)(1, 3) / (*
this)(1, 0);
203 else if (::std::abs((*
this)(1, 0)) <= ::std::numeric_limits<Scalar>::epsilon())
205 a = (*this)(0, 3) / (*
this)(0, 0);
209 a = (*this)(1, 3) / (*
this)(1, 0) + (*
this)(0, 3) / (*
this)(0, 0);
212 alpha = ::std::atan2((*
this)(2, 1), (*
this)(2, 2));
215 #endif // RL_MATH_TRANSFORMADDONS_H