Posts

Showing posts from April 24, 2011

BEZIER CURVE IN COMPUTER GRAPHICS

#include<dos.h> #include<conio.h> #include<stdio.h> #include<graphics.h> #include<iostream.h> #include<stdlib.h> int gd,gm,maxx,maxy; float X[4][2]; void line(float x2,float y2) { line(X[0][0],X[0][1],x2,y2); X[0][0]=x2; X[0][1]=y2; } void bezier(float xb,float yb,float xc,float yc,float xd,float yd,int n) { float xab,yab,xbc,ybc,xcd,ycd; float xabc,yabc,xbcd,ybcd; float xabcd,yabcd; if(n==0) { line(xb,yb); delay(20); line(xc,yc); delay(20); line(xd,yd); delay(20); } else { xab=(X[0][0]+xb)/2 ; yab=(X[0][1]+yb)/2 ; xbc=(xb+xc)/2 ; ybc=(yb+yc)/2; xcd=(xc+xd)/2 ; ycd=(yc+yd)/2 ; xabc=(xab+xbc)/2; yabc=(yab+ybc)/2 ; xbcd=(xbc+xcd)/2; ybcd=(ybc+ycd)/2; xabcd=(xabc+xbcd)/2; n=n-1; bezier(xab,yab,xabc,yabc,xabcd,yabcd,n); bezier(xbcd,ybcd,xcd,ycd,xd,yd,n); } } void igraph() { detectgraph(&gd,&gm); if(gd<0) { printf("\n \t cannot detect a graphics card!!!"); exit(1); } initgraph(...

PERSPECTIVE PROJECTION

#include<stdio.h> #include<conio.h> #include<graphics.h> void main() { int ch,x[10],y[10],z[10],a,b,c,j,xr[10],yr[10],zr[10]; int gd=DETECT,gm; printf("\n\n perspective projection"); printf("\n\n to enter coordinates\n\n") ; printf("\n else any other value would lead to default value \t:"); scanf("%d",&ch); if(ch==1) { printf("\n follow these steps"); for(int i=0;i<8;i++) scanf("%d",&x[i],&y[i],&z[i]); } else { x[0]=y[0]=z[0]=0; x[1]=80;y[1]=z[1]=0; x[2]=y[2]=80;z[2]=0; x[3]=0;y[3]=80;z[3]=0; x[4]=0;y[4]=z[4]=80; x[5]=y[5]=0;z[5]=80; x[6]=80;y[6]=0;z[6]=80; x[7]=y[7]=z[7]=80; printf("\n default values have been set"); printf("\n\n now enter the projection distance \t"); scanf("%d",&d); for(int i=0;i<8;i++) { xr[i]=(d*x[i]/(d+x[i])); yr[i]=(d*y[i]/(d+x[i])); zr[i]=0; } initgraph(&gd,&gm,""); setcolo...

PARALLEL PROJECTION in COMPUTER GRAPHICS

#include<stdio.h> #include<conio.h> #include<graphics.h> void main() { int ch,x[10],y[10],z[10],a,b,c,j,xr[10],yr[10],zr[10]; int gd=DETECT,gm; printf("\n\n parallel projection"); printf("\n\n to enter coordinates\n\n") ; printf("\n else any other value would lead to default value \t:"); scanf("%d",&ch); if(ch==1) { printf("\n follow these steps"); for(int i=0;i<8;i++) scanf("%d",&x[i],&y[i],&z[i]); } else { x[0]=y[0]=z[0]=0; x[1]=80;y[1]=z[1]=0; x[2]=y[2]=80;z[2]=0; x[3]=0;y[3]=80;z[3]=0; x[4]=0;y[4]=z[4]=80; x[5]=y[5]=0;z[5]=80; x[6]=80;y[6]=0;z[6]=80; x[7]=y[7]=z[7]=80; printf("\n default values have been set"); } printf("\n\n now enter the projection vector \t"); scanf("%d%d%d",&a,&b,&c); for(int i=0;i<8;i++) { xr[i]=x[i]-(a*z[i]/c); yr[i]=y[i]-(b*z[i]/c); zr[i]=0; } initgraph(&gd,&gm,"...

REFLECTION OF A TRIANGLE (COMPUTER GRAPHICS)

