您的位置:首页 > 其它

getAngle, getNewPoint

2014-02-14 17:20 351 查看
//求两个点的角度
float getAngle(CCPoint &a, CCPoint &b)
{
float x = b.x-a.x;
float y = b.y-a.y;
float hypotenuse = sqrt(pow(x, 2)+pow(y, 2));
//斜边长度
float cos = x/hypotenuse;
float radian = acos(cos);

//求出弧度
float angle = 180/(3.14159265359/radian);
if (y<0) {
angle = 180+angle;
} else if ((y == 0) && (x<0)) {
angle = 180;
}
return angle;
}
//获得点a到点b方向的fDistance像素的位置
CCPoint getNewPoint(CCPoint &a, CCPoint &b, float fDistance)
{
CCPoint c;
//(b.y-a.y)/(c.y-a.y)=(ccpDistance(a,b)/fDistance);
//(b.y-a.y)/(ccpDistance(a,b)/fDistance) = (c.y-a.y)
c.x = (b.x-a.x)/(ccpDistance(a,b)/fDistance) + a.x;
c.y = (b.y-a.y)/(ccpDistance(a,b)/fDistance) + a.y;
return c;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: