Gokhale Education Society's R. H. Sapat College of Engineering, Management Studies & Research, Nashik-422005 Department of Computer Engineering
Gokhale Education Society's R. H. Sapat College of Engineering, Management Studies & Research, Nashik-422005 Department of Computer Engineering
Gokhale Education Society's R. H. Sapat College of Engineering, Management Studies & Research, Nashik-422005 Department of Computer Engineering
Prepared By:
PROBLEM STATEMENT
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.
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.
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
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 :−
3
x′ = xcosθ − ysinθ
y′ = xsinθ + ycosθ
Matrix for homogeneous co-ordinate rotation (clockwise)
CODE :
#include<iostream>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<direct.h>
#define PI 3.141592653589793238
int main()
{
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];
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 :