pds 0 #1 March 18, 2005 i want to get the heading (or angle), in degrees, of an arbitrary point (x,y) relative to 0,0. e.g. skydiver icon at 0,0 and i want it to face the mouse cursor. capisce? and iffn you don't have the answer, please tell me what it is i am asking for in proper terminology so i can inquire elsewhere. FANKYU!namaste, motherfucker. Quote Share this post Link to post Share on other sites
sunshine 2 #2 March 18, 2005 Quoteand iffn you don't have the answer, please tell me what it is i am asking for in proper terminology so i can inquire elsewhere. The proper way to say it is: Can i have another shot of tequila please? ___________________________________________ meow I get a Mike hug! I get a Mike hug! Quote Share this post Link to post Share on other sites
pds 0 #4 March 18, 2005 QuoteQuoteand iffn you don't have the answer, please tell me what it is i am asking for in proper terminology so i can inquire elsewhere. The proper way to say it is: Can i have another shot of tequila please? namaste, motherfucker. Quote Share this post Link to post Share on other sites
pds 0 #5 March 18, 2005 got it thanks to a helpful hint from MWGemini. he says i want the inverse tangent. which make sense. given his nutshell trig refresher and some twiddling got exactly what i needed. FANKYU! i'll have that shot of tequila now.namaste, motherfucker. Quote Share this post Link to post Share on other sites
pilotdave 0 #6 March 18, 2005 You're getting me all excited again. edit: not about the math. Dave Quote Share this post Link to post Share on other sites
pds 0 #7 March 18, 2005 QuoteYou're getting me all excited again. edit: not about the math. Dave namaste, motherfucker. Quote Share this post Link to post Share on other sites
Remster 30 #8 March 18, 2005 tang alpha = y/x so tan-1 (x/y) = alpha Alpha being the angle in radians. To converts to deg, use 180 deg = pi radiansRemster Quote Share this post Link to post Share on other sites
pds 0 #9 March 18, 2005 Quotetang alpha = y/x so tan-1 (x/y) = alpha Alpha being the angle in radians. To converts to deg, use 180 deg = pi radians yes. but computer don't know how to speak trig this is what i came up with after my trig lecture with mwgemini. rather elegant if i do say so mesef function relativeCoordsToHeading(x,y) { var radians = Math.atan2(x,y); var degrees = (eval(radians))*(180/Math.PI); if (x>0){degrees = 180 - degrees;} else {degrees = -degrees + 180;} return degrees; } namaste, motherfucker. Quote Share this post Link to post Share on other sites
Remster 30 #10 March 18, 2005 So you want us to do all the work, is that it???? Remster Quote Share this post Link to post Share on other sites
pds 0 #11 March 18, 2005 QuoteSo you want us to do all the work, is that it???? uh oh, is it that obvious? is an old programmer trick. ok, it's an old guy trick recycled: if you keep doing a crappy job at doing the dishes and washing the clothes she finally stops asking you to do it!namaste, motherfucker. Quote Share this post Link to post Share on other sites
penniless 0 #12 March 18, 2005 QuoteQuotetang alpha = y/x so tan-1 (x/y) = alpha Alpha being the angle in radians. To converts to deg, use 180 deg = pi radians yes. but computer don't know how to speak trig this is what i came up with after my trig lecture with mwgemini. rather elegant if i do say so mesef function relativeCoordsToHeading(x,y) { var radians = Math.atan2(x,y); var degrees = (eval(radians))*(180/Math.PI); if (x>0){degrees = 180 - degrees;} else {degrees = -degrees + 180;} return degrees; } Does it work in your application? There's something a bit funny about your if/else statement, since (180-degrees) is the same as (-degrees +180) Quote Share this post Link to post Share on other sites
Cornholio 0 #13 March 18, 2005 SOHCAHTOA That's your answer. Glad I could help. Butthead: Whoa! Burritos for breakfast! Beavis: Yeah! Yeah! Cool! bellyflier on the dz.com hybrid record jump Quote Share this post Link to post Share on other sites
lummy 4 #14 March 18, 2005 the answer's right here!! I promise not to TP Davis under canopy.. I promise not to TP Davis under canopy.. eat sushi, get smoochieTTK#1 Quote Share this post Link to post Share on other sites
pds 0 #15 March 18, 2005 QuoteDoes it work in your application? There's something a bit funny about your if/else statement, since (180-degrees) is the same as (-degrees +180) ummm, not. you are breaking a fundamental rule of logic. you are assuming, wrongly given the conditional you base your statement on, that the degree is the same in both expressions. works great. try it.... dzDivepool beta edit: it has to do with quadrants as per mwgemini. if x is negative it returns a negative angle. this is not what i want. -(-45 ) + 180 = 225 is what i want. or sumthing. dunno. i fudged around and it works. go figure. cheersnamaste, motherfucker. Quote Share this post Link to post Share on other sites
pds 0 #16 March 18, 2005 Quotethe answer's right here!! i didnt know the question retard!namaste, motherfucker. Quote Share this post Link to post Share on other sites
lummy 4 #17 March 18, 2005 LOL... I've been waiting to use that one..I promise not to TP Davis under canopy.. I promise not to TP Davis under canopy.. eat sushi, get smoochieTTK#1 Quote Share this post Link to post Share on other sites
MWGemini 0 #18 March 19, 2005 Glad I could help. I realized after I signed off that the numbers I gave you for converting the angle based on quadrant location would need to be changed. My math was based on the circle being 0 to 2pi radians, but Javascript returns the value in negative pi to pi radians. Glad I could help. Mike Quote Share this post Link to post Share on other sites