您的位置:首页 > 其它

常用游戏数学算法总结

2010-12-09 18:57 218 查看
已知圆点坐标,圆上一点坐标,求圆上该点在旋转x角度后的坐标?

用极坐标做 x=p.cosA y=p.sinA p等于圆的半径
变换后的坐标就是 x,=p.cos(A+x) y=p.sin(A+x)

//随便定个圆心点坐标
float centerX = 100;
float centerY = 100;
float PI = 3.14159;

//已知点坐标
float pointX = 200;
float pointY = 200;
//旋转角度
float angle = 10*(-1);
//求出半径
float px = pointX - centerX;
float py = pointY - centerY;
float r = sqrt(px*px + py*py);
//求出弧度
float l = (angle * PI)/180;

//得出新坐标
float newX = (pointX - centerX) * cos(l) + (pointY - centerY) * sin(l) + centerX;
float newY = -(pointX - centerX) * sin(l) + (pointY - centerY) * cos(l) + centerY;

cout<<"newX:"<<newX<<"newY:"<<newY<<endl;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: