views:

138

answers:

1

this seems like such a simple problem but I have been unable to find an answer (and im no good at math). I am trying to move a UIView to a new CGPoint X distance away along a certain heading. What is the formula for determining the new coordinates?

(i do no want this to be animated, just an instantaneous move)

something like:

x = 100; (current x value)
y = 150; (current y value)
d = 25; (distance to move the point)
h = 90; (west)

\\\ insert formula to determine new x,y coords

self.car.center =  (CGPointMake ([newX],[newY]);
+1  A: 

If p is your point, D is the distance, and θ is the heading-angle from the X-axis,

pnew.x = pold.x + D * cos(θ)
pnew.y = pold.y + D * sin(θ)

Rather than storing distances and angles, though, this is usually done using vectors (which removes the need for the sin/cos)

BlueRaja - Danny Pflughoeft
Additionally, don't forget to convert the angle to radians.
Eiko