jmasterx
jmasterx

Reputation: 54183

Angle from vector

Say I have point A (20,20) and point B (60,60).

The resulting vector would be 40, 40. How could I get the angle of this vector?

By this I mean, imagine there is an imaginary circle around the origin.

I guess sort of what atan2 does but without atan2.

Thank

Upvotes: 1

Views: 1845

Answers (3)

Oliver Moran
Oliver Moran

Reputation: 5167

Presuming that you want to find the angle of the vector against the X axis (in JavaScript):

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

var rad = Math.atan(vector.y/vector.x)
var deg = rad * 180/Math.PI;

alert(deg); // 45 deg

Upvotes: 3

tkerwin
tkerwin

Reputation: 9769

I'm not sure what you mean by angle, since you only give one vector in your example. But, given two vectors, you can find the angle between them like so:

Given vectors a and b, normalize both of them. Then, dot(a, b) = cos(θ), where θ is the angle between the two vectors. Use arccos to find θ.

Upvotes: 1

Gary Tsui
Gary Tsui

Reputation: 1755

Below is the link that will show you how to find the angle bewteen two vectors:

http://www.wikihow.com/Find-the-Angle-Between-Two-Vectors

Upvotes: 0

Related Questions