0% found this document useful (0 votes)
44 views

Assignment4 CG Rollno18

The document contains the code for implementing 3D rotation, translation and scaling using matrix transformations in C++. It includes functions for identity matrix, matrix multiplication, and rotating, translating or scaling point coordinates by pre-multiplying the coordinate matrix with appropriate transformation matrices. The code takes input coordinates, transformation parameters like angles or offsets, performs the transformation and outputs the transformed coordinates. Menu-based programs are provided to implement interactive 3D rotations, translations and scaling along different axes.

Uploaded by

Shirin Menon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Assignment4 CG Rollno18

The document contains the code for implementing 3D rotation, translation and scaling using matrix transformations in C++. It includes functions for identity matrix, matrix multiplication, and rotating, translating or scaling point coordinates by pre-multiplying the coordinate matrix with appropriate transformation matrices. The code takes input coordinates, transformation parameters like angles or offsets, performs the transformation and outputs the transformed coordinates. Menu-based programs are provided to implement interactive 3D rotations, translations and scaling along different axes.

Uploaded by

Shirin Menon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

22. Write a C++ program to plot an ellipse using the Mid-Point Ellipse algorithm

CODE:

#include<stdio.h>

#include<dos.h>

#include<conio.h>

#include<graphics.h>

#include<iostream.h>

