|
-
Nov 12th, 2004, 10:12 AM
#1
Thread Starter
Hyperactive Member
HELP! calculating vector components [RESOLVED]
hi... i know this has been asked before but i haev spent the last half an hour searchin the forums for the answer.. basically does anyone have some code which you can use to turn two points (x1,y1),(x2,y2) into a vector, basically i want to find the direction from object 1 to object 2 in a vector form (assume the magnitude=1) and i know you need a different equation depending on which quadrant its in (0-90,90-180 etc) but i cant figure it out any help would b much appreciated
Last edited by Arachnid13; Nov 15th, 2004 at 09:53 AM.
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
-
Nov 13th, 2004, 03:04 PM
#2
-
Nov 14th, 2004, 12:54 AM
#3
Hi Arachnid13, did you get what you need? Or do you also need the direction in degrees? Let us know
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Nov 14th, 2004, 01:38 AM
#4
Found the routine I'm using
VB Code:
Public Const Pi = 3.141592654
Public Const PiDurch180 = Pi / 180
Public Const A180DurchPi = 180 / Pi
Public Function Bearing(x1, y1, x2, y2) As Single
'Input X1, Y1, X2, Y2
Calculates Bearing(0-360)
'Calculates from X1,Y1 to X2,Y2 in 360degree-system
'North, Y , Lat gets bigger!!!!
'East X, Long gets bigger!!!!!
Dim dx As Single
Dim dy As Single
dx = x2 - x1
dy = y2 - y1
If dy <> 0 Then
Bearing = (Atn(dx / dy) * A180DurchPi)
If x2 > x1 Then
If y2 > y1 Then
Bearing = Bearing
Else
Bearing = 180 + Bearing
End If
Else
If y2 > y1 Then
Bearing = 360 + Bearing
Else
Bearing = 180 + Bearing
End If
End If
Else
If x1 > x2 Then
Bearing = 270
Else
Bearing = 90
End If
End If
End Function
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Nov 15th, 2004, 09:53 AM
#5
Thread Starter
Hyperactive Member
thanks guys, both are very useful, the second post was what i meant but ive just realised i can do what i needed with the first one and its much simpler... should have thought of it before... thanks!
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
-
Nov 15th, 2004, 02:22 PM
#6
No worries
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|