長方形内の点を回転させるCプログラムを書きたい。
私のプログラムでは、長方形の中心がピボットポイントであり、長方形の寸法は320x480
です。長方形の頂点の1つが原点にあるとすると、ピボットポイントは(160,240)
です。
(px, py)
ここで、ピボットを基準にして長方形内の点を回転させるために(ox, oy)
、次の式を使用しています-
p'x = cos(theta) * (px-ox) - sin(theta) * (py-oy) + ox
p'y = sin(theta) * (px-ox) + cos(theta) * (py-oy) + oy
ただし、ポイントを90度回転させようとすると、すべてのポイントが直線にマッピングされます。
誰かがこの問題を解決できますか?
theta2=90;
theta1=abs(theta2*3.1415926)/180;
if(theta2>0)
{
for(int tc=0;tc<rstruct2->nrows;tc++)
{
rstruct2->xcol[tc]=round((rstruct2->xcol[tc]-160)*cos(theta1)-sin(theta1)*(rstruct2->ycol[tc]-240)+160);
rstruct2->ycol[tc]=round((rstruct2->xcol[tc]-160)*sin(theta1)+cos(theta1)*(rstruct2->ycol[tc]-240)+240);
}
}
else
{
for(int tc=0;tc<rstruct2->nrows;tc++)
{
rstruct2->xcol[tc]=round(160+(rstruct2->xcol[tc]-160)*cos(theta1)+(rstruct2->ycol[tc]-240)*sin(theta1));
rstruct2->ycol[tc]=round(240+(-rstruct2->xcol[tc]-160)*sin(theta1)+(rstruct2->ycol[tc]-240)*cos(theta1));
}
}