Question

I found the equations to convert an X,Y into radius and angle:

x = r*Cos(Q)
y = r*Sin(Q)

r= sqrt(x*x + y*y)
Q = tan^-1(y/x)

My problem is that I dont remember what is the syntax for the tan^-1 in objective C. I do not want to get things wrong.

This got me thinking: Why build this from scratch? Is there a built-in way to convert a given CGPoint in Objective C from polar to rectangular coordinates? Maybe there's some CAAnimation class that can help me with this?

Était-ce utile?

La solution

To get the angle use:

Q = atan2( y, x );

This function will work out the quadrant to give the correct sign of the angle.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top