translating x/y to angle?
Moderator: Moderators
translating x/y to angle?
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?
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
۞
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:
How about trigonometry?
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.
Code: Select all
B
/2|
/\_|
c / | b
/ |
/1) (.|
A------+
ab = B.y - A.y
c2 = a2 + b2
You can get the value of angle #1 by a trigonometric function.
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.
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.
Moderator
۞
Abyssus pro sapientia
Olympus pro Ignarus
۞
AND STUFF™ © 2006
۞
Abyssus pro sapientia
Olympus pro Ignarus
۞
AND STUFF™ © 2006
sticks
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.
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.
-
Rookie One.pl
- Site Admin
- Posts: 2752
- Joined: Fri Jan 31, 2003 7:49 pm
- Location: Nowa Wies Tworoska, Poland
- Contact:
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
). 
To be honest, I don't know the exact way to do it either (we'll have trigonometry in May).
I just know you can do it like that. Ask your dad maybe? 
To be honest, I don't know the exact way to do it either (we'll have trigonometry in May).
-
Rookie One.pl
- Site Admin
- Posts: 2752
- Joined: Fri Jan 31, 2003 7:49 pm
- Location: Nowa Wies Tworoska, Poland
- Contact:
Yes i know about the Cartesian Graph system
, 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.
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
۞
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)
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 .


-
PKM
- General
- Posts: 1888
- Joined: Tue Aug 09, 2005 4:43 pm
- Location: Philadelpia but stuck in San Antonio TX (hell)
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.lizardkid wrote:without math dorks, you wouldnt even be discussing it
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 .


-
Rookie One.pl
- Site Admin
- Posts: 2752
- Joined: Fri Jan 31, 2003 7:49 pm
- Location: Nowa Wies Tworoska, Poland
- Contact:
IT's completely arguable.. but i'm hijacking my own thread 0_0PKM wrote: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.lizardkid wrote:without math dorks, you wouldnt even be discussing it
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.
Moderator
۞
Abyssus pro sapientia
Olympus pro Ignarus
۞
AND STUFF™ © 2006
۞
Abyssus pro sapientia
Olympus pro Ignarus
۞
AND STUFF™ © 2006