#include<stdio.h> #include<conio.h> #include<graphics.h> #include<stdlib.h> void main() { int gd=DETECT,gm; int x1,y1,x2,y2,x3,y3; char a; clrscr(); initgraph(&gd,&gm,""); printf("\n enter the coordinates of triangle"); sacnf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3); line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); line(320,0,320,430); line(0,240,640,240); printf("\n enter the axis of reflection"); scanf("%d",&a); if(a='x'||a='X') { x1=x1; x2=x2; x3=x3; y1=y1+240; y2=y2+240; y3=y3+240; } else if(a='y'||a='Y') { y1=y1; y2=y2; y3=y3; x1+=320; x2+=320; x3+=320; } printf("\n triangle after reflection"); line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); getch(); closegraph(); }

SHEARING OF AN OBJECT

/* SHEARING OF AN OBJECT */ #include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h> #include<process.h> #include<stdlib.h> void main() { int ch,ch1; int gd=DETECT,gm; int n,a[3][3],b[3][10],i,x[10],y[10],c[3][10],j,k,a1,b1; initgraph(&gd,&gm,""); line(320,0,320,480); line(0,240,640,240); printf("enter th eno. of vertices"); scanf("%d",&n); printf("enter the coordinates"); for(i=0;i<n;i++) { scanf("%d",&x[i]); scanf("%d",&y[i]); } for(i=0;i<n;i++) { b[0][i]=x[i]; b[1][i]=y[i]; b[2][i]=1; } for(i=0;i<n-1;i++) { line(b[0][i]+320,b[1][i]+240,b[0][i+1]+320,b[1][i+1]+240); line(b[0][n-1]+320,b[1][n-1]+240,b[0][0]+320,b[1][0]+240); printf("\n 1.about x-axis"); printf("\n 2.about y-axis"); printf("\n 3.about both axis"); scanf("%d",&ch1); a[0][0]=1; a[0][1]=a1; a[0][2]=0...

LONGEST COMMON SUBSEQUENCE for file

#include<iostream.h> #include<conio.h> #include<string.h> #include<stdio.h> #include<time.h> #define max 12 void lcs_length(char[],char[],int,int); void print_lcs(char[max][max],char[],int,int); void main() { char x[10],y[10],ans ; int i,j; clrscr(); clock_t t1,t2; t1=clock(); cout<<"\n Enter the first sequence(less than or equal to 10 characters"; gets(x); i=strlen(x); cout<<"\n enter the second sequence"; gets(y); j=strlen(y); lcs_length(x,y,i,j); t2=clock(); cout<<"the time complexity"<<(t2-t1)/CLK_TCK; getch(); } void lcs_length(char x[10],char y[10],int m,int n) { int i,j; int c[max][max]; char b[max][max]; for(i=0;i<max;i++) for(j=0;j<max;j++) b[i][j]='0'; for(i=1;i<=m;i++) c[i][0]=0; for(j=0;j<=n;j++) c[0][j]=0; for(i=0;i<m;i++) { for(j=0;j<=n;j++) { if(x[i]==y[j]) { c[i+1][j+1]=c[i][j]+1; b[i+1][j+1]='\\'; } else if(c[i][j+1]>=c[i+1][j]) { c[i+1][j+1]=c[i][...

merge sort for practical file

#include<iostream.h> #include<conio.h> #include<time.h> void mergesort(int [],int,int); void merge(int[],int,int,int); void main() { int a[10],p,q,r,i,n; clrscr(); clock_t start,end; cout<<"enter the number of elements"; cin>>n; start=clock(); p=0; r=n-1; cout<<"enter the array"; for(i=0;i<n;i++) { cin>>a[i]; } mergesort(a,p,r); end=clock(); cout<<"the sorted array is"; for(i=0;i<n;i++) { cout<<"\n"<<a[i]; } cout<<""the time complexity is"<<(end-start)/CLK_TCK; getch(); } void mergesort(int a[],int p,int r) { if(p<r) { int q=(p+r)/2; mergesort(a,p,q); mergesort(a,q+1,r) ; merge(a,p,q,r); } } void merge(int a[],int p,int q,int r) { int c[10]; int i=p; int j=q+1; int k=p; while((i<=q)&&(j<=r)) { if(a[i]<a[j]) { c[k] =a[i]; i=i+1; k=k+1; } else { c[k]=a[j]; j=j+1; k=k+1; } } whi...