plz help for my project

My project is on IMAGE SCALING AND ROTATION..following code is error f

Page 1 of 1

1 Replies - 684 Views - Last Post: 03 January 2009 - 02:40 PM Rate Topic: -----

#1 pradeep_1427   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-January 09

plz help for my project

Post icon  Posted 03 January 2009 - 07:02 AM

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
#include<stdlib.h>
void bresenline(int,int,int,int,int);
int sign(int,int);
void multi(int x[1][3],int tr[3][3],int);
void multil(int x[1][3],double tr[3][3],int);
void display(int a[10][2],int);
int obmat[10][2],n;
void main()
{
int xc,yc,i,j,tx,ty;
double Q;
float sx,sy;
int a[10][2],sc[3][3],tr[3][3],x[1][3];
double r0[3][3];
int gd=DETECT ,gm,ch;
initgraph(&gd,&gm,"c:\\tc\\bgi");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
if(i==j)
tr[i][j]=r0[i][j]=sc[i][j]=1;
else
tr[i][j]=r0[i][j]=sc[i][j]=0;
}
printf("enter the number of edges\n");
scanf("%d",&n);
if(n<3)
{
printf("\n cannot draw polygon");
exit(0);
}
printf("enter the edges\n");
for(i=0;i<n;i++)
scanf("%d%d ",&a[i][0],&a[i][1]);
bresenline(0,getmaxx(),getmaxy()/2,getmaxy()/2,RED);
bresenline(getmaxx()/2,getmaxx()/2,0,getmaxy(),RED);
display(a,BLUE);
getch();
while(1)
{
clrscr();
cleardevice();
printf("\n 1.Translate \n 2.scaling \n 3.Rotate\n 4.exit\n enter your choice\n");
scanf("%d",&ch);
if(ch==4)
exit(0);
bresenline(0,getmaxx(),getmaxy()/2,getmaxy()/2,RED);
bresenline(getmaxx()/2,getmaxx()/2,0,getmaxy(),RED);
display(a,BLUE);
switch(ch)
{
case 1: printf("enter tx and ty values \n");
scanf("%d%d",&tx,&ty);
tr[2][0]=tx;
tr[2][1]=ty;
for(i=0;i<n;i++)
{
x[0][0]=a[i][0];
x[0][1]=a[i][1];
x[0][2]=1;
multi(x,tr,i);
}
break;
case 2:
printf("enter sx,and sy values \n");
scanf("%f%f",&sx,&sy);
sc[0][0]=sx;
sc[1][1]=sy;
for(i=0;i<n;i++)
{
x[0][0]=a[i][0];
x[0][1]=a[i][1];
x[0][2]=1;
multi(x,sc,i);
}
break;
case 3:
printf("enter the angle  of rotation \n");
scanf("%f",&Q);
Q=(Q*3.1428)/180;
printf("enter the point about which  the polygon is to be rotated\n");
scanf("%d%d",&xc,&yc);
r0[0][0]=cos(Q);
r0[0][1]=sin(Q);
r0[0][2]=0;
r0[1][0]=-sin(Q);
r0[1][1]=cos(Q);
r0[1][2]=0;
r0[2][0]=yc*sin(Q)-xc*cos(Q)+xc;
r0[2][1]=yc-yc*cos(Q)-xc*sin(Q);
r0[2][2]=1;
for(i=0;i<n;i++)
{
x[0][0]=a[i][0];
x[0][1]=a[i][1];
x[0][2]=1;
multil(x,r0,i);
}
break;
}
display(a,BLACK);
bresenline(0,getmaxx(),getmaxy()/2,getmaxy()/2,RED);
bresenline(getmaxx()/2,getmaxx()/2,0,getmaxy(),RED);
display(obmat,GREEN);
getch();
}
}
void bresenline(int xa,int xb,int ya,int yb,int color)
{
int dx,dy,xe,p,x,y,ch,s1,s2,temp,i;
dx=abs(xb-xa);
dy=abs(yb-ya);
s1=sign(xa,xb);
s2=sign(ya,yb);
if(dy>dx)
{
temp=dy;
dy=dx;
dx=temp;
ch=1;
}
else
ch=0;
p=2*dy-dx;
x=xa;
y=ya;
putpixel(x,y,color);
for(i=0;i<dx;i++)
{
putpixel(x,y,color);
delay(1);
while(p>0)
{
if(ch==1)
x=x+s1;
else
y=y+s2;
p=p-2*dx;
}
if(ch==1)
y+=s2;
else
x+=s1;
p+=2*dy;
}
}
int sign(int xa,int xb)
{
if((xb-xa)<0)
return (-1);
else
if(xa==xb)
return 0;
else
return 1;
}
void display(int a[10][2],int color)
{
int i;
for(i=0;i<n-1;i++)
bresenline(a[i][0]+getmaxx()/2,a[i+1][0]+getmaxx()/2,getmaxy()/2-a[i][1],getmaxy()/2-a[i+1][1],color);
bresenline(a[0][0]+getmaxx()/2,a[n-1][0]+getmaxx()/2,getmaxy()/2-a[0][1],getmaxy()/2-a[n-1][1],color);
}
void multi(int z[1][3],int t[3][3],int l)
{
int i,j,k;
int temp[1][3];
for(i=0;i<1;i++)
for(j=0;j<3;j++)
{
temp[i][j]=0;
for(k=0;k<3;k++)
temp[i][j]+=z[i][k]*t[k][j];
}
obmat[l][0]=temp[0][0];
obmat[l][1]=temp[0][1];
}
void multil(int x[1][3],double tr[3][3],int l)
{
int i,j,k;
double temp[1][3];
for(i=0;i<1;i++)
for(j=0;j<3;j++)
{
temp[i][j]=0;
for(k=0;k<3;k++)
temp[i][j]+=x[i][k]*tr[k][j];
}
printf("translate\n");
printf("%f%f",temp[0][0],temp[0][1]);
obmat[l][0]=ceil(round(temp[0][0]));
obmat[l][1]=ceil(round(temp[0][1]));
}
int round(double x)
{
if(x<x+1/2)
return (x+1);
else
return x;
}


Is This A Good Question/Topic? 0
  • +

Replies To: plz help for my project

#2 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1433
  • View blog
  • Posts: 11,006
  • Joined: 06-February 08

Re: plz help for my project

Posted 03 January 2009 - 02:40 PM

Why did you quote yourself? Wasn't really necessary~

What's wrong with this code?

Please post any error messages that you receive.
Does it compile?
Does it screw up at runtime?

Help us to help you. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1