Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angle from 2D unit vector?

Tags:

c++

vector

angle

Given unit vector 0.5, 0.5 how could I find the angle (its direction),

is it

cos(x) + sin(y)?

like image 481
jmasterx Avatar asked Jun 06 '11 01:06

jmasterx


People also ask

How do you find the angle of a 2D vector?

To calculate the angle between two vectors in a 2D space: Find the dot product of the vectors. Divide the dot product by the magnitude of the first vector. Divide the resultant by the magnitude of the second vector.


2 Answers

Given y and x, the angle with the x axis is given by:

atan2(y,x) 

With (0.5, 0.5) the angle is:

radians:

In [2]: math.atan2(0.5,0.5) Out[2]: 0.7853981633974483 

degrees:

In [3]: math.atan2(0.5, 0.5)*180/math.pi Out[3]: 45.0 
like image 63
mpenkov Avatar answered Oct 16 '22 17:10

mpenkov


#include <cmath>  double x = 0.5; double y = 0.5; double angleInRadians = std::atan2(y, x); double angleInDegrees = (angleInRadians / M_PI) * 180.0; 
like image 32
Jonathan Grynspan Avatar answered Oct 16 '22 16:10

Jonathan Grynspan