用c语言编写图形的变换程序,利用C语言实现二维图形的变换

满意答案

dcebd7a0de6265b6ccae5ead692f1eab.png

csmes

2013.08.27

dcebd7a0de6265b6ccae5ead692f1eab.png

采纳率:41%    等级:13

已帮助:8466人

你先看看吧,思路大概就是这样,不懂的问我。

#include

#include

#include

using namespace std;

struct point

{

float x;

float y;

};

void translation(point*pt, float xp,float yp,int num)//num代表点的个数

{

for(int i=0;i

{

(pt+i)->x+=xp;

(pt+i)->y+=yp;

}

}

void scale(point *pt,float xs,float ys,int num)

{

for(int i=0;i

{

(pt+i)->x*=xs;

(pt+i)->y*=ys;

}

}

void rotation(point *pt,float angle,int num)

{

int 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

{

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;

cout<

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");

cin>>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

printf("%f %f\n",pt[i].x,pt[i].y);

}

12分享举报

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值