常用遊戲數學算法總結

已知圓點座標,圓上一點座標,求圓上該點在旋轉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;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章