Lab Manual - CGL - 2017
Lab Manual - CGL - 2017
The laboratory assignments are to be submitted by student in the form of journal. Journal
consists of prologue, Certificate, table of contents, and handwritten write-up of each
assignment (Title, Objectives, Problem Statement, Outcomes, software & Hardware
requirements, Date of Completion, Assessment grade/marks and assessor's sign, Theory-
Concept in brief, algorithm, flowchart, test cases, conclusion/analysis. Program codes
with sample output of all performed assignments are to be submitted as softcopy.
Group A
EXPERIMENT NO. 1
Write C++/Java program to draw line using DDA and Bresenham‘s algorithm. Inherit pixel
class and Use function overloading
1.1 Objectives: To learn function to Draw a line using DDA and Bresenham’s Algorithm.
1.2 Problem Statement: Write a c++ class for a line drawing using DDA andBresenham’s
Algorithm, Inheriting the Pixel or Point
1.3 Software Requirement:Fedora,C++
1.4 Input: Read the X & Y co-ordinates From the Users.
1.5 Output: It Display the Line on the Screen.
1.6 Theory:
1.6.1Write and Explain DDA Line Drawing Algorithm
DDA Line Drawing Algorithm:
Digital differential analyzer (DDA) is hardware or software used for linear
interpolation of variables over an interval between start and end point. DDAs are
used for rasterization of lines, triangles and [Link] algorithm is an
incremental scan conversion method. Here we perform calculations at each step
using the results from the preceding step. The characteristic of the DDA algorithm is
to take unit steps along one coordinate and compute the corresponding values along
the other coordinate.
Algorithm:
1. Read the line end points (𝑥1,1) and (𝑥2,𝑦2) such that they are not equal. [If
equal then plot that point and exit]
2. Δ𝑥 = |𝑥2 − 𝑥1|and Δ𝑦 = |𝑦2 –𝑦1|
3. If (Δ𝑥 ≥ Δ𝑦) 𝑡ℎ𝑒𝑛
Length=Δ𝑥
else
Length=Δ𝑦
end if
4. Δ𝑥 = (𝑥2 − 𝑥1)/𝑙𝑒𝑛𝑔𝑡ℎ
Δ𝑦 = (𝑦2 − 𝑦1)/𝑙𝑒𝑛𝑔𝑡ℎ
[This makes either Δ𝑥 or Δ𝑦 equal to 1 because length is either |𝑥2 − 𝑥1| or
|𝑦2− 𝑦1| . Therefore, the incremental value for either x or y is one.]
5. 𝑥 = 𝑥1 + 0.5 (Δ𝑥)
𝑌 = 𝑦1 + 0.5 (Δ𝑦)
[Here, sign function makes the algorithm work in all quadrants.
It returns -1, 0, 1
Depending on whether its argument is <0, =0, >0, respectively.]
6. i=1
[begins the loop, in this points are plotted]
While (i≤length)
{
Plot (integer(x), integer(y))
𝑥 = 𝑥 + Δ𝑥
𝑦 = 𝑦 + Δ𝑦
𝑖=𝑖+1
}
Advantages of DDA Algorithm:
1. It is the simplest algorithm and it does not require special skills for
implementation.
2. It is a faster method for calculating pixel positions than the direct use of equation
y = mx + b. It eliminates the multiplication in the equation by making use of raster
Characteristics, so that appropriate increments are applied in the x or y direction to
Find the pixel positions along the line path.
Disadvantages of DDA Algorithm:
1. Floating point arithmetic in DDA algorithm is still time-consuming.
2. The algorithm is orientation dependent. So the end point accuracy is poor.
Bresenham's line algorithm
1. Input the two line endpoints and store the left endpoint in (xo,yo)
2. Load (xO, yO) into the frame buffer; that is, plot the first point.
3. Calculate constants ∆x, ∆y, 2∆y, and 2∆y - 2∆x, and obtain the starting value for the
decision parameter as
po= 2∆y - ∆x
4. At each xk along the line, starting at k = 0, perform the following test:
If Pk< 0, the next point to plot is (xk+1, yk) and
Pk+1=P k+2∆y
Otherwise, the next point to plot is (xk+ 1, yk+ 1) and
pk+1= pk+ 2∆y - 2∆x
5. Repeat step 4 ∆x times.
1.8 Conclusion:
DDA and Bresenham’s Line Drawing Algorithm are understood and executed
successfully.
Group A
EXPERIMENT NO. 2
Problem Statement:
Without just calculating the pixels from a global formula. This algorithm is called
incremental, because the position of the next pixel is calculated on the basis of the
last plotted one Bresenham's circle algorithm calculates the locations of the pixels in
the first 45 degrees. It assumes that the circle is centered on the origin shifting the
original center coordinates (centerx, centery). So for every pixel (x, y) it calculates,
we draw a pixel in each of the 8 octants of the circle.
Output: Circle.
Theory: Circles have the property of being highly symmetrical, which is handy when it
comes to drawing them on a display screen.
We know that there are 360 degrees in a circle. First we see that a circle is
symmetrical about the x axis, so only the first 180 degrees need to be calculated. Next, we
see that it's also symmetrical about the y axis, so now we only need to calculate the first 90
degrees. Finally, we see that the circle is also symmetrical about the 45 degree diagonal
axis, so we only need to calculate the first 45 degrees.
putpixel(centerx + x, center y + y)
putpixel(centerx + x, center y - y)
putpixel(centerx - x, center y + y)
putpixel(centerx - x, center y - y)
putpixel(centerx + y, center y + x)
putpixel(centerx + y, center y - x)
putpixel(centerx - y, center y + x)
putpixel(centerx - y, center y - x)
Now, consider a very small continuous arc of the circle interpolated below, passing
by the discrete pixels as shown.
As can be easily intercepted, the continuous arc of the circle cannot be plotted on a
raster display device, but has to be approximated by choosing the pixels to be highlighted.
At any point (x,y), we have two choices – to choose the pixel on east of it, i.e. N(x+1,y) or the
south-east pixel S(x+1,y-1). To choose the pixel, we determine the errors involved with
both N & S which are f(N) and f(S) respectively and whichever gives the lesser error, we
choose that pixel.
Let di = f(N) + f(S), where d can be called as "decision parameter", so that
If di<=0, then, N(x+1,y) is to be chosen as next pixel i.e. xi+1 = xi+1 and yi+1 = yi,
and
If di>0, then, S(x+1,y-1) is to be chosen as next pixel i.e. xi+1 = xi+1 and yi+1 = yi-1.
Mathematical Foundation:
We know that for a circle,
x2 + y2 = r2
r= radius of the circle which is input to the algorithm.
Error can be represented as
f(N) = (xi + 1)2 + yi2 - r2, ------------------ (1)
f(S) = (xi + 1)2 + (yi - 1)2 - r2 ------------- (2)
As di = f(N) + f(S),
di = 2(xi+1)2 + yi2 + (yi-1)2 – 2r2 ------------- (3)
Calculate Next Decision Parameter..
di+1 = 2(xi+2)2 + yi+12 + (yi+1-1)2 – 2r2 --- (4)
From (4) –(3) we get
di+1 – di = 2((xi+2)2-(xi+1)2) + (yi+12 – yi2) + ((yi+1-1)2 + (yi-1)2)
di+1 = di + 2((xi+2+xi+1)(xi+2-xi-1)) + ((yi+1+yi)(yi+1-yi)) + ((yi+1-1+yi-1)(yi+1-1-yi+1))
di+1 = di + 2(2xi+3) + ((yi+1+yi)(yi+1-yi)) + ((yi+1-1+yi-1)(yi+1-1-yi+1)
Now, if (di<=0),
xi+1=xi+1 and yi+1=yi
so that di+1 = di + 2(2xi + 3) + ((yi+1+yi)( yi-yi)) + ((yi-1+yi-1)(yi-1-yi+1))
di+1 = di + 2(2xi + 3) + ((yi+1+yi)(0)) + ((yi-1+yi-1)(0))
di+1 = di + 4xi + 6
Else
di+1 = di + 2(2xi+3) + ((yi-1+yi)(yi-1-yi)) + ((yi-2+yi-1)(yi-2-yi+1))
di+1 = di + 4xi+6 + ((2yi-1)(-1)) + ((2yi-3)(-1))
di+1 = di + 4xi+6 - 2yi - 2yi + 1 + 3
di+1 = di + 4(xi - yi) + 10
To know di+1, we have to know di first. The initial value of di can be obtained by
replacing x=0 and y=r in (3). Thus, we get,
do = 2 + r2 + (r - 1)2 -2r2
do = 2 + r2 + r2 + 1 -2r – 2r2
do = 3 – 2r
Using the highlighted formulas, we can easily plot a circle on a raster graphics display
device.
Pseudo code:
void circleBres(int xc, int yc, int r)
{
int x = 0, y = r;
int d = 3 - 2 * r;
while (x < y)
{
drawCircle(xc, yc, x, y);
x++;
if (d < 0)
d = d + 4 * x + 6;
else
{
y--;
d = d + 4 * (x - y) + 10;
}
}
}
Conclusion:
Group A
EXPERIMENT NO. 3
Aim:
Write C++/Java program to draw 2-D object and perform following basic
transformations,
a) Scaling
b) Translation
c) Rotation
Use operator overloading.
Input: Polygon
Theory:
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.
Homogenous Coordinates
Translation
A translation moves an object to a different position on the screen. You can translate a
point in 2D by adding translation coordinate (tx, ty) to the original coordinate (X, Y) to get
the new coordinate (X’, Y’).
From the above figure, you can write that −
X’ = X + tx
Y’ = Y + ty
The pair (tx, ty) is called the translation vector or shift vector. The above equations can also
be represented using the column vectors.
P=[X][Y]
We can write it as −
P’ = P + T
Rotation
In rotation, we rotate the object at particular angle θ (theta) from its origin. From the
following figure, we can see that the point P(X, Y) is located at angle φ from the horizontal X
coordinate with distance r from the origin.
Let us suppose you want to rotate it at the angle θ. After rotating it to a new location, you
will get a new point P’ (X’, Y’).
Using standard trigonometric the original coordinate of point P(X, Y) can be represented as
−
X=rcosϕ......(1)
Y=rsinϕ......(2)
x′=rcos(ϕ+θ)=rcosϕcosθ−rsinϕsinθ.......(3)
y′=rsin(ϕ+θ)=rcosϕsinθ+rsinϕcosθ.......(4)
Substituting equation (1) & (2) in (3) & (4) respectively, we will get
x′=xcosθ−ysinθ
y′=xsinθ+ycosθ
[X′Y′]=[X′Y′][cosθ−sinθsinθcosθ]OR
P’ = P . R
R=[cosθ−sinθsinθcosθ]
For positive rotation angle, we can use the above rotation matrix. However, for negative
angle rotation, the matrix will change as shown below −
R=[cos(−θ)−sin(−θ)sin(−θ)cos(−θ)]
=[cosθsinθ−sinθcosθ](∵cos(−θ)=cosθandsin(−θ)=−sinθ)
Scaling
To change the size of an object, scaling transformation is used. In the scaling process, you
either expand or compress the dimensions of the object. Scaling can be achieved by
multiplying the original coordinates of the object with the scaling factor to get the desired
result.
Let us assume that the original coordinates are (X, Y), the scaling factors are (SX, SY), and
the produced coordinates are (X’, Y’). This can be mathematically represented as shown
below −
The scaling factor SX, SY scales the object in X and Y direction respectively. The above
equations can also be represented in matrix form as below −
(X′Y′)=(XY)[Sx00Sy]
OR
P’ = P . S
Where S is the scaling matrix. The scaling process is shown in the following figure.
Conclusion:
Group A
EXPERIMENT NO. 4
Aim: Write C++ program to fill polygon using scan line algorithm. Use mouse interfacing to
draw polygon
Software required: Linux Operating system, GCC
Input: Polygon
THEORY:
Polygon:
The boundary of the polygon is formed by joining the last point you specify to the first one.
Scan line:-
The scan line fill algorithm is an ingenious way of filling in irregular polygons. The
algorithm begins with a set of points. Each point is connected to the next, and the line
between them is considered to be an edge of the polygon. The points of each edge are
adjusted to ensure that the point with the smaller y value appears first. Next, a data
structure is created that contains a list of edges that begin on each scan line of the image.
The program progresses from the first scan line upward. For each line, any pixels that
contain an intersection between this scan line and an edge of the polygon are filled in.
Then, the algorithm progresses along the scan line, turning on when it reaches a polygon
pixel and turning off when it reaches another one, all the way across the scan line.
This algorithm works by intersecting scanline with polygon edges and fills the polygon
between pairs of intersections. The following steps depict how this algorithm works.
Step 1 − Find out the Ymin and Ymax from the given polygon.
Step 2 − ScanLine intersects with each edge of the polygon from Ymin to Ymax. Name each
intersection point of the polygon. As per the figure shown above, they are named as p0, p1,
p2, p3.
Step 3 − Sort the intersection point in the increasing order of X coordinate i.e. (p0, p1), (p1,
p2), and (p2, p3).
Step 4 − Fill all those pair of coordinates that are inside polygons and ignore the alternate
pairs.
Pseudo code :
ALGORITHM:
4. The slope of the edge is constant from one scan line to the next:
a. Let m denote the slope of the edge.
b.
5. Each successive x is computed by a
Each successive x is computed by adding the inverse of the slope and rounding to the
nearest integer
Conclusion:
Group B
EXPERIMENT NO. 1
Write C++ program to draw inscribed and Circumscribed circles in the triangle as shown as
an example below. (Use any Circle drawing and Line drawing algorithms)
Title: Line drawing using DDA and Bresenham’s Algorithm.
Objectives: To learn function to Draw a line using DDA and Bresenham’s Algorithm.
Problem Statement: Write C++/Java program for line drawing using DDA or Bresenhams
algorithm with patterns such as solid, dotted, dashed, dash dot and thick.
Software Requirement: Fedora, GCC
Input: Read the X & Y co-ordinates From the Users.
Theory:
[This makes either Δ𝑥 or Δ𝑦 equal to 1 because length is either |𝑥2 − 𝑥1| or |𝑦2− 𝑦1|
Therefore, the incremental value for either x or y is one.]
5. 𝑥 = 𝑥1 + 0.5 (Δ𝑥)
𝑌 = 𝑦1 + 0.5 (Δ𝑦)
[Here, sign function makes the algorithm work in all quadrants. It
returns -1, 0, 1
Depending on whether its argument is <0, =0, >0, respectively.]
6. i=1
[begins the loop, in this points are plotted]
While (i≤length)
{
Plot (integer(x), integer(y))
𝑥 = 𝑥 + Δ𝑥
𝑦 = 𝑦 + Δ𝑦
𝑖=𝑖+1
}
Algorithm:
1. Read the line end points (x1, y1) and (x2, y2) such that they are not equal. (If equal
then plot that point and exit)
2. y = |y2-y1| and x = | x2-x1| .
3. [Initialize starting point]
x=x1 y=y1
4. e=2y-x [Initialize value of decision variable or error to compensate for nonzero
intercepts]
5. I=1 [Initialize counter]
6. Plot (x, y)
7. While (e>=0)
{
y=y+1
e=e-2x
}
x=x+1
e=e+2y
8. I=I+1
9. If ( I<=x) then go to step 6.
10. Stop.
Conclusion:
Group B
EXPERIMENT NO. 2
Title:
Objectives: To learn function to Draw and fill convex polygon usingSeed fill algorithm
Problem Statement:Write C++/Java program to draw a convex polygon and fill it with
desired color using Seed fill algorithm. Use mouse interfacing to draw polygon
Output: It Display the convex polygon filled with desired color on the Screen.
Theory:
A line drawn through a convex polygon will intersect the polygon exactly twice, as can
be seen from the figure on the left. You can also see that the line will divide the polygon into
exactly two pieces.
All the diagonals of a convex polygon lie entirely inside the polygon. See
figure on the left. (In a concave polygon, some diagonals will lie outside the polygon).
The area of an irregular convex polygon can be found by dividing it into triangles and
summing the triangle's areas. See Area of an Irregular Polygon
Regular Polygons are always convex by definition. See Regular Polygon Definition. In the
figure at the top of the page, click on "make regular" to force the polygon to always be a
regular polygon. You will see then that, no matter what you do, it will remain convex.
Seed Filling:
In this method a particular seed point is picked and we start filling upwards and
downwards pixels until boundary is reached. Seed fill method is of two types: Boundary fill
and Flood fill.
Boundary fill algorithm: In Boundary filling a seed point is fixed, and then neighboring
pixels are checked to match with the boundary color. Then, color filling is done until
boundary is reached. A region may be 4 connected or 8 connected:
Procedure for filling a 4- connected region: Color is specified by parameter fill color (f-
color) and boundary color is specified by boundary color (b-color). getpixel() function
gives the color of specified pixel and putpixel() fills the pixel with particular color.
{
If (getpixel (x,y) != b_color&& getpixel (x,y) != f_color)
putpixel(x,y,f_color)
Flood fill algorithm: There are some cases where the boundary color is different than the
fill color. For situations like these Flood fill algorithm is used. Here the process is started in
a similar way by examining the colors of neighboring pixels. But instead of matching it with
a boundary color a specified color is matched.
putpixel(x,y,new_color)
}
}
1) If an inside pixel is in some other color then the fill terminates and the polygon remains
unfilled.
Conclusion:
Successfully executed seed fill algorithm to draw a convex polygon and fill it with desired
color .
Group B
EXPERIMENT NO. 3
Title: Write C++/Java program to implement Cohen-Sutherland line clipping algorithm for
given window. Draw line using mouse interfacing to draw polygon.
Theory:
The sequence for reading the codes' bits is LRBT (Left, Right, Bottom, Top).
Algorithm:
1. Given a line segment with endpoint P1=(x1,y1) and P2=(x2,y2)
2. Compute the 4-bit codes for each endpoint.
If both codes are 0000,(bitwise OR of the codes yields 0000 ) line lies completely
inside the window: pass the endpoints to the draw routine.
If both codes have a 1 in the same bit position (bitwise AND of the codes is not
0000), the line lies outside the window. It can be trivially rejected.
3. If a line cannot be trivially accepted or rejected, at least one of the two endpoints
must lie outside the window and the line segment crosses a window edge. This line
must be clipped at the window edge before being passed to the drawing routine.
4. Examine one of the endpoints, say P1=(x1,y1). Read P1 's 4-bit code in order: Left-
to-Right, Bottom-to-Top.
5. When a set bit (1) is found, compute the intersection I of the corresponding
window edge with the line from P1 to P2. Replace P1 with I and repeat the
algorithm.
Before Clipping
1. Consider the
line segment
AD.
Point A has an outcode of 0000 and point D has an outcode of 1001. The logical
AND of these outcodes is zero; therefore, the line cannot be trivally rejected. Also,
the logical OR of the outcodes is not zero; therefore, the line cannot be trivally
accepted. The algorithm then chooses D as the outside point (its outcode contains
1's). By our testing order, we first use the top edge to clip AD at B. The algorithm
then recomputes B's outcode as 0000. With the next iteration of the algorithm, AB is
tested and is trivially accepted and displayed.
2. Consider the line segment EI
Point E has an outcode of 0100, while point I's outcode is 1010. The results of the
trivial tests show that the line can neither be trivally rejected or accepted. Point E is
determined to be an outside point, so the algorithm clips the line against the bottom
edge of the window. Now line EI has been clipped to be line FI. Line FI is tested and
cannot be trivially accepted or rejected. Point F has an outcode of 0000, so the
algorithm chooses point I as an outside point since its outcode is1010. The line FI is
clipped against the window's top edge, yielding a new line FH. Line FH cannot be
trivally accepted or rejected. Since H's outcode is 0010, the next iteration of the
algorthm clips against the window's right edge, yielding line FG. The next iteration
of the algorithm tests FG, and it is trivially accepted and display.
After Clipping
After clipping the segments AD and EI, the result is that only the line segment AB and FG
can be seen in
the window.
Conclusion:
Cohen Sutherland algorithm is easy to implement algorithm to clip the given line
against rectangle window.
Group B
EXPERIMENT NO. 4
Title: Write C++/Java program to generate Hilbert curve using concept of fractals
Objectives:
Student will be able to generate Hilbert curve using concept of fractals
1.1Problem Statement:
Write a C++or java program to generate hilbert curve
1.2Software Requirement:
Ubantu ,java
1.3Input:
n : order of Hilbert curve.
1.4Output:
Display curve of order n.
1.5 Theory:
Hilbert Curve
The Hilbert curve is a space filling curve that visits every point in a square grid with
a size of 2×2, 4×4, 8×8, 16×16, or any other power of 2. It was first described by
David Hilbert in 1892. Applications of the Hilbert curve are in image processing:
especially image compression and dithering. The basic elements of the Hilbert
curves are what I call "cups" (a square with one open side) and "joins" (a vector that
joins two cups).The "open" side of a cup can be top, bottom, left or right. In addition,
every cup has two end-points, and each of these can be the "entry" point or the
"exit" point. So, there are eight possible varieties of cups. In practice, a Hilbert curve
uses only four types of cups. In a similar vein, a join has a direction: up, down, left or
right.
A first order Hilbert curve is just a single cup.( figure a)
The second order Hilbert curve replaces that cup by four (smaller) cups,
which are linked together by three joins (see the figure on the right; the link
between a cup and a join has been marked with a fat dot in the figure).( figure
b).
Every next order repeats the process or replacing each cup by four smaller
cups and three joins.
1.7 Conclusion:
The Hilbert curve is easy to generate. When applied over a digitized photograph or a ray-
traced image, it makes better use of the coherence of neighboring pixels than the
traditional scan-line based approach.
Group B
EXPERIMENT NO. 5
Title: Write C++ program to draw any object such as flower, waves using any curve
generation techniques
Objectives:
Student will be able to generate any object such as flower, waves using any curve
generation
1.1Problem Statement:
Write a C++or java program to generate any object such as flower, waves using any
curve generation
1.2Software Requirement:
Ubantu ,java
1.3Input:
n : order of B splin curve.
1.4Output:
Display curve of order n.
Introduction to curves :
The basic aim of computer graphics is to display realistic object . Graphics scenes
can contain many different kinds of objects: flowers, clouds, rocks, water, bricks, wood
paneling, rubber, paper, marble, steel, glass, plastic, and cloth, just to mention a few. So it is
probably not too surprising that there is no one method that we can use to describe objects
that will include all characteristics of these different materials. Line and polygon clipping
routines are standard components of graphics packages, but many packages accommodate
curved objects,such as circles and ellipses . And to produce realistic displays of scenes, we
need to use representations that accurately model object characteristics . In computer
graphics often we need to draw different objects which are not always flat which will be
drawn with lines . We have to use to use curves many times to draw an object.
B-SPLINE CURVES
Last section:
B[i](u) = F[5 - i](1 - u) where F[i](u) is the ith blending function for
the first section.
Note that B-Spines are designed to eliminate sharp corners, as seen above. A sharp corner
can be obtained, however, by using duplicate sequential control points. Using three
identical control points causes the curve to pass through the point, as illustrated below.
Conclusion:
Group C
EXPERIMENT NO. 1
Aim:Write C++/Java program to simulate any one of or similar scene- Vehicle /boat
locomotion
Input: -
Theory:
Vehicle
Land vehicles are classified broadly by what is used to apply steering and drive forces
against the ground: wheeled, tracked, railed or skied. ISO 3833-1977 is the standard, also
internationally used in legislation, for road vehicles types, terms and definitions.
Locomotion:
Movement from one place to another and the ability to locomote, to get from one place to
the next. The locomotive system permits locomotion and consists of bones that are the
framework of the skeleton, joints that hold the bones together and make movement
possible, and muscles that contract and relax and make for movement.
In this program, we will first draw a car and color it. In every iteration of for loop we keep
on increasing the x coordinates of every point of car to make it look like this car is moving
from left to right. We will use below mentioned graphics functions in this program.
Function Description
It initializes the graphics system by loading the passed graphics
initgraph
driver then changing the system into graphics mode.
It returns the maximum X coordinate in current graphics mode and
getmaxx
driver.
It returns the maximum X coordinate in current graphics mode and
getmaxy
driver.
It changes the current drawing colour. Default colour is white. Each
setcolor color is assigned a number, like BLACK is 0 and RED is 4. Here we
are using colour constants defined inside graphics.h header file.
setfillstyle It sets the current fill pattern and fill color.
circle It draws a circle with radius r and centre at (x, y).
line It draws a straight line between two points on screen.
arc It draws a circular arc from start angle till end angle.
It is used to fill a closed area with current fill pattern and fill color. It
floodfill takes any point inside closed area and color of the boundary as
input.
cleardevice It clears the screen, and sets current position to (0, 0).
delay It is used to suspend execution of a program for a M milliseconds.
It unloads the graphics drivers and sets the screen back to text
closegraph
mode.
Group C
EXPERIMENT NO. 2
Aim: Write C++/Java program to draw implement Cube rotation about vertical axis passing
through its centroid.
Output: It displays the Cube rotation about vertical axis passing through its centroid.
Theory:
2D Rotation: In two dimensions, every rotation matrix has the following form,
This rotates column vectors by means of the following matrix multiplication,
3D ROTATION: A basic rotation (also called elemental rotation) is a rotation about one of
the axes of a Coordinate system. The following three basic rotation matrices rotate vectors
by an angle θ about the x, y, or z axis, in three dimensions, using the right-hand rule—which
codifies their alternating signs. (The same matrices can also represent a clockwise rotation
of the axes)
About x-axis:
About y-axis:
About z-axis:
x’ = x
y’ = ycosθ + zsinθ
z’ = ysinθ + zcosθ
x’ = xcosθ + zsinθ
y’ = y
z’ = -xsinθ + zcosθ
Conclusion : Hence we completed with Cube rotation about vertical axis passing through
its centriod.