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

时间:2010-06-03 19:39:44

标签: iphone objective-c trigonometry 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]);

1 个答案:

答案 0 :(得分:6)

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

  

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

不是存储距离和角度,而是通常使用vectors(不需要sin / cos)来完成

相关问题