Click to See Complete Forum and Search --> : Angle of two points...
loopfish
Mar 5th, 2001, 03:49 AM
Hi I have two points on 2d plane and need to work out the angle that they create relative to +x axis..
This is what I have come up with so far but it's too long and I'm sure there is a better way..
x = DistX - SrcX
y = DistY - SrcY
if y>0 and x>0 then Angle = ATN(abs(y)/abs(x))
if y>0 and x<0 then Angle = ATN(abs(x)/abs(y)) + 90
if y<0 and x<0 then Angle = ATN(abs(y)/abs(x)) + 180
if y<0 and x>0 then Angle = ATN(abs(x)/abs(y)) + 270
HarryW
Mar 5th, 2001, 04:37 AM
You can use Guv's ATan function: http://forums.vb-world.net/showthread.php?s=&threadid=53924
kedaman
Mar 5th, 2001, 09:13 AM
It's becoming more and more famous :)
although Arktangent(y,x) gives you the angle from 0 to 180, it's still Arctan and won't return angles above 180.
Here's what you should use for 360 degree angles:
Function AngleByOffset(offsetX As Double, offsetY As Double) As Double
If offsetX Then
AngleByOffset = Atn(offsetY / offsetX) - (offsetX > 0) * 3.14159265358979
Else
AngleByOffset = 1.5707963267949 + (offsetY > 0) * 3.14159265358979
End If
End Function
loopfish
Mar 5th, 2001, 12:34 PM
Thanks Kedaman,
Works perfectly..
Sastraxi
Mar 11th, 2001, 09:17 AM
I need to find the angle of two points on a 3d plane... maybe someone could help me there, as I am not too good in maths...
HarryW
Mar 11th, 2001, 10:23 AM
Well I just posted this in your other thread Sastraxi, but I may as well post it again here :) You can try the geometry tutorial at flipCode (http://www.flipcode.com/geometry/) for some good geometry info. To get the angle between 2 vectors you use the dot product, that much I remember.
kedaman
Mar 11th, 2001, 12:40 PM
yep, pretty simple actually
cos(angle) = (a·b) / |a||b|
where a and b are the vectors.
arcus cosinus can be substituted with this formula using arcus tangent, in vb5 help files:
Arccos(X) = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.