0% found this document useful (0 votes)
8 views

Unity University Department of Computer Science Individual Assignment Course: Computer Graphics Code: Cosc3062

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Unity University Department of Computer Science Individual Assignment Course: Computer Graphics Code: Cosc3062

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Unity University

Department of computer science


Individual assignment
Course: computer graphics
Code: cosc3062

Name: Esmael ali


Id.no. 04518/14
Section: 1

Submitted to: INS. Ketema


1. Draw the circle with r=12 using Bresenham algorithm and Draw the circle with r=14 and
center at (15, 10).

Circle with r=12:


- Center: (0, 0)
- Radius: 12
Using the Bresenham algorithm, we can find the points on the circumference of the circle. The
algorithm works by plotting points in one octant of the circle and then mirroring those points in
the other octants.

Iteration Steps:

1. x0=0x_0 = 0x0=0, y0=12y_0 = 12y0=12


2. Decision parameter d0=3−2rd_0 = 3 - 2rd0=3−2r
3. Loop through iterations adjusting xxx and yyy based on ddd
4. Plot points in all 8 octants using symmetry.

Calculated Points and Decision Parameters:

 Iteration 0: x0 = 0 , y0 = 12 , d = -21

 Iteration 1: x1 = 1 , y1 = 12 , d1 = -11

 Iteration 2: x2 = 2 , y2 = 12 , d2 = -1

 Iteration 3: x3 = 3 , y3 = 11 , d3 = 13

 Iteration 4: x4 = 4 , y4 = 11 , d4 = -3

 Iteration 5: x5 = 5 , y5 = 10 , d5 = 21

 Iteration 6: x6 = 6 , y6 = 10 , d6 = 5

 Iteration 7: x7 = 7, y7 = 9 , d7 = 33

 Iteration 8: x8 = 8, y8 = 9 , d8 = 25

Here are the coordinates for the circle with r=12:


(0, 12) (1, 12) (2, 11) (3, 10) (4, 9) (5, 8) (6, 7) (7, 6) (8, 5) (9, 4) (10, 3) (11, 2) (12,
1) (12, 0)
(12, -1) (11, -2) (10, -3) (9, -4) (8, -5) (7, -6) (6, -7) (5, -8) (4, -9) (3, -10) (2, -11) (1, -
12) (0, -12)
(-1, -12) (-2, -11) (-3, -10) (-4, -9) (-5, -8) (-6, -7) (-7, -6) (-8, -5) (-9, -4) (-10, -3) (-11, -
2) (-12, -1) (-12, 0)
(-12, 1) (-11, 2) (-10, 3) (-9, 4) (-8, 5) (-7, 6) (-6, 7) (-5, 8) (-4, 9) (-3, 10) (-2, 11) (-1,
12)

2. Draw the ellipse with Rx = 6, Ry = 8.


To draw a circle using the Bresenham algorithm, we need to determine the points on the
circumference of the circle based on the radius and the center coordinates. Let's draw the
circles you mentioned:
Circle with r=14 and center at (15, 10):
- Center: (15, 10)
- Radius: 14
We can use the same Bresenham algorithm to find the points on the circumference of this
circle. Here are the coordinates:

