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

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

问题描述

我想快点.Cocos2d 和 xcode 中的 2d 问题.

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

我有

CGPoint currPoint;
float lineLength;
float angle;

现在,我需要找到 lineLength 与 currPoint 相距角度 Degrees 的点.

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天全站免登陆