这似乎是一个简单的问题,但我一直无法找到答案(而且我不擅长数学)。我正在尝试将 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]);
If p是您的点,D 是距离,θ 是相对于 X 轴的航向角,
pnew.x = pold.x + D * cos(θ)
pnew.y = pold.y + D * sin(θ)
不过,这通常不是存储距离和角度,而是使用vectors http://www.ux1.eiu.edu/~cfadd/1150/03Vct2D/Vectrs.html(这消除了对 sin/cos 的需要)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)