0% found this document useful (0 votes)
17 views9 pages

Computer Graphics Practical 4

Uploaded by

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

Computer Graphics Practical 4

Uploaded by

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

SE(AIDS NAME: Khedkar Minakshi

) Ganesh

Computer graphics practical 4


Q) write C++ program to draw 2-d object and perform
following basic transformations a) Scaling b) Translation
c) Rotation. Apply the concept of operator overloading.
CODE:
#include<iostream

.h>

#include<graphics.

h>

#include<math.h>

#include<conio.h>

#include<stdlib.h>

#include<stdio.h>

class transform

public:

Cout<<”khedkar minakshi”<<endl;

int m,a[20][20],c[20][20];

int

i,j,k;

public:

void object();

void accept();

void operator *(float b[20][20])

for(int i=0;i<m;i++)
VACOE AHMEDNAGAR 2024-25
SE(AIDS NAME: Khedkar Minakshi
) Ganesh

for(int j=0;j<m;j++)

VACOE AHMEDNAGAR 2024-25


SE(AIDS NAME: Khedkar Minakshi
) Ganesh

c[i][j]=0;

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

c[i][j]=c[i][j]+(a[i][k]*b[k][j]);

};

void transform::object()

int gd,gm;

gd=DETECT;

initgraph(&gd,&gm,"C:\\Turboc3\\

BGI"); line(300,0,300,600);

line(0,300,600,300);

for( i=0;i<m-1;i++)

line(300+a[i][0],300-a[i][1],300+a[i+1][0],300-a[i+1][1]);

line(300+a[0][0],300-a[0][1],300+a[i][0],300-a[i][1]);

for( i=0;i<m-1;i++)

line(300+c[i][0],300-c[i][1],300+c[i+1][0],300-c[i+1][1]);

VACOE AHMEDNAGAR 2024-25


SE(AIDS NAME: Khedkar Minakshi
) Ganesh

line(300+c[0][0],300-c[0][1],300+c[i][0],300-c[i][1]);

int temp;

cout << "Press 1 to

continue"; cin >> temp;

closegraph();

void transform::accept()

cout<<"\n";

cout<<"Enter the Number Of

Edges:"; cin>>m;

cout<<"\nEnter The

Coordinates :"; for(int

i=0;i<m;i++)

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

if(j>=2)

a[i][j]=1;

else

cin>>a[i]

[j];

int main()

VACOE AHMEDNAGAR 2024-25


SE(AIDS NAME: Khedkar Minakshi
) Ganesh

int ch,tx,ty,sx,sy;

VACOE AHMEDNAGAR 2024-25


SE(AIDS NAME: Khedkar Minakshi
) Ganesh

float deg,theta,b[20]

[20]; transform t;

t.accept();

cout<<"\nEnter your choice";

cout<<"\n1.Translation"

"\n2.Scaling"

"\n3.Rotation";

cin>>ch;

switch(ch)

case 1: cout<<"\nTRANSLATION

OPERATION\n"; cout<<"Enter value

for tx and ty:"; cin>>tx>>ty;

b[0][0]=b[2][2]=b[1][1]=1;

b[0][1]=b[0][2]=b[1][0]=b[1]

[2]=0; b[2][0]=tx;

b[2][1]=ty;

t * b;

t.object(

); break;

case 2: cout<<"\nSCALING OPERATION\n";

cout<<"Enter value for sx,sy:";

cin>>sx>>sy;

VACOE AHMEDNAGAR 2024-25


SE(AIDS NAME: Khedkar Minakshi
) Ganesh

b[0][0]=sx;

b[1][1]=sy; b[0][1]=b[0][2]=b[1]

[0]=b[1][2]=0; b[2][0]=b[2][1]=0;

b[2][2] = 1;

t * b;

t.object(

); break;

case 3: cout<<"\nROTATION OPERATION\

n"; cout<<"Enter value for angle:";

cin>>deg;

theta=deg*(3.14/100); b[0]

[0]=b[1][1]=cos(theta); b[0]

[1]=sin(theta);

b[1][0]=sin(-theta); b[0]

[2]=b[1][2]=b[2][0]=b[2][1]=0;

b[2][2]=1;

t * b;

t.object(

); break;

default:

cout<<"\nInvalid choice";

getch();

VACOE AHMEDNAGAR 2024-25


SE(AIDS NAME: Khedkar Minakshi
) Ganesh

return 0;

OUTPUT
1) TRANSLATION

2) SCALING

VACOE AHMEDNAGAR 2024-25


SE(AIDS NAME: Khedkar Minakshi
) Ganesh

3) ROTATION

VACOE AHMEDNAGAR 2024-25

You might also like