void main(){

long x,y,x_center,y_center;

long a_sqr,b_sqr, fx,fy, d,a,b,tmp1,tmp2;

int g_driver=DETECT,g_mode;

clrscr();

initgraph(&g_driver,&g_mode,"C:\\TURBOC3\\BGI");

cout<<"\n\n Enter coordinate x and y ";

cin>>x_center>>y_center;

cout<<"\n Now enter constants a and b ";

cin>>a>>b;

x=0;

y=b;

a_sqr=a*a;

b_sqr=b*b;

fx=2*b_sqr*x;

fy=2*a_sqr*y;

d=b_sqr-(a_sqr*b)+(a_sqr*0.25);

do

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

putpixel(x_center+x,y_center+y,1);

putpixel(x_center-x,y_center-y,1);

putpixel(x_center+x,y_center-y,1);

putpixel(x_center-x,y_center+y,1);

if(d<0)

d=d+fx+b_sqr;

else

y=y-1;

d=d+fx+-fy+b_sqr;

fy=fy-(2*a_sqr);

x=x+1;

fx=fx+(2*b_sqr);

delay(10);

while(fx<fy);

tmp1=(x+0.5)*(x+0.5);

tmp2=(y-1)*(y-1);

d=b_sqr*tmp1+a_sqr*tmp2-(a_sqr*b_sqr);

do

putpixel(x_center+x,y_center+y,1);

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

putpixel(x_center-x,y_center-y,1);

putpixel(x_center+x,y_center-y,1);

putpixel(x_center-x,y_center+y,1);

if(d>=0)

d=d-fy+a_sqr;

else

x=x+1;

d=d+fx-fy+a_sqr;

fx=fx+(2*b_sqr);

y=y-1;

fy=fy-(2*a_sqr);

while(y>0);

getch();

closegraph();

Output:

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

23. Write a program to implement 3-dimensional Scaling.

CODE:

#include<conio.h>

#include<iostream.h>

#include<graphics.h>

#include<math.h>

//identity matrix

void identity(int im[3][3]){

for(int i=0; i<3; i++)

for(int j=0; j<3; j++){

if(i==j)

im[i][j]=1;

else

im[i][j]=0;} }

//matrix multiplicaiton

void matmu(int m1[50][3], int m2[3][3], int m3[50][3], int n){

for(int i=0; i<n; i++)

for(int j=0; j<3; j++){

m3[i][j]=0;

for(int k=0; k<3; k++)

m3[i][j]+= m1[i][k]*m2[k][j];

//scale

void scale(int arr1[50][3], int arr3[50][3], int sx, int sy, int sz, int n){

int arr2[3][3];

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

identity(arr2);

arr2[0][0]=sx;

arr2[1][1]=sy;

arr2[2][2]=sz;

matmu(arr1,arr2,arr3,n);

void main(){

clrscr();

int c, n, gdriver = DETECT, gmode, sx, sy, sz,coords[50][3],tcoords[50][3];

//coords input

initgraph(&gdriver,&gmode,"C:\\TurboC3\\BGI");

cout<<"Enter no.of lines:\n";

cin>>n;

for(int i=0; i<n*2; i+=2){

cout<<"Enter coords for line(x1,y1,z1,x2,y2,z2) :\n";


cin>>coords[i][0]>>coords[i][1]>>coords[i][2]>>coords[i+1][0]>>coords[i+1][1]>>coords[i+1][
2];

//divide screen

line(320,0,320,479);

line(0,240,639,240);

//rotation input

cout<<"Enter scaling factor(sx, sy, sz):";

cin>>sx>>sy>>sz;

//transformation

scale(coords,tcoords, sx, sy, sz,n*2);

cout<<"Scaled coords:\n";

for(i=0; i<n*2; i+=2)

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

cout<<tcoords[i][0]<<" "<<tcoords[i][1]<<" "<<tcoords[i][2]<<" "<<tcoords[i+1][0]<<"


"<<tcoords[i+1][1]<<" "<<tcoords[i+1][2]<<endl;

getch();

OUTPUT:

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

24. Write a program to implement 3-dimensional Translation

CODE:

#include<conio.h>

#include<iostream.h>

#include<graphics.h>

#include<math.h>

//rounding

int round(int val){

int incr=1,sc=1;

if(val<0){

incr=-1;sc=-1;

if((val*sc)-((int)(val*sc))>=0.5)

return ((int)val+incr);

else return ((int)val);

//identity matrix

void identity(int im[4][4]){

for(int i=0; i<4; i++)

for(int j=0; j<4; j++){

if(i==j)

im[i][j]=1;

else

im[i][j]=0;

//matrix multiplicaiton

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

void matmu(int m1[50][4], int m2[4][4], int m3[50][4], int n){

for(int i=0; i<n; i++)

for(int j=0; j<4; j++){

m3[i][j]=0;

for(int k=0; k<4; k++)

m3[i][j]+= m1[i][k]*m2[k][j];

//rotation

void rotate(int arr1[50][4], int arr3[50][4], int tx, int ty, int tz, int n){

int arr2[4][4];

identity(arr2);

arr2[3][0]=tx;

arr2[3][1]=ty;

arr2[3][2]=tz;

matmu(arr1,arr2,arr3,n);

void main(){

clrscr();

int c, n, gdriver = DETECT, gmode, tx, ty, tz,coords[50][4],tcoords[50][4];

//coords input

initgraph(&gdriver,&gmode,"C:\\TurboC3\\BGI");

cout<<"Enter no.of lines:\n";

cin>>n;

for(int i=0; i<n*2; i+=2){

cout<<"Enter coords for line(x1,y1,z1,x2,y2,z2) :\n";

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

cin>>coords[i][0]>>coords[i][1]>>coords[i][2]>>coords[i+1][0]>>coords[i+1][1]>>coords[i+1][
2];

coords[i][3]=1;

coords[i+1][3]=1;

//divide screen

line(320,0,320,479);

line(0,240,639,240);

//rotation input

cout<<"Enter translation factor(tx, ty, tz):";

cin>>tx>>ty>>tz;

//transformation

rotate(coords,tcoords, tx, ty, tz,n*2);

cout<<"Translated coords:\n";

for(i=0; i<n*2; i+=2)

cout<<round(tcoords[i][0])<<" "<<round(tcoords[i][1])<<"
"<<round(tcoords[i][2])<<" "<<round(tcoords[i+1][0])<<" "<<round(tcoords[i+1][1])<<"
"<<round(tcoords[i+1][2])<<endl;

getch();

OUTPUT:

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

25. Write a menu based program to implement 3-dimensional Rotation (X Axis, Y Axis and Z Axis).

CODE:

#include<conio.h>

#include<iostream.h>

#include<graphics.h>

#include<math.h>

//rounding

int round(float val){

int incr=1,sc=1;

if(val<0){

incr=-1;sc=-1;

if((val*sc)-((int)(val*sc))>=0.5)

return ((int)val+incr);

else return ((int)val);

//identity matrix

void identity(float im[4][4]){

for(int i=0; i<4; i++)

for(int j=0; j<4; j++){

if(i==j)

im[i][j]=1;

else

im[i][j]=0;

//matrix multiplicaiton

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

void matmu(float m1[50][4], float m2[4][4], float m3[50][4], int n){

for(int i=0; i<n; i++)

for(int j=0; j<4; j++){

m3[i][j]=0;

for(int k=0; k<4; k++)

m3[i][j]+= m1[i][k]*m2[k][j];

//rotation

void rotate(float arr1[50][4], float arr3[50][4], float t, int c, int n){

float arr2[4][4];

identity(arr2);

if(c==1){

arr2[1][1]=cos(t);

arr2[1][2]=sin(t);

arr2[2][1]=-sin(t);

arr2[2][2]=cos(t);

if(c==2){

arr2[0][0]=cos(t);

arr2[0][2]=-sin(t);

arr2[2][0]=sin(t);

arr2[2][2]=cos(t);

if(c==3){

arr2[0][0]=cos(t);

arr2[0][1]=sin(t);

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

arr2[1][0]=-sin(t);

arr2[1][1]=cos(t);

matmu(arr1,arr2,arr3,n);

void main()

clrscr();

int c, n, gdriver = DETECT, gmode;

float t,coords[50][4],tcoords[50][4];

//coords input

initgraph(&gdriver,&gmode,"C:\\TurboC3\\BGI");

cout<<"Enter no.of lines:\n";

cin>>n;

for(int i=0; i<n*2; i+=2){

cout<<"Enter coords for line(x1,y1,z1,x2,y2,z2) :\n";

cin>>coords[i][0]>>coords[i][1]>>coords[i][2]>>coords[i+1][0]>>coords[i+1][1]>>coords[i+1][
2];

coords[i][3]=1;

coords[i+1][3]=1;

//divide screen

line(320,0,320,479);

line(0,240,639,240);

//rotation input

cout<<"Enter angle of rotation(0-360):";

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

cin>>t;

t=t*3.14/180;

cout<<"1.Around X-axis\n2.Around Y-axis\n3.Around Z-axis\n";

cin>>c;

//transformation

rotate(coords,tcoords,t,c,n*2);

cout<<"Rotated coords:\n";

for(i=0; i<n*2; i+=2)

cout<<round(tcoords[i][0])<<" "<<round(tcoords[i][1])<<"
"<<round(tcoords[i][2])<<" "<<round(tcoords[i+1][0])<<" "<<round(tcoords[i+1][1])<<"
"<<round(tcoords[i+1][2])<<endl;

getch();

OUTPUT:

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

26. Write a program to implement line clipping using Cohen Sutherland algorithm.

CODE:

//Cohen Sutherland

#include<stdio.h>

#include<graphics.h>

#include<conio.h>

#include<iostream.h>

typedef unsigned int outcode;

enum { TOP=0x1, BOTTOM=0x2, RIGHT=0x4, LEFT=0x8 };

//int calcode(float,float,float,float,float,float);

//float x0,y0,x1,y1,xwmin,ywmin,xwmax,ywmax;

int calcode (float x,float y,float xwmin,float ywmin,float xwmax,float ywmax)

int code =0;

if(y> ywmax)

code |=TOP;

else if( y<ywmin)

code |= BOTTOM;

else if(x > xwmax)

code |= RIGHT;

else if ( x< xwmin)

code |= LEFT;

return(code);

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

void lineclip(float x0,float y0,float x1,float y1,float xwmin,float ywmin,float xwmax,float ywmax )

int gd,gm;

outcode code0,code1,codeout;

int accept = 0, done=0;

code0 = calcode(x0,y0,xwmin,ywmin,xwmax,ywmax);

code1 = calcode(x1,y1,xwmin,ywmin,xwmax,ywmax);

do{

if(!(code0 | code1))

accept =1 ; done =1;

else

if(code0 & code1) done = 1;

else

float x,y;

codeout = code0 ? code0 : code1;

if(codeout & TOP)

x = x0 + (x1-x0)*(ywmax-y0)/(y1-y0);

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

y = ywmax;

else

if( codeout & BOTTOM)

x = x0 + (x1-x0)*(ywmin-y0)/(y1-y0);

y = ywmin;

else

if ( codeout & RIGHT)

y = y0+(y1-y0)*(xwmax-x0)/(x1-x0);

x = xwmax;

else

y = y0 + (y1-y0)*(xwmin-x0)/(x1-x0);

x = xwmin;

if( codeout == code0)

x0 = x; y0 = y;

code0=calcode(x0,y0,xwmin,ywmin,xwmax,ywmax);

else

x1 = x; y1 = y;

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

code1 =
calcode(x1,y1,xwmin,ywmin,xwmax,ywmax);

} while( done == 0);

rectangle(xwmin,ywmin,xwmax,ywmax);

setcolor(YELLOW);

if(accept) line(x0,y0,x1,y1);

getch();

void main()

float x2,y2,x1,y1,xwmin,ywmin,xwmax,ywmax;

int gd=DETECT,gm;

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

cout<<"\n\n\tEnter the co-ordinates of Line :";

cout<<"\n\n\t X1 Y1 : ";

cin>>x1>>y1;

cout<<"\n\n\t X2 Y2 : ";

cin>>x2>>y2;

cout<<"\n\tEnter the co_ordinates of window :\n ";

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

cout<<"\n\txwmin , ywmin : ";

cin>>xwmin>>ywmin;

cout<<"\n\txwmax , ywmax : ";

cin>>xwmax>>ywmax;

cleardevice();

line(x1,y1,x2,y2);

rectangle(xwmin,ywmin,xwmax,ywmax);

getch();

cleardevice();

lineclip(x1,y1,x2,y2,xwmin,ywmin,xwmax,ywmax );

getch();

closegraph();

OUTPUT:

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

27. Write a program to implement line clipping using Mid-point subdivision algorithm.

CODE:

//Midpoint Subdivision

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

#include<dos.h>

#include<math.h>

#include<graphics.h>

/* Defining structure for end point of line */

typedef struct coordinate

int x,y;

char code[4];

}PT;

void drawwindow();

void midsub(PT p1,PT p2);

void drawline (PT p1,PT p2,int cl);

PT setcode(PT p);

int visibility (PT p1,PT p2);

PT resetendpt (PT p1,PT p2);

void main()

int gd=DETECT, gm,v;

PT p1,p2,ptemp;

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

cleardevice();

printf("\nENTER END-POINT 1 (x,y): ");

scanf("%d %d",&p1.x,&p1.y);

printf("\nENTER END-POINT 2 (x,y): ");

scanf("%d %d",&p2.x,&p2.y);

cleardevice();

drawwindow();

getch();

drawline(p1,p2,15);

getch();

cleardevice();

drawwindow();

midsub(p1,p2);

getch();

closegraph();

void midsub(PT p1,PT p2)

PT mid;

int v;

p1=setcode(p1);

p2=setcode(p2);

v=visibility(p1,p2);

switch(v)

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

case 0: /* Line conpletely visible */

drawline(p1,p2,15);

break;

case 1: /* Line completely invisible */

break;

case 2: /* line partly visible */

mid.x = p1.x + (p2.x-p1.x)/2;

mid.y = p1.y + (p2.y-p1.y)/2;

midsub(p1,mid);

mid.x = mid.x+1;

mid.y = mid.y+1;

midsub(mid,p2);

break;

/* Function to draw window */

void drawwindow()

setcolor(RED);

rectangle(150,100,450,400);

/* Function to draw line between two points*/

void drawline (PT p1,PT p2,int cl)

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

setcolor(cl);

line(p1.x,p1.y,p2.x,p2.y);

/* Function to set code of the coordinates*/

PT setcode(PT p)

PT ptemp;

if(p.y<=100)

ptemp.code[0]='1'; /* TOP */

else

ptemp.code[0]='0';

if(p.y>=400)

ptemp.code[1]='1'; /* BOTTOM */

else

ptemp.code[1]='0';

if (p.x>=450)

ptemp.code[2]='1'; /* RIGHT */

else

ptemp.code[2]='0';

if (p.x<=150) /* LEFT */

ptemp.code[3]='1';

else

ptemp.code[3]='0';

ptemp.x=p.x;

ptemp.y=p.y;

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

return(ptemp);

/* Function to determine visibility of line*/

int visibility (PT p1,PT p2)

int i,flag=0;

for(i=0;i<4;i++)

if((p1.code[i]!='0')||(p2.code[i]!='0'))

flag=1;

if(flag==0)

return(0);

for(i=0;i<4;i++)

if((p1.code[i]==p2.code[i]) &&(p1.code[i]=='1'))

flag=0;

if(flag==0)

return(1);

return(2);

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

OUTPUT:

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

28. Write a program to implement line clipping using Laing-Barsky algorithm.

CODE:

#include<iostream.h>

#include<graphics.h>

#include<math.h>

#include<dos.h>

#include<conio.h>

void main()

int i,gd=DETECT,gm;

int x1,y1,x2,y2,xmin,xmax,ymin,ymax,xx1,xx2,yy1,yy2,dx,dy;

float t1,t2,p[4],q[4],temp;

clrscr();

//x1=120;

//y1=120;

//x2=300;

//y2=300;

//xmin=100;

//ymin=100;

//xmax=250;

//ymax=250;

cout<<"Enter xmin and ymin: ";

cin>>xmin>>ymin;

cout<<"\nEnter xmax and ymax: ";

cin>>xmax>>ymax;

cout<<"\nEnter x1 and y1:";

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

cin>>x1>>y1;

cout<<"\nEnter x2 and y2:";

cin>>x2>>y2;

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

rectangle(xmin,ymin,xmax,ymax);

dx=x2-x1;

dy=y2-y1;

p[0]=-dx;

p[1]=dx;

p[2]=-dy;

p[3]=dy;

q[0]=x1-xmin;

q[1]=xmax-x1;

q[2]=y1-ymin;

q[3]=ymax-y1;

for(i=0;i<4;i++)

if(p[i]==0)

cout<<"line is parallel to one of the clipping boundary";

if(q[i]>=0)

if(i<2)

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

if(y1<ymin)

y1=ymin;

if(y2>ymax)

y2=ymax;

line(x1,y1,x2,y2);

if(i>1)

if(x1<xmin)

x1=xmin;

if(x2>xmax)

x2=xmax;

line(x1,y1,x2,y2);

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

t1=0;

t2=1;

for(i=0;i<4;i++)

temp=q[i]/p[i];

if(p[i]<0)

if(t1<=temp)

t1=temp;

else

if(t2>temp)

t2=temp;

if(t1<t2)

xx1 = x1 + t1 * p[1];

xx2 = x1 + t2 * p[1];

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

yy1 = y1 + t1 * p[3];

yy2 = y1 + t2 * p[3];

line(xx1,yy1,xx2,yy2);

delay(500);

getch();

closegraph();

OUTPUT:

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

29. Write a program to implement polygon clipping using Sutherland-Hodgeman algorithm.

CODE:

#include<iostream.h>

#include<conio.h>

#include<graphics.h>

#include<dos.h>

#include<stdlib.h>

#include<stdio.h>

void main()

int gm,gd,n,c=0,y,xmin,ymin,xmax,ymax,poly[50];

gd=DETECT;

initgraph(&gd,&gm,"C:\\TurboC3\\BGI");

cout<<"Enter xmin and ymin: ";

cin>>xmin>>ymin;

cout<<"Enter xmax and ymax: ";

cin>>xmax>>ymax;

cout<<"Enter no.of vertices:\n";

cin>>n;

for(int i=0; i<n; i++){

cout<<"Enter coords for vertex "<<i+1<<" : ";

cin>>poly[c++]>>poly[c++];

poly[c++]=poly[0];

poly[c++]=poly[1];

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

c=0;

for(i=0; i<n; i++){

line(poly[c++],poly[c++],poly[c++],poly[c++]);

c-=2;

rectangle(xmin,ymin,xmax,ymax);

//Code for right clip

setviewport(xmax+1,0,639,479,1);

getch();

clearviewport();

//Code for bottom clip

setviewport(xmin,ymax+1,xmax,479,1);

getch();

clearviewport();

//Code for left clip

setviewport(0,0,xmin-1,479,1);

getch();

clearviewport();

//Code for top clip

setviewport(xmin,0,xmax,ymin-1,1);

getch();

clearviewport();

cout<<"\t\tAfter clipping: ";

getch();

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

OUTPUT:

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

30. Write a program to generate a Bezier Curve.

CODE:

#include<stdio.h>

#include<math.h>

#include<conio.h>

#include<iostream.h>

#include<graphics.h>

void main(){

int gd=DETECT,gm,x[4],y[4],i,xx,yy;

float u;

initgraph(&gd,&gm,"C:\\turboc3\\bgi");

for(i=0;i<4;i++){

cout<<"\nEnter Control Point "<<i+1<<": ";

cin>>x[i]>>y[i];

for(i=0;i<3;i++)

line(x[i],y[i],x[i+1],y[i+1]);

moveto(x[0],y[0]);

for(u=0;u<=1;u+=0.001){

xx=pow(1-u,3)*x[0]+3*u*pow(1-u,2)*x[1]+3*u*u*(1-u)*x[2]+u*u*u*x[3];

yy=pow(1-u,3)*y[0]+3*u*pow(1-u,2)*y[1]+3*u*u*(1-u)*y[2]+u*u*u*y[3];

lineto(xx,yy);

getch();

Subject : Computer Graphics April 2021


SIES College of Management Studies SYMCA, Sem IV, Roll No : 18

OUTPUT:

Subject : Computer Graphics April 2021

You might also like