Skip to content
Advertisement

Getting the angle from a direction vector?

I have this simple function to set an angle for a vector. It effectively gets the vector’s current magnitude (length), calulates the angle and converts the angle from radians to degrees. Then I apply the angle to X and Y, lastly multiplying the vector by it’s original magnitude.

JavaScript

However I am unsure how to obtain (get) an angle from a Vector. Below is my attempt:

JavaScript

This attempt doesn’t return any value except 0 or -1.

Any suggestions?

Edit:

Correct method:

JavaScript

Advertisement

Answer

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement