• get heading from 2D coordinates.
    10 replies, posted
I have a bit of a problem, I need to turn X and Y coordinates into an angle fron the centre of a shape. I have a 10 by 10 grid, and I am detecting presses, I need to work out the angle those presses are at relative to the center of the grid. [IMG]http://i205.photobucket.com/albums/bb139/chrishind10/diagram-1.jpg[/IMG] So basicly I want to convert X and Y coordinates into a heading. A formula to do this would be brilliant (sorry for the bad diagram and possibly bad explination)
like a local vector 2 get to it [editline]12:52PM[/editline] ?
Yes, exactly! [editline]12:54PM[/editline] I just need an algebra formula, that would be perfect.
If I remember correctly then you can use atan to get the angular heading from a set of (normalized) coordinates, I think it was something like [code]double ang = atan2(x, -y);[/code]
in 3d angles , i would do this local header = destination - Player.Getpos() or somthing like that , its one way or the other , it works in wire , i know that
use sin, cos, tan ([url]http://en.wikipedia.org/wiki/Trigonometric_functions[/url]) [url]http://www.cplusplus.com/reference/clibrary/cmath/atan/[/url] [cpp] double ang = atan(Y/X); [/cpp] Yea its also possible to use atan2 its the same thing [cpp]sqrt(pow(X,2) + pow(Y,2))[/cpp] The lenght [cpp]ang * 180 / PI[/cpp] converts rad to deg Everything should be done using normalized vectors.
[QUOTE=ColdFusion;25037465]Yea its also possible to use atan2 its the same thing[/QUOTE] Actually you want to use atan2 and not atan, because atan doesn't give the correct angle for each quadrant.
[QUOTE=ColdFusion;25037465]Yea its also possible to use atan2 its the same thing.[/QUOTE] wrooooooooooooooooooooooong. [IMG]http://imgur.com/cLRzQ.png[/IMG]
[img]http://www.fortfn.co.uk/images/angle1.png[/img] Classic GCSE math question. [editline]09:33PM[/editline] Assuming x is right, and y is up.
[QUOTE=ace13;25037341]If I remember correctly then you can use atan to get the angular heading from a set of (normalized) coordinates, I think it was something like [code]double ang = atan2(x, -y);[/code][/QUOTE] I'm pretty sure the first parameter for atan2 is usually y.
Thanks for the help, I have my C in Maths (Not my strong point), so I dropped it and moved onto Graphics...
Sorry, you need to Log In to post a reply to this thread.