Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angle between two vectors? #30

Open
ahvonenj opened this issue Apr 18, 2016 · 1 comment
Open

Angle between two vectors? #30

ahvonenj opened this issue Apr 18, 2016 · 1 comment

Comments

@ahvonenj
Copy link

Could we get a method for angle between two vectors?`

Something like:

var v1 = new Victor(10, 10);
var v2 = new Victor(20, 20);
var angle = v1.angle(v2);

This would be inherently useful for game programming.

@ahvonenj
Copy link
Author

Here is a Gist that I've starred and use currently:

https://gist.github.com/conorbuck/2606166

var p1 = {
    x: 20,
    y: 20
};

var p2 = {
    x: 40,
    y: 40
};

// angle in radians
var angleRadians = Math.atan2(p2.y - p1.y, p2.x - p1.x);

// angle in degrees
var angleDeg = Math.atan2(p2.y - p1.y, p2.x - p1.x) * 180 / Math.PI;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant