cocos2d计算目的点给定的起点,角度和距离 [英] cocos2d calculate destination point given start point, angle and distance

查看:475
本文介绍了cocos2d计算目的点给定的起点,角度和距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想的快一个。在Cocos2d和xcode中的第二个问题。

Quick one I think. 2d problem in Cocos2d and xcode.

我有

CGPoint currPoint;
float lineLength;
float angle;

现在,我需要找到lineLength从角度角度的currPoint。

Now, I need to find the point that is lineLength away from currPoint at angle Degrees.

试图搜索,但我发现的答案不是我所寻找的。

Tried to search, but the answers i have found aren't quite what I was looking for. Would appreciate anyone pointing out the (I assume) pretty simple math I have overlooked.

推荐答案

从我的头顶:

CGPoint endPoint;
endPoint.x = sinf(CC_DEGREES_TO_RADIANS(angle)) * lineLength;
endPoint.y = cosf(CC_DEGREES_TO_RADIANS(angle)) * lineLength;
endPoint = ccpAdd(currPoint, endPoint);

不确定向量指向的位置,如果它可以旋转90,180或270度。如果是,只需从角度添加/减去该量。

Not sure where the vector points to, if it may be rotated by 90, 180 or 270 degrees. If so, just add/subtract that amount from angle.

这篇关于cocos2d计算目的点给定的起点,角度和距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