0
pds

GEO and TRIG whizzzs quick question....

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Quote

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.



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!

Share this post


Link to post
Share on other sites
Quote

Quote

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.



The proper way to say it is:

Can i have another shot of tequila please?



:D
namaste, motherfucker.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote

tang 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.

Share this post


Link to post
Share on other sites
Quote

So you want us to do all the work, is that it???? :P



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.

Share this post


Link to post
Share on other sites
Quote

Quote

tang 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)

Share this post


Link to post
Share on other sites
Quote

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)



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.:P

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.

cheers
namaste, motherfucker.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

0