I have tried to implement the rotation of a 3D vector around an arbitrary axis for an arbitrary angle, using Rodrigues' rotation formula (Rodrigues' rotation formula):
vector3 vector3::rotate(const vector3 &axis, double theta) const
{
double cos_theta = cos(theta);
double sin_theta = sin(theta);
vector3 rotated = *this*cos_theta + (axis^*this)*sin_theta + axis*(axis*(*this))*(1 - cos_theta);
return rotated;
}
but it doesn't seem to be working correctly. I don't know what I am missing here, any help would be appreciated.
Edit:
These are the operators I used:
vector3 operator*(double) const; //multiplication by scalar
friend vector3 operator*(double, const vector3&); //multiplication by scalar
double operator*(const vector3&) const; //dot product
vector3 operator^(const vector3&) const; //cross product
and they have been tested (they work correctly).