1
我想写一个C程序来旋转矩形内的点。旋转矩形内的几个点
在我的程序中,矩形中心是枢轴点,矩形尺寸是320x480
。假设矩形的顶点之一位于原点,则支点为(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));
}
}
1.这是C++或C?他们是不同的。我们可以看看你的代码吗? (这很可能会回答1) – BoBTFish 2013-02-27 10:53:00
@BoBTFish它是c – 2013-02-27 11:03:36
好的,我删除了'C++'标记。 – BoBTFish 2013-02-27 11:05:50