GithubHelp home page GithubHelp logo

lionkor / vector2 Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 38 KB

A templated header-only 2D Vector class

License: MIT License

C++ 100.00%
maths vector geometry physics cpp cpp11 cpp17 math mathematics tools

vector2's Issues

rotate_deg does not work correctly

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));
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.