The Cat Sat On An Orange And Had Histerics

Writing games generally involves a fair bit of trigonometry. I never really liked it at school but it turns out I did remember one thing: a little phrase to aid one’s memory of equations for a right-angled triangle. In my current project I need to work out a coordinate position based on an angle and a distance – which relate to the angle and hypotenuse of said triangle. Now I realise this isn’t rocket science, but because I’m so generous I’m gonna share my function for returning the coordinates (from 0,0 origin) to a point at an angle and distance:

CGPoint translateAngleDistance(float angle, float distance)
CGPoint returnVal;
returnVal.x = cos(angle) * distance;
returnVal.y = sin(angle) * distance;
return returnVal;

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>