Page 1 of 2
translating x/y to angle?
Posted: Sun Mar 19, 2006 9:46 pm
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?
Posted: Sun Mar 19, 2006 9:57 pm
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.
Posted: Mon Mar 20, 2006 1:54 am
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.

sticks
Posted: Mon Mar 20, 2006 1:18 pm
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.
Posted: Mon Mar 20, 2006 2:46 pm
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

).
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?

Posted: Mon Mar 20, 2006 4:38 pm
by jv_map
Errmm arctan (y/x) maybe?
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)).
Posted: Mon Mar 20, 2006 4:47 pm
by Rookie One.pl
...and jv_map saves the day again.

Posted: Mon Mar 20, 2006 4:48 pm
by lizardkid
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.
Posted: Mon Mar 20, 2006 7:16 pm
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.
Posted: Tue Mar 21, 2006 5:56 am
by lizardkid
without math dorks, you wouldnt even be discussing it

Posted: Tue Mar 21, 2006 11:42 am
by PKM
lizardkid wrote:without math dorks, you wouldnt even be discussing it

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.
Posted: Tue Mar 21, 2006 1:35 pm
by Elgan
maths* ffs
Posted: Tue Mar 21, 2006 2:41 pm
by Rookie One.pl
Mathematics* ffs!
Calm down, Elg.

Posted: Tue Mar 21, 2006 4:20 pm
by lizardkid
PKM wrote:lizardkid wrote:without math dorks, you wouldnt even be discussing it

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
Posted: Tue Mar 21, 2006 6:21 pm
by PKM
lizardkid wrote:
IT's completely arguable.. but i'm hijacking my own thread 0_0
basta !!!!