translating x/y to angle?

Post everything that hasn't to do with MOHAA or MOHPA here, including site feedback/suggestions.

Moderator: Moderators

lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

translating x/y to angle?

Post by lizardkid »

well i'm fooling around with a 2D game, just a basic one, not even sure what it's going to be like yet. but i'm jsut getting the basic moving items and such down, so far i've managed to get most of it without help, but this has me stumped.

I'm trying to make it so when an entity is going somewhere, it turns to face the destination, and i have the values set up like MOH. angle and x/y values.

What kind of algorithm do i need to translate x/y coords to 360 degrees?
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

How about trigonometry?

Code: Select all

       B
     /2|
    /\_|
c  /   | b
  /    |
 /1) (.|
A------+
    a
a = B.x - A.x
b = B.y - A.y
c2 = a2 + b2
You can get the value of angle #1 by a trigonometric function.
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post by lizardkid »

trig's next year for me, i knew it had to be something fairly obvious with higher math, but i didn't know what.

i understand it.. the only trig i've ever done is the most basic of basic sine cosin etangent stuff, so yes i know a1 would be the difference of b1 and c1 (all tri's have 180 degrees... allangles must add up to that)

that's great and dandy, if i were angling multiple sprites. but this is just one, it's all 90 degree angles and i can get the length of the sides easy enough, but what sort of code would i be using to determine an overall angle of a polygon?

maybe i just didnt understand your post. :lol:
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

sticks

Post by tltrude »

Take four yardsticks or rulers and make a cross (+). X is the north-south ones, and Y is the east-west ones. Zero is the center. Now you can plot any point by seeing how many inches there are for X and Y. But remember that points below and left of center are negitive numbers.

Angles from center would be done with two protractor sitting on the Y line of rulers. The 0-360 angle will be to the right (east), so 90 is south, 180 is west and 270 is north. At least that is how it is done in Moh.

Hope that helps.
Tom Trude,

Image
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

Tom, I think you're confusing the axes. ;) X is always the horizontal one, Y is the vertical. Besides, I think he knows that stuff (at least I learnt it at elementary school :P). ;)

To be honest, I don't know the exact way to do it either (we'll have trigonometry in May). :P I just know you can do it like that. Ask your dad maybe? ;)
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Errmm arctan (y/x) maybe? :P

Also written tan^-1 (y/x).

Angle returned may be in degrees or radians, usually radians.

1 deg = pi / 180 rad

If x < 0, you need to add or subtract 180 degrees (unless you're using atan2(y,x)).
Image
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

...and jv_map saves the day again. :)
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post by lizardkid »

Yes i know about the Cartesian Graph system :P, i can move entities around in my little gamespace, jsut not rotate them so they face the direction they're going.

Thanks jv, i'll try that tan(y/x)^-1 thing, of course after that i'll need to divide by (pi / 180) ? it just seems like a constant the way you wrote it...

just double-checking, i'll try it next chance i get.
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
PKM
General
Posts: 1888
Joined: Tue Aug 09, 2005 4:43 pm
Location: Philadelpia but stuck in San Antonio TX (hell)

Post by PKM »

math dorks. i hate you all. ironic i married a polak math teacher, isn't it. oh the heated 'discussions' we have. also strange is the fact that nine months after one of these heated 'discussions'...i somehow end up with another son. go figure. it must be my blessed yardstick.
i'm not f****** angry, i'm from philadelphia .
Image
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post by lizardkid »

without math dorks, you wouldnt even be discussing it :P
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
PKM
General
Posts: 1888
Joined: Tue Aug 09, 2005 4:43 pm
Location: Philadelpia but stuck in San Antonio TX (hell)

Post by PKM »

lizardkid wrote:without math dorks, you wouldnt even be discussing it :P
ooooooooooooh, there's that arguement. the ''math provided the light for the world'' egotistic thrust. sure we wouldn't be having this discussion...........so far apart from each other without math and (pfffffft) engineering.


we'd be doing it face to face the same way man has done it for millions of years. open ORAL discussions trumps any IM service not matter what dings and bells it has ? file transfer ? hell i'd rather you live in my village and i give you the information you need with a handshake.

math and engineering do not provide solutions , they provide nothing more than conviences.

bring it.
i'm not f****** angry, i'm from philadelphia .
Image
Elgan
Lieutenant General
Posts: 890
Joined: Tue Apr 13, 2004 10:43 pm
Location: uk
Contact:

Post by Elgan »

maths* ffs
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

Mathematics* ffs! :P

Calm down, Elg. ;)
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post by lizardkid »

PKM wrote:
lizardkid wrote:without math dorks, you wouldnt even be discussing it :P
ooooooooooooh, there's that arguement. the ''math provided the light for the world'' egotistic thrust. sure we wouldn't be having this discussion...........so far apart from each other without math and (pfffffft) engineering.


we'd be doing it face to face the same way man has done it for millions of years. open ORAL discussions trumps any IM service not matter what dings and bells it has ? file transfer ? hell i'd rather you live in my village and i give you the information you need with a handshake.

math and engineering do not provide solutions , they provide nothing more than conviences.

bring it.
IT's completely arguable.. but i'm hijacking my own thread 0_0
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
PKM
General
Posts: 1888
Joined: Tue Aug 09, 2005 4:43 pm
Location: Philadelpia but stuck in San Antonio TX (hell)

Post by PKM »

lizardkid wrote: IT's completely arguable.. but i'm hijacking my own thread 0_0

basta !!!!
i'm not f****** angry, i'm from philadelphia .
Image
Post Reply