MATHDLL_API Vector3 RotateAround(const Vector3 & axis, float amount, const Vector3 & vectorToRotate) { Matrix4 identity; identity.Identity(); Matrix4 first = identity * cos(amount); Matrix4 second = TensorProductMatrix(axis) * (1 - cos(amount)); Matrix4 third = CrossProductMatrix(axis) * sin(amount); Vector4 endVal = (first + second + third) * vectorToRotate; return Vector3(endVal.x, endVal.y, endVal.z); }
void FlyingLayer::AngleAxisRotationMatrix(float angle, const Vector3f& axis, Matrix3x3f &retval) const { Vector3f axisVec = axis.normalized(); // use Rodrigues' formula to create the matrix float cos_angle = std::cos(angle); float sin_angle = std::sin(angle); // start with the cross product term, calculating it in-place CrossProductMatrix(axisVec*sin_angle, retval); // add Matrix3x3f::Identity()*cos_angle to retval retval(0, 0) += cos_angle; retval(1, 1) += cos_angle; retval(2, 2) += cos_angle; // add the outer product term -- multiply the scalar factor before forming the outer product retval += ((1.0 - cos_angle)*axisVec) * axisVec.transpose(); }
Matrix3x3f FlyingLayer::CrossProductMatrix(const Vector3f& vector) const { Matrix3x3f result; CrossProductMatrix(vector, result); return result; }
EigenTypes::Matrix3x3f MathUtility::CrossProductMatrix(const EigenTypes::Vector3f& vector) { EigenTypes::Matrix3x3f result; CrossProductMatrix(vector, result); return result; }