(15, 24) (16, 24) (17, 23) (18, 22) (19, 21) (20, 20) (21, 19) (22, 18) (23, 17) (24, 15)
(24, 14) (25, 13) (26, 12) (27, 11) (28, 9) (28, 8) (29, 7) (30, 6) (31, 5) (32, 3) (32, 2)
(33, 1) (34, 0) (34, -1) (35, -2) (36, -3) (37, -5) (37, -6) (38, -7) (39, -8) (40, -9) (41, -
11) (41, -12) (42, -13) (43, -15) (43, -16) (44, -17) (45, -18) (46, -19) (47, -21) (47, -22)
(48, -23) (49, -24) (49, -25) (50, -26) (51, -28) (51, -29) (52, -30) (53, -31) (53, -32) (54, -
33) (55, -34) (56, -36) (56, -37) (57, -38) (58, -39) (58, -40) (59, -41) (60, -42) (61, -43)
(62, -45) (62, -46) (63, -47) (64, -48) (64,

3. Draw the ellipse with Rx = 14, Ry = 10 and center at (15, 10)


4. Consider a line from A (5, 7) to B (10, 15). Use the DDA line drawing algorithm rasterize the
line from A to B. Draw the pixel wise rasterization of Line.
The DDA (Digital Differential Analyzer) algorithm is used to draw lines on raster displays. Here’s how you can use
the DDA algorithm to rasterize the line from point A (5, 7) to point B (10, 15):

Steps of the DDA Algorithm


Calculate the differences:
𝑑𝑥=𝑥1−𝑥0=10−5=5
𝑑𝑦=𝑦1−𝑦0=15−7=8
Determine the number of steps
Steps= max (∣𝑑𝑥∣, ∣𝑑𝑦∣) =max⁡(5,8)=8
Calculate the increments:
X increment= steps 𝑑𝑥 =5/8=0.625

Y increment= steps Dy =8/8=1

Initialize starting points:


x=x0=5
y=y0=7

Rasterize the line:


For each step, calculate the next point and round to the nearest integer.
Calculation of the Points

Step 𝑥 y Rounded x Rounded 𝑦 Plotted Point


1 5.000 7.000 5 7 (5, 7)
2 5.625 8.000 6 8 (6, 8)
3 6.250 9.000 6 9 (6, 9)
4 6.875 10.000 7 10 (7, 10)
5 7.500 11.000 8 11 (8, 11)
6 8.125 12.000 8 12 (8, 12)
7 8.750 13.000 9 13 (9, 13)
8 9.375 14.000 9 14 (9, 14)
9 10.000 15.000 10 15 (10, 15)
15

14

13

12

11

10

0
5 6 7 8 9 10 11 12 13

5. To translate the circle with center coordinates (1, 4) by a distance of 5 units towards
the X-axis and 1 unit towards the Y-axis, we use the translation equations:

X' x + xx
Y'= y + Ty

where Tx = 5 and Ty 1.

Applying the translation to the center coordinates (1, 4):


X'=1+5=6
Y'=4+1 = 5

So, the new center coordinates of the circle after translation are (6, 5).

The radius of the circle remains unchanged.

Therefore, the new coordinates of the circle C are:


Center: (6, 5)
Radius: 10
The translated circle has the same radius of 10 but is now centered at (6, 5).

6. To apply the translation with a distance of 6 towards the X-axis and 3 towards the Y-
axis to a square with vertices at A (0, 3), B (3, 3), C (3, 0), and D (0, 0), we use the
translation equations:

X'=X + Tx
Y'=Y + Ty

where Tx = 6 and Ty = 3.

Let's translate each vertex:

1. For the vertex A(0, 3):

X'=0+6=6
Y'=3+3=6

New vertex: (6, 6)

2. For the vertex B(3, 3):

X'=3+6=9
Y'=3+3=6

New vertex: (9, 6)

3. For the vertex C(3,0):


X'=3+6=9
Y'=0+3=3
New vertex: (9, 3)

4. for the vertex D (0, 0):


X'=0+6=6
Y'=0+3=3
New vertex: (6, 3)
Thus, after translating the square by (Tx , Ty) = (6, 3), the new vertices of the square are:
A'(6, 6)
B'(9, 6)
C'(9, 3)
D'(6, 3)
These new coordinates represent the vertices of the translated square.

7. Given a triangle with corner coordinates (0, 0), (1, 0) and (1, 1).Rotate the triangle by 30 and
45 degree anticlockwise direction and find out the new coordinates
cos θ −sinθ
R(θ ) = [
sin θ cos θ ]
Rotating by 30o
√3 −1
o o
cos 30 −sin 30 2 2
o
R(30 ) = [ sin θ 30o cos θ 30 o ]=[ 1 √3 ]
2 2

Apply the rotation matrix to each vertex of the triangle.

For Point (0, 0): For Point (1, 0):


√3 −1 √3 −1 √3
2 2 0 0 2 2 1 2
[ 1 √3 ][ ]=[ ]
0 0 [ 1 √3 ][ ]=[
0 1 ]
2 2 2 2 2
√3 1
New Coordinates (0 , 0) New Coordinates ( 2 , 2 )

For Point (1, 1):

√3 −1 √3 −1 √3−1
2 2 1 2 2 2
[ 1 √3 ] [ ] =[
1 1 √3 ]= [ √ 3+1 ]
2 2 2 2 2
√3−1 , √3+ 1
New Coordinates ( 2 2 )
Rotating by 45o
√2 −√ 2
o o
cos 30 −sin 30 2 2
o
R(45 ) = [ sin θ 30o cos θ 30 o ]=[ √2 √2 ]
2 2

Apply the rotation matrix to each vertex of the triangle

For Point (0,0): For Point (1,0):


√2 −√ 2 √2 −√ 2 √2
2 2 0 0 2 2 1 2
[ √2 √2 ] [ 0] = [ 0] [ √2 √2 ] [ 0] = [ √2 ]
2 2 2 2 2
√2 √ 2
New Coordinates (0 , 0) New Coordinates ( 2 , 2 )

For Point (1,1):


√2 −√ 2 √2 −√ 2
2 2 1 2 2 0
[ √2 √2 ][ ] [
1 = √2 +√ 2 ] = [ √2 ]
2 2 2 2

New Coordinates (0 , √ 2)

8. Show that the composition of two rotations is additive by concatenating the matrix
representations for R (β1) and R (β2) to obtain R (β1). R (β2) = R (β1) + R (β2).
Let's denote R(β1) as R1 (β2) as R2
cos θ −sinθ
R(θ ) = [ sin θ cos θ ]
Now, for R1 and R2, we have:
cos (β 1)
R(1) = [ sin (β 1)
¿ ]
cos (β 2)
R(2) = [ sin (β 2)
¿ ]
Now, let's multiply these matrices:
cos (β 1) cos (β 2)
R1 ⋅ R2 = [ sin (β 1)
¿ ]⋅[ sin (β 2)
¿ ]
R1 ⋅ R2 = [ ¿]
cos (β 1+ β 2)
R1 ⋅ R2 = [ sin (β 1+ β 2)
¿ ]
This matrix represents the rotation R(β 1+ β 2), which shows that the composition of two
rotations is additive. Thus, R1⋅R2= R(β 1+ β 2),

9.

Shearing and Reflection Transformations in 2D and 3D


Transformations are fundamental operations in computer graphics used to manipulate the
position, size, and orientation of objects. Two such transformations are shearing and reflection,
which can be applied in both 2D and 3D spaces.

Shearing

 Concept: Shearing distorts an object by tilting it along a specific axis. Imagine sliding
layers of the object sideways relative to each other.
 2D Shearing: There are two types of shearing in 2D:
o X-shear: This slants the object along the x-axis. Points are shifted horizontally
based on their original y-coordinate.
o Y-shear: This slants the object along the y-axis. Points are shifted vertically
based on their original x-coordinate.
 3D Shearing: Similar to 2D, 3D shearing can be applied along any of the three axes (x,
y, or z). Here, the concept remains the same, but we're dealing with changes in all three
coordinates.

Reflection

 Concept: Reflection creates a mirror image of an object across a specific line (axis in 2D,
plane in 3D).
 2D Reflection: Reflection can be performed across the x-axis, y-axis, or any line defined
by an equation. The object is flipped so corresponding points on either side of the
reflection line are mirrored.
 3D Reflection: Reflection in 3D happens across a plane. We can reflect across the xy-
plane (mirroring on the ground), yz-plane (mirroring on a side wall), or any plane defined
by an equation.

Here's a table summarizing the key points:

Feature Shearing Reflection


Purpose Tilts/slants the object Creates a mirror image
2D Types X-shear, Y-shear Across x, y-axis, or any line
3D Types X, Y, Z-axis shearing Across xy, yz, zx planes, or any defined plane
Effect on size Distorts the shape Maintains original size

Applications

Shearing and reflection are used in various graphics applications:

 Shearing: Used for creating parallelogram shapes, simulating wind effects on trees, or
animating object deformations.
 Reflection: Creating realistic water surfaces, mirroring objects, or adding special effects
like portals.

By combining these transformations with others like rotation, scaling, and translation, we
achieve a wide range of effects in computer graphics and animation.
10.

The new coordinates of the vertices after the rotation are:

1. \ (O (0, 0, 0)\) → \ ((0, 0, 0)\)

2. \ (A (0, 4, 0)\) → \ ((0, 4, 0)\)

3. \ (B (0, 4, 4)\) → \ ((2.828, 4, 2.828)\)

4. \ (F (0, 0, 4)\) → \ ((2.828, 0, 2.828)\)

5. \ (E (4, 0, 0)\) → \ ((2.828, 0, -2.828)\)

6. \(C (4, 4, 0)\) → \ ((2.828, 4, -2.828)\)


7. \ (D (4, 4, 4)\) → \ ((5.656, 4, 0)\)

8. \ (G (4, 0, 4)\) → \ ((5.656, 0, 0)\)

You might also like