沿着某个标题移动CGPoint一定距离... iphone

Bro*_*die 3 iphone trigonometry objective-c heading cgpoint

这似乎是一个简单的问题,但我一直无法找到答案(我不擅长数学).我试图沿着某个标题将UIView移动到新的CGPoint X距离.确定新坐标的公式是什么?

(我不希望这个动画,只是瞬间移动)

就像是:

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]);
Run Code Online (Sandbox Code Playgroud)

Blu*_*eft 6

如果p是你的点,D是距离,θ是从X轴的航向角,

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

但是,不是存储距离和角度,而是通常使用向量来完成(这消除了对sin/cos的需要)