lionkor / Vector2

A templated header-only 2D Vector class

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rotate_deg does not work correctly

lionkor opened this issue · comments

commented

When rotating a vector, rotate_deg does not calculate correctly.

Example:
Vector2 (2, 5).rotated_deg (90) should rotate vector (2, 5) by 90 degrees, which should return a vector (-5, 2) (correct example result).

It instead returns a vector (2, -5).

Using the latest version, you can reproduce it with this code:

std::cout << Vector2f (2, 5).rotated_deg (90) << std::endl;

Which will output x: 2 y: -5, a wrong result.

This is reproducible with many different vectors and degrees.

Vector2/Vector2.hpp

Lines 364 to 371 in 17cdcf4

constexpr Vector2 rotated_deg (double angle_degrees) const
{
// convert to radians
long double radians = angle_degrees * (VECTOR2_MATH_PI<long double> / 180.0);
return Vector2 (
x * sin (radians) + x * cos (radians),
x * cos (radians) - y * sin (radians));
}

commented

rotate_rad was broken as well, and both did not rotate clockwise either. Fixed both in the latest commit bc2ba09