找出错误并修改!
先说说题目:二维图形由点或直线段组成,直线段可由其端点坐标定义,二维图形的几何变换实际是对点或对直线段端点在变换矩阵的作用下来实现的。设 是原来的点, 是变换之后的点,则几种典型的变换如下:
(a) 平移变换(translation):BM
(b) 比例变换(scale):
(c) 旋转变换(rotation):
下面是代码:
#include<stdio.h>
#include<math.h>
struct point
{
float x;
float y;
};
void translation(point*pt, float xp,float yp,int num)//num代表点的个数
{
for(int i=0;i<num;i++)
{
(pt+i)->x+=xp;
(pt+i)->y+=yp;
}
}
void scale(point *pt,float xs,float ys,int num)
{
for(int i=0;i<num;i++)
{
(pt+i)->x*=xs;
(pt+i)->y*=ys;
}
}
void rotation(point *pt,float angle,int num)
{
float a[2][2];
angle=angle/180*3.141592657;
a[0][0]=cos(angle);
a[0][1]=-sin(angle);
a[1][0]=sin(angle);
a[1][1]=cos(angle);
point temp;
for(int i=0;i<num;i++)
{
temp.x=(pt+i)->x;
temp.y=(pt+i)->y;
(pt+i)->x=temp.x*a[0][0]+a[0][1]*temp.y;
(pt+i)->y=temp.x*a[1][0]+a[1][1]*temp.y;
}
}
int main()
{
int i=0,N,mode,angle,xp,yp,xk,yk,num;
printf("please input the number of point\n ";
scanf("%d",&N);
num=N;
point pt[10];
while(N--)
{
printf("please input points(x,y):\n");
scanf("%f%f",&pt[i].x,&pt[i].y);
i++;
}
printf("please input motions\n");
printf("0 stand for translation:\n");
printf("1 stand for scale:\n");
printf("2 stand for rotation:\n");
scanf("%d",&mode);
switch(mode)
{
case 0:
printf("please input the translation in x and y direction respectivly:\n");
scanf("%f%f",&xp,&yp);
translation(pt, xp,yp,num);
break;
case 1:
printf("please input the scale in x and y direction respectivly:\n");
scanf("%f%f",&xk,&yk);
scale(pt, xk,yk,num);
break;
case 2:
printf("please input the angle:\n");
scanf("%f",&angle);
rotation(pt, angle,num);
break;
}
printf("after translatiton or scale or rotation:\n");
for(int i=0;i<num;i++)
printf("%f %f\n",pt[i].x,pt[i].y);
}
但是就是不能按照题目说的运行,还有错误,各位大神看看并改改!!!