Moving CGPoint a certain distance along a specific heading ... iphone

it seems like such a simple problem, but I could not find the answer (and I do not know how to math). I am trying to move a UIView to a new CGPoint X distance in a specific area. What is the formula for determining the new coordinates?

(I don't want this to be animated, just an instant move)

sort of:

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]);
+3
source share
1 answer

If p is your point, D is the distance, and θ is the angle of rotation along the X axis,

p new.x = p old.x + D * cos (θ)
p new.y = p old.y + D * sin (θ)

, , ( sin/cos)

+6

Source: https://habr.com/ru/post/1748409/


All Articles