Skip to content

Commit

Permalink
quaternion fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alemuntoni committed Oct 27, 2023
1 parent abfc719 commit 1ed603b
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions include/vclib/space/quaternion.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,14 @@ class Quaternion
{
}

Quaternion(const Eigen::Quaternion<Scalar>& qq) { q << qq; }
Quaternion(const Eigen::Quaternion<Scalar>& qq) : q(qq) {}

Quaternion(const Matrix33<Scalar>& rotMatrix) : q(rotMatrix) {}

Quaternion(const Matrix44<Scalar>& rotMatrix) : q(rotMatrix) {}
Quaternion(const Matrix44<Scalar>& rotMatrix) :
q(Matrix33<Scalar>(rotMatrix.block(0, 0, 3, 3)))
{
}

/**
* @brief Constructs the quaternion that will represent the rotation between
Expand Down Expand Up @@ -277,8 +280,16 @@ class Quaternion
Point3<Scalar> operator*(const Point3<Scalar>& p)
{
const Eigen::Matrix<Scalar, 1, 3>& v = p.eigenVector();
return Point3<Scalar>(
v + 2.0 * q.vec().cross(q.vec().cross(v) + q.w() * v));

Eigen::Matrix<Scalar, 1, 3> fc = q.vec().cross(v);

Eigen::Matrix<Scalar, 1, 3> fd = v * q.w();

Eigen::Matrix<Scalar, 1, 3> s = fc + fd;

Eigen::Matrix<Scalar, 1, 3> sc = q.vec().cross(s);

return Point3<Scalar>(v + sc * 2.0 );
}

Quaternion& operator*=(const Quaternion<Scalar>& q2)
Expand Down

0 comments on commit 1ed603b

Please sign in to comment.