Quote: Original post by hiigara
How do I rotate this vector 0.02 Radians using the Unit Vector Method?
You can rotate the vector like this:
Vector2D rotate(Vector2D const &v, double angle) {
double cosine = std::cos(angle), sine = std::sin(angle);
return Vector2D(cosine*v.x - sine*v.y, sine*v.x + cosine*v.y);
}
If you do it using complex numbers, it becomes:
std::complex<double> rotate(std::complex<double> z, double angle) {
return z * std::complex<double>(std::cos(angle), std::sin(angle));
}
Or even:
std::complex<double> rotate(std::complex<double> z, double angle) {
return z * std::exp(std::complex<double>(0,angle));
}
Quote: Another task I need to perform is to calculate the Angle of a foreign Object in my Local Referencial and I am currently doing it with Angles:
*** Source Snippet Removed ***
This kind of operation is very easy with complex numbers:
std::complex<double> rotation_that_turns_A_into_B(std::complex<double> A, std::complex<double> B) {
std::complex<double> result = B/A;
return result/std::abs(result);
}
If I had to do it with 2D vectors, I would simply expand the formula for complex division.