Jump to content

Moving around a Graph


Recommended Posts

I am trying to find out how to get from one point to the next using autoit. The purpose is waypoints for a game I am working on. I know my starting location and my destination, but I do not know how to get there. The points are plotted on a standard 4 quadrant graph.

Here is what I am talking about.

Posted Image

The Red Dot is my starting location and it is at (3,-3)

The Blue Dot is my destination at (5,-1)

Look at the graph as a piece of land, and you standing on the red dot. You know you are at (3,-3) and that you need to get to (5,-1). However, you do not know which direction to move. How could I find out which direction to face and then move to the location?

I am sure there is a way to do this mathmatically, but it has been a while since I was in High School math and didn't like it much anyway. Any help is greatly appreciated!

Thanks

Link to comment
Share on other sites

I'm rusty, but:

(3,-3) and (5,-1)

change in X is -2

change in Y is 2

Slope is rise over run (delta Y / delta X) == 2/-2 == -1

for every x coordinate you increment by 1, you decrement y coord by 1.

EDIT: (So I guess that's north-east)

Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

end x - start x, end y - start y

5-3,-1--3 or 2,2 that's your right triangle to calculate the direction from.

Bah, too slow of a typer

Edited by Ejoc
Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Link to comment
Share on other sites

I will need to spin the character in the right direction in order to run the right way to the target coordinates. Without being able to directly edit the current coordinates, other then hitting the run forward and turn keys. Would it even be possible?

<{POST_SNAPBACK}>

Do you have a way to find your current orientation? It's a bit of simple trig to find your desired direction, but you need to know your current one for it to be useful.
Link to comment
Share on other sites

Look at the graph as a piece of land, and you standing on the red dot. You know you are at (3,-3) and that you need to get to (5,-1). However, you do not know which direction to move. How could I find out which direction to face and then move to the location?

I think the below syntax is correct for you to work out if its N, W, E, S, NE, SE, SW or NW.

Corret me if I'm wrong please.

X = (X2 - X1)
Y = (Y2 - Y1)

Gradient(M) = Y  / X 

A = X                     ;Adjacent
O = Y                     ;Opposite
H = Sqrt (X^2 + Y^2)       ;Hypotenuse

sin = O/H
cos = A/H
tan = O/A


If M = 0 Then
   If X > 0 Then 
      East
   ElseIf X < 0 Then
      West
   EndIf
Else
   If M = "-1.#INF" Then 
      South
   ElseIf M = "1.#INF" Then 
      North
   EndIf
EndIf

If sin > 0 AND cos > 0 AND tan > 0 Then
   North East
ElseIf sin > 0 AND cos < 0 AND tan < 0 Then
   North West
ElseIf tan > 0 AND cos < 0 AND sin < 0 Then
   South West
ElseIf cos > 0 AND tan < 0 AND sin < 0 Then
   South East
EndIf
Edited by Burrup

qq

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...