gpt4 book ai didi

iphone - 将 CGPoint 沿某个方向移动一定距离...iphone

转载 作者:搜寻专家 更新时间:2023-10-30 20:01:53 25 4
gpt4 key购买 nike

这似乎是一个如此简单的问题,但我一直无法找到答案(而且我不擅长数学)。我正在尝试将 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]);

最佳答案

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

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

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

关于iphone - 将 CGPoint 沿某个方向移动一定距离...iphone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2969181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com