Browse Source

Math: rotation dual complex number.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
1a5e18564e
  1. 1
      src/Math/Complex.h
  2. 26
      src/Math/DualComplex.h
  3. 6
      src/Math/DualQuaternion.h
  4. 2
      src/Math/Matrix3.h
  5. 6
      src/Math/Matrix4.h
  6. 2
      src/Math/Quaternion.h
  7. 12
      src/Math/Test/DualComplexTest.cpp

1
src/Math/Complex.h

@ -140,6 +140,7 @@ template<class T> class Complex {
* @f[
* \theta = atan2(b, a)
* @f]
* @see rotation(), DualComplex::rotationAngle()
*/
inline Rad<T> rotationAngle() const {
return Rad<T>(std::atan2(_imaginary, _real));

26
src/Math/DualComplex.h

@ -35,6 +35,20 @@ template<class T> class DualComplex: public Dual<Complex<T>> {
public:
typedef T Type; /**< @brief Underlying data type */
/**
* @brief Rotation dual complex number
* @param angle Rotation angle (counterclockwise)
*
* @f[
* \hat c = (cos \theta + i sin \theta) + \epsilon (0 + i0)
* @f]
* @see rotationAngle(), Complex::rotation(), Matrix3::rotation(),
* DualQuaternion::rotation()
*/
inline static DualComplex<T> rotation(Rad<T> angle) {
return {Complex<T>::rotation(angle), {{}, {}}};
}
/**
* @brief Default constructor
*
@ -58,6 +72,18 @@ template<class T> class DualComplex: public Dual<Complex<T>> {
*/
inline constexpr /*implicit*/ DualComplex(const Complex<T>& real, const Complex<T>& dual): Dual<Complex<T>>(real, dual) {}
/**
* @brief Rotation angle of dual complex number
*
* @f[
* \theta = atan2(b_0, a_0)
* @f]
* @see rotation(), Complex::rotationAngle()
*/
inline Rad<T> rotationAngle() const {
return this->real().rotationAngle();
}
/**
* @brief Complex-conjugated dual complex number
*

6
src/Math/DualQuaternion.h

@ -38,15 +38,15 @@ template<class T> class DualQuaternion: public Dual<Quaternion<T>> {
/**
* @brief Rotation dual quaternion
* @param angle Rotation angle (counterclockwise, in radians)
* @param angle Rotation angle (counterclockwise)
* @param normalizedAxis Normalized rotation axis
*
* Expects that the rotation axis is normalized. @f[
* \hat q = [\boldsymbol a \cdot sin \frac \theta 2, cos \frac \theta 2] + \epsilon [\boldsymbol 0, 0]
* @f]
* @see rotationAngle(), rotationAxis(), Quaternion::rotation(),
* Matrix4::rotation(), Vector3::xAxis(), Vector3::yAxis(),
* Vector3::zAxis()
* Matrix4::rotation(), DualComplex::rotation(), Vector3::xAxis(),
* Vector3::yAxis(), Vector3::zAxis()
*/
inline static DualQuaternion<T> rotation(Rad<T> angle, const Vector3<T>& normalizedAxis) {
return {Quaternion<T>::rotation(angle, normalizedAxis), {{}, T(0)}};

2
src/Math/Matrix3.h

@ -64,7 +64,7 @@ template<class T> class Matrix3: public Matrix<3, T> {
* @brief 2D rotation matrix
* @param angle Rotation angle (counterclockwise)
*
* @see rotation() const, Complex::rotation(),
* @see rotation() const, Complex::rotation(), DualComplex::rotation(),
* Matrix4::rotation(Rad, const Vector3&)
*/
static Matrix3<T> rotation(Rad<T> angle) {

6
src/Math/Matrix4.h

@ -76,9 +76,9 @@ template<class T> class Matrix4: public Matrix<4, T> {
*
* Expects that the rotation axis is normalized. If possible, use
* faster alternatives like rotationX(), rotationY() and rotationZ().
* @see rotation() const, DualQuaternion::rotation(),
* Quaternion::rotation(), Matrix3::rotation(Rad), Vector3::xAxis(),
* Vector3::yAxis(), Vector3::zAxis()
* @see rotation() const, Quaternion::rotation(), DualQuaternion::rotation(),
* Matrix3::rotation(Rad), Vector3::xAxis(), Vector3::yAxis(),
* Vector3::zAxis()
*/
static Matrix4<T> rotation(Rad<T> angle, const Vector3<T>& normalizedAxis) {
CORRADE_ASSERT(MathTypeTraits<T>::equals(normalizedAxis.dot(), T(1)),

2
src/Math/Quaternion.h

@ -175,7 +175,7 @@ template<class T> class Quaternion {
* Expects that the quaternion is normalized. @f[
* \theta = 2 \cdot acos q_S
* @f]
* @see rotationAxis(), rotation()
* @see rotationAxis(), rotation(), DualQuaternion::rotationAngle()
*/
inline Rad<T> rotationAngle() const {
CORRADE_ASSERT(MathTypeTraits<T>::equals(dot(), T(1)),

12
src/Math/Test/DualComplexTest.cpp

@ -39,9 +39,13 @@ class DualComplexTest: public Corrade::TestSuite::Tester {
void inverted();
void invertedNormalized();
void rotation();
void debug();
};
typedef Math::Deg<float> Deg;
typedef Math::Rad<float> Rad;
typedef Math::Complex<float> Complex;
typedef Math::Dual<float> Dual;
typedef Math::DualComplex<float> DualComplex;
@ -62,6 +66,8 @@ DualComplexTest::DualComplexTest() {
&DualComplexTest::inverted,
&DualComplexTest::invertedNormalized,
&DualComplexTest::rotation,
&DualComplexTest::debug);
}
@ -149,6 +155,12 @@ void DualComplexTest::invertedNormalized() {
CORRADE_COMPARE(inverted, b/Math::sqrt(Dual(7.25f, -43.5f)));
}
void DualComplexTest::rotation() {
DualComplex a = DualComplex::rotation(Deg(120.0f));
CORRADE_COMPARE(a, DualComplex({-0.5f, 0.8660254f}, {0.0f, 0.0f}));
CORRADE_COMPARE_AS(a.rotationAngle(), Deg(120.0f), Rad);
}
void DualComplexTest::debug() {
std::ostringstream o;

Loading…
Cancel
Save