Jump to content

given 2 points, calculate angle


Recommended Posts

I'm not sure if this is in the right sub-forums. If not, please move it.

 

If I were given two points (x,y) and (x',y'), how can I determine the angle they form? Let's assume that (x,y) is the vertex of the angle, and the other line the angle is to be measured from is (x+1,y). If the angle is to be defined by the area swept from (x+1,y), pivoting around (x,y) is a counterclockwise direction, and reaching the line connecting (x,y) and (x',y'), how would one calculate the angle?

Link to comment
Share on other sites

Thanks both,

 

The dot product works for angles from 0 to 180, but beyond that it starts repeating. For example, if (x',y') = (-1,-1) and (x,y) = (0, 0), then theta = 2.356, but if I set (x',y') = (-1,1) then theta = 2.356 - exactly the same. Obviously, I can deduce the angle on the other side by subtracting this result from 2*pi, but it would be best if I had a formula in which I didn't have to do this - the reason being I'm implementing this into a computer program, and I can't just tell it to "eye ball" the angle to tell whether or not it needs to subtract the result from 2*pi. What I need is a formula that gives results that span the whole range from 0 degrees to 360.

 

Fuzzwood,

 

Would your suggestion do this? I'm not sure what you mean by "finding the intersecting point". Do you mean the vertex (which wouldn't necessarily be at the origin)?

Link to comment
Share on other sites

If the angle with the x-axis is what you want, it's easier to calculate the inverse tan of the slope. But again, be careful; if the angle is larger than 90°, the angle will be negative, and you have to add it, or subtract it's absolute value, to/from 180°.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.