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() function #5

Closed
SolarLune opened this issue Apr 19, 2020 · 4 comments · Fixed by #8
Closed

Angle() function #5

SolarLune opened this issue Apr 19, 2020 · 4 comments · Fixed by #8

Comments

@SolarLune
Copy link
Contributor

Hello!

A function to return the angle between two Vectors would be highly useful, particularly in 2D; any plans to add this? I'm not too hot on my math, but I can take a crack at it if you'd find it useful.

@quartercastle
Copy link
Owner

I agree, it would be very useful. Your welcome to take a crack at it!

It is important that the solution works with both 2D and 3D vectors. The API could look something like the example below?

angle, err := vector.Angle(v1, v2)
// and
angle, err := v1.Angle(v2)

SolarLune added a commit to SolarLune/vector that referenced this issue May 4, 2020
Also fixing Vector.Cross(), because the function's formula was incorrect (double-checked using https://www.vcalc.com/wiki/vCalc/V3+-+V+x+U and https://www.omnicalculator.com/math/cross-product).
@SolarLune
Copy link
Contributor Author

Adding the Angle() function via PR. My proposed Angle() function returns the vector of rotation to get the angle from one vector to another, as well; seems like it might be good for Vector.Rotate() to take Vectors to rotate by, rather than being fixed axes.

SolarLune added a commit to SolarLune/vector that referenced this issue May 4, 2020
Also fixing Vector.Cross(), because the function's formula was incorrect (double-checked using https://www.vcalc.com/wiki/vCalc/V3+-+V+x+U and https://www.omnicalculator.com/math/cross-product).
@SolarLune
Copy link
Contributor Author

Updated with a slight improvement to the verbage of the docs for the Angle() function.

@quartercastle
Copy link
Owner

Seems like it might be good for Vector.Rotate() to take Vectors to rotate by, rather than being fixed axes.

This is a great idea! Will look into that.

quartercastle added a commit that referenced this issue May 5, 2020
* #5 - Adding Angle() function.
Also fixing Vector.Cross(), because the function's formula was incorrect (double-checked using https://www.vcalc.com/wiki/vCalc/V3+-+V+x+U and https://www.omnicalculator.com/math/cross-product).

* Taking out vector of rotation from Angle().
Not really useful until Vector.Rotate() takes arbitrary Vectors.
Fixing tests, adding benchmark.

Co-authored-by: Frederik Kvartborg Albertsen <[email protected]>
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

Successfully merging a pull request may close this issue.

2 participants