Skip to main content

2D Object Transformations

 

Group B  

Practical 4 a  

Problem Statement :  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.

Check Out Code Here 👇

#include <graphics.h>
#include <stdlib.h>
#include<dos.h>
#include <iostream.h>
#include<conio.h>
#include<math.h>
class triangle
{
int x1,x2,x3,y1,y2,y3,nx1,nx2,nx3,ny1,ny2,ny3,c;
public:
void read();
void draw();
triangle operator+(triangle t);
triangle operator*(triangle t);
triangle operator/(triangle t);
};
void triangle::read()
{
cout<<"\t Program for basic transformations";
cout<<"\n\t Enter the coordinates of triangle and press ENTER ";
setcolor(11);
cin>>x1>>y1>>x2>>y2>>x3>>y3;
}
void triangle::draw()
{
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
getch();
}
triangle triangle:: operator+(triangle t)
{ int tx,ty;
cout<<"\Enter translation factors(tx and ty) ";
cin>>tx>>ty;
t.x1=x1+tx;
t.y1=y1+ty;
t.x2=x2+tx;
t.y2=y2+ty;
t.x3=x3+tx;
t.y3=y3+ty;
return(t);
}
triangle triangle:: operator*(triangle t)
{
float sx,sy;
cout<<"\n Enter the scalling factor(Sx and Sy) ";
cin>>sx>>sy;
t.x1=x1*sx;
t.y1=y1*sy;
t.x2=x2*sx;
t.y2=y2*sy;
t.x3=x3*sx;
t.y3=y3*sy;
return(t);
}
triangle triangle ::operator/(triangle t)
{
int r;
float theta;
cout<<"\n Enter the angle of rotation ";
cin>>r;
theta=3.14*r/180;
t.x1=abs(x1*cos(theta)-y1*sin(theta));
t.y1=abs(x1*sin(theta)+y1*cos(theta));
t.x2=abs(x2*cos(theta)-y2*sin(theta));
t.y2=abs(x2*sin(theta)+y2*cos(theta));
t.x3=abs(x3*cos(theta)-y3*sin(theta));
t.y3=abs(x3*sin(theta)+y3*cos(theta));
return(t);
}
int main()
{
int gm,c;
int gd=DETECT;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
triangle t1,T, S,R,t2;
t1.read();
t1.draw();
cout<<"\n 1.Translation\n 2.Rotation\n 3.Scalling\n 4.exit";
cout<<"\n Enter your choice: ";
cin>>c;
switch(c)
{
case 1:
T=t1+t2;
T.draw();
break;
case 2:
R=t1/t1;
R.draw();
break;
case 3:
S=t1*t1;
S.draw();
break;
}
getch();
closegraph();
return 0;
}

Output :

a) Scaling -

b) Translation -

c) Rotation -


Code can get updated so also come back later to see if there is any changes. Also if there is any problem with code you can comment below. If you like it, do share with your friends.😊

Comments

Popular posts from this blog

DSL A1

Hello Friends lets See the first practical of Data Structure Laboratory(DSL) of SPPU Second Year. Some of the students are afraid of coding as it is new to all of us. So we are here to conquer your fear. You will find it easy as it explained by students only. So lets Get into it The first practical of part A is : In second year computer engineering class, group A student’s play cricket, group B students play badminton and group C students play football. Write a Python program using functions to compute following: -  a) List of students who play both cricket and badminton  b) List of students who play either cricket or badminton but not both  c) Number of students who play neither cricket nor badminton  d) Number of students who play cricket and football but not badminton.  (Note- While realizing the group, duplicate entries should be avoided, Do not use SET built-in functions)  So most of us know the SET theory in mathematics. The above problem is very easy...

OOP 2

Object Oriented Programming Group A - Practical : 2 Problem Statement :  Develop a program in C++ to create a database of student’s information system containing the following information: Name, Roll number, Class, Division, Date of Birth, Blood group, Contact address, Telephone number, Driving license no. and other. Construct the database with suitable member functions. Make use of constructor, default constructor, copy constructor, destructor, static member functions, friend class, this pointer, inline code and dynamic memory allocation operators-new and delete as well as exception handling. Check Out Code Here  👇 Code can get updated so also come back later to see if there is any changes. Also if there is any problem with code you can comment below. If you like it, do share with your friends.😊

OOP 6

   Object Oriented Programming Group B - Practical : 6 Problem Statement :  Write C++ program using STL for sorting and searching user defined records such as personal records (Name, DOB, Telephone number etc) using vector container. Check Out Code Here  👇 Code can get updated so also come back later to see if there is any changes. Also if there is any problem with code you can comment below. If you like it, do share with your friends.😊