Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Gokhale Education Society's R. H. Sapat College of Engineering, Management Studies & Research, Nashik-422005 Department of Computer Engineering

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Gokhale Education Society’s

R. H. Sapat College of Engineering, Management Studies &


Research, Nashik-422005

Department of Computer Engineering

Name of Subject: Computer Graphics


Class: SE Computer
Div: B
Semester: III
Subject Teacher: Prof. G. G. Raut

Project Based Learning Report

Prepared By:

Kothawade Aniket Devendra –(1)


Kshirsagar Yash Milind –(2)
Kumbhar Yogeshwar Vitthal –(3)
Mahajan Umesh Arun –(6)

PROBLEM STATEMENT

Write a program to slide the circle on slanted ramp.

1
ANALYSIS OF PROBLEM STATEMENT :
The given problem statement states that we have to use computer graphics
related concepts (2-D Transformations) to stimulate the circle as sliding from the slanted
ramp.

WHAT IS 2-D TRANSFORMATION:


Transformation means changing some graphics into something else by applying
rules. We can have various types of transformations such as translation, scaling up or down,
rotation, shearing, etc. When a transformation takes place on a 2D plane, it is called 2D
transformation.
Transformations play an important role in computer graphics to reposition the
graphics on the screen and change their size or orientation.

Types of Transformations:

1. Translation

2. Rotation

3. Scaling

4. Reflection

5. Shearing

 2-D Translation :

Translation means moving an object from one position to a different position on the
screen without changing the size and shape of the object in a 2-D plane.

To translate a point P from coordinate position P(x, y) to another P’(x′,y′), we algebraically


add the translation distances tx and ty to the original coordinates.

From the above figure, we can write that −


x’ = x + tx
y’ = y + ty
The pair (tx, ty) is called the translation vector or shift vector.

2
Matrix for homogeneous co-ordinate translation

 2-D Rotation :

Rotation means rotating an object with an angle with respect to the origin without
changing the size and shape of the object in a 2-D plane. Rotation can be clockwise or
anticlockwise. For rotation, we have to specify the angle of rotation and rotation point. Rotation point is also
called a pivot point. It is the point about which object is rotated.

Types of Rotation :

1. Anticlockwise
2. Clockwise

The positive value of the rotation angle rotates an object in an anti-clockwise


direction. The negative value of the rotation angle rotates an object in a clockwise
direction.

In rotation, we rotate the object at particular angle θ from its origin. From the figure, we
can see that the point P(x,y) is located at angle φ from the horizontal X-axis with distance r
from the origin.
We want to rotate it at the angle θ. After rotating it to a new location, we get a new
point P’(x′,y′).

Using standard trigonometric the original coordinate of point P(x,y) can be represented as:-

x = rcosϕ Eqn(1)
y = rsinϕ Eqn(2)
Similarly, the point P’(x’,y’) can be represented as :−

x′ = rcos(ϕ+θ) = rcosϕcosθ – rsinϕsinθ Eqn(3)


y′ = rsin(ϕ+θ) = rcosϕsinθ + rsinϕcosθ ........Eqn(4)

Substituting Eqn(1) and Eqn(2) in Eqn(3) and Eqn(4) respectively, we get

3
x′ = xcosθ − ysinθ
y′ = xsinθ + ycosθ
Matrix for homogeneous co-ordinate rotation (clockwise)

Matrix for homogeneous co-ordinate rotation (anticlockwise)

CODE :

#include<iostream>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<direct.h>
#define PI 3.141592653589793238

using namespace std;

int main()
{

int cx,cy,r; float deg,rad;


cout<<"\t\t\t\t\tWELCOME TO GRAPHICS PROGRAM\n";
cout<<"\n\t\t\t\t Slide the circle on a slanted ramp\n";
cout<<"\nEnter the details for circle : ";
cout<<"\n\tEnter the x co-ordinate of the center of the circle : ";
cin>>cx; cout<<"\tEnter the y co-ordinate of the center of the
circle : ";
cin>>cy; cout<<"\tEnter the radius of the circle : "; cin>>r;
cout<<"\tEnter the inclination of the ramp (in degrees) : ";
cin>>deg;
rad=deg*(PI/180);
cout<<"\nInclication of the ramp (in radians) : "<<rad;

int i,j,k,numver=1;
float
x1,y1,xn,yn,x2,y2,x3,y3,b,h,x4,y
4,dist,tx,ty; float

4
rot[3][3],pnew[numver][3],pold[n
umver][3];

x1=cx-(r*sin(rad)); y1=cy+(r*cos(rad)); xn=cx+(4*r); yn=y1;

pnew[0][0]=pnew[0][1]=pnew[0][2]=0;
pold[0][0]=xn;
pold[0][1]=yn;
pold[0][2]=1;

rot[0][0]=rot[1][1]=cos(rad);
rot[0][1]=sin(rad);
rot[1][0]=-sin(rad);
rot[1][2]=rot[0][2]=rot[2][0]=rot[2][1]=0;
rot[2][2]=1;

for(i=0;i<numver;i++)
{
for(k=0;k<3;k++)
{
for(j=0;j<3;j++)
{
pnew[i][k]+=pold[i][j]*rot[j][k];
}
}
}

x2=pnew[0][0];
y2=pnew[0][1];
x3=x1;
y3=y2;
b=x2-x3;
h=y3-y1;
x4=cx+b;
y4=cy+h;
dist=sqrt(pow(x2-x1,2)+pow(y2-y1,2));

tx=(x2-x1+20)/50;
ty=(y2-y1)/50;

int gd=DETECT,gm;
initgraph(&gd,&gm,(char*)" ");

setbkcolor(BLACK);
setcolor(WHITE);

line(x1,y1,x2,y2);
delay(2000);
line(x1,y1,x3,y3);

5
delay(2000);
line(x2,y2,x3,y3);
delay(2000);

for(i=cx,j=cy;i<x2+r,j<=y3-r*cos(rad);i+=tx,j+=ty)
{
cleardevice();
line(0,y3,getmaxx(),y3);
line(x1,y1,x2,y2);
line(x1,y1,x3,y3);
line(x2,y2,x3,y3);
circle(i,j,r);
delay(200);
}

getch();
closegraph();

return 0; }

OUTPUT :

6
7
8
CONCLUSION :

Hence, we have successfully stimulated the circle sliding from a slanted ramp
using various concepts of computer graphics like 2-D transformations.

REFERENCES :

https://www.tutorialspoint.com/computer_graphics/2d_transformation Computer Graphics


Introduction of Transformation - javatpoint Computer Graphics Homogeneous Coordinates -
javatpoint

You might also like