Computer Graphics3
Computer Graphics3
Computer Graphics3
Coordinates Systems:
There are three types of coordinates systems to locate any point in the space: Cartesian, Cylindrical, Spherical coordinates.
1-
enter coordinates values, you indicate a point's distance (in units) and its direction (+ or -) along the x, y, and z axes relative to the coordinates system origin (0,0,0) or relative to the previous point.
72 Dr.Eng.Ziyad Al-Tai
2-D polar coordinates system uses a distance and an angle to locate a point. When you enter polar coordinates values, you indicate a point's distance from the origin or from the previous point and its angle along the (x,y) plane of the current coordinates system. Cylindrical coordinates entry is similar to 2-D polar coordinates entry, but with an additional distance from the polar coordinates perpendicular to the (x,y) plane. You locate a point by specifying its distance along relative to the x-axis and its z value perpendicular to the (x,y) plane as shown in following figure. (5<60,6) Y X 60o 5 Z 6 The point coordinate (5<60,6) indicates a point 5 units from the origin, 60 degrees from the x-axis in the (X,Y) plane, and 6 units along the z-axis. The coordinate (8<30,1) indicates a point 8 units from the origin in the (X,Y) plane, 30 degrees from the x-axis in the (X,Y) plane and 1 unit along the z-axis.
Spherical coordinate entry in 3-D is also similar to polar coordinate entry in 2-D. You can locate a point by specifying its distance from the origin, its angle from x-axis in the (x,y) plane, and its angle from the (x,y) plane. The coordinate (8<60<30) indicates a point 8 units from the origin, 60 degrees from the x-axis in the (x,y) plane, and 30 degrees up from the (x,y) plane as shown in figure below. (x,y)plane
1 2
74 Dr.Eng.Ziyad Al-Tai
1 2
=53.3(from xy-plane)
Vectors:
Vector is the difference between two points which the vector passes through these points as shown in the following example. Example: Find the vector which pass through the point p1(1,1,1) and the point p2(1,2,3)? V(1-1,2-1,3-1)=(0,1,2) - Let V1=(x1,y1,z1) and V2=(x2,y2,z2) be two three dimensional vectors. The dot product of these two vectors is defined as: V1.V2=x1x2+y1y2+z1z2 The dot product of two vectors is not a vectors but a real number (scalar). Example: If V1=(1,2,3) and V2=(-2,1,-4) then: V1.V2=1(-2)+2(1)+3(-4)=-12
75 Dr.Eng.Ziyad Al-Tai
Where V 1 is the length of the vector V1 and V 2 is the length of the vector V2, and V =
x2 + y2 + z 2 .
Example: Find the angle between the vector V1(1,0,0) and the vector V2(1,1,0)?
V = x 2 + y 2 + z 2 , 45
3
) 45
(0,0)
X1 a- Original figure
e Y
(translation) Y
Y1 .
76 Dr.Eng.Ziyad Al-Tai
(0,0)
X1
c- second step (rotation) Where the second coordinates system, denoted by (x1,y1) is at clockwise angle 45o wi3 R= EMBED Equation.3 A point P defined in the (x,y,z) coordinates system ha Y Y1 Y1 . (8,6) (5,3) 45 45 X X1 a- Original figure Y Y1 . Y1 b-First step (translation) (0,0) X . (3,3)
(0,0) X1 X c- second step (rotation) Where the second coordinates system, denoted by (x1,y1) is at clockwise angle 45o with the original coordinates system
77 Dr.Eng.Ziyad Al-Tai
(x,y). The steps of transforming coordinates system for the point (8,6) at figure (a) above in 2-D are: First step (shown at figure (b) above): is 2-D translation of second coordinates system (x1,y1) to first coordinates system (x,y) by:
0 0 1 0 1 0 Translate (-5,-3)= 5 3 1
Second step (shown at figure (c) above): is 2-D rotation of second coordinates system (X1,Y1) counterclockwise 45o by:
cos 45 sin 45 0 Rotate(45)= sin 45 cos 45 0 0 0 1
The above example can be extended to 3-D. Let a coordinates system (x1,y1,z1) be defined in terms of the standard (x,y, and z) coordinates by the unit vector: u=(ux,uy,uz), v=(vx,vy,vz), w=(wx,wy,wz) also assume the origin of the (x1,y1,z1) coordinates system is at (a,b,c) with respect to the (x,y,z) coordinates system as shown in figure below: Z Z1 W U X Y X1 V Y1
The transformation sends the (x1,y1,z1) coordinates system to the (x,y,z) system (with u going to x, v going to y, and w
78 Dr.Eng.Ziyad Al-Tai
A point P defined in the (x,y,z) coordinates system has representation P1 in (x1,y1,z1) coordinates system given by: P1=P Tr R Example: The coordinates of point P in terms of (x,y,z) is (0,0,5), find the coordinates of the same point in terms of (x1,y1,z1) using transforming coordinates system with center at (5,5,-5) as shown in figure below: (5,5,-5)
x1 (5,5,0)
z1
(10,5,-5)
y1
y x z
P(0,0,-5)
(5,0,-5)
79 Dr.Eng.Ziyad Al-Tai
P in terms of (x1,y1,z1)=P1=
0 1 0 1 Tr R= [ 0 0 5 1] =P 0 0 5 5 0 0 1 5 0 0 0 0 0 1 0 1 0 1 0 0 1 0 0 0 0 0 = [ 0 5 5 1] 0 1
80 Dr.Eng.Ziyad Al-Tai
A 3-D geometric transformations are extensions of the two dimensional transformations techniques as shown below:
1- 3-D Translation:
A 3-D object can be translated from one place to another by translating every point of the 3-D object to the new place as follows:
x =x+Tx , y =y+Ty , z =z+Tz
3-D Translation transformation can be represented in a uniform way by a 4 4 matrix as shown below:
1 0 0 0 1 0 z 1] 0 0 1 Tx Ty Tz 0 0 0 1
[x
z 1] = [ x
T=(Tx,Ty,Tz) z x
2- 3-D Scaling:
A 3-D object can be scaled as follows:
x =xSx , y =ySy , z =zSz
Where Sx, Sy, and Sz are scaling factors. 3-D scaling transformation can be represented in a uniform way by a 4 4 matrix as shown below:
81 Dr.Eng.Ziyad Al-Tai
[x
z 1] = [ x
Sx 0 0 0 0 Sy 0 0 z 1] 0 0 Sz 0 0 0 0 1
3- 3-D Rotation:
In order to rotate an object in 3-D world, the rotation axis and rotation angle must be specified firstly. Any of the three axes (x,y,z) may be the rotation axis. Rotation of a point (x,y,z) through a counterclockwise angle about the positive part of the axis, can be shown in following figures: y y y
x z
x z
x z
[x
z 1] = [ x
cos sin z 1] 0 0
sin cos 0 0
0 0 1 0
0 0 0 1
82 Dr.Eng.Ziyad Al-Tai
[x
z 1] = [ x
0 1 0 cos z 1] 0 sin 0 0
0 sin cos 0
0 0 0 1
[x
z 1] = [ x
cos 0 z 1] sin 0
0 sin 1 0 0 cos 0 0
0 0 0 1
H.W.:
Write complete (C or C++) program in order to perform all types of 3-D transformations on a cubic object (Use suitable vertices for the cubic object)?
Projections
83 Dr.Eng.Ziyad Al-Tai
It is easy to see a group of points in 2-D world and convert them onto computer screen. This is can be done by putting these points in a viewport with clipping processing for enhancement. In 3-D world the subject is different. In order to see 3-D object, there are different views such as: top view, side view, or front view. In addition, 3-D object must be processed with projections techniques in order to see it as a flat object on a 2-D screen. There are two methods for projecting 3-D object on 2-D plane:
1- Parallel Projection:
Parallel projection represents the 3-D object relatively; therefore this type is used with quick drawing (draft drawing). Parallel projection can give different views fro the 3-D object from different sides as shown in figure below:
84 Dr.Eng.Ziyad Al-Tai
Top view
Side view
Front view Note: parallel projection can not give a realistic representation for 3-D object.
85 Dr.Eng.Ziyad Al-Tai
1 0 [ Pz ] = 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Similarly, the matrices for projection onto the x=0 and y=0 planes are:
0 0 [ Px] = 0 0 1 0 [ Py ] = 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 1
Z x y
x y
86 Dr.Eng.Ziyad Al-Tai
A single orthographic projection does not provide sufficient information to visually and practically reconstruct the shape of an object. Consequently, multiple orthographic projections are necessary.
2- Perspective Projection:
Perspective projection gives a realistic representation for 3D object, but without real dimensions values.
Center of Projection
Projection plane
In above figure, there are two equal length lines, but with different perspective projections. The closer line to the projection plane is the larger projection length. To calculate the perspective projection lengths, the following equations are used:
87 Dr.Eng.Ziyad Al-Tai
d ) d+Z d Yp = Y ( ) d +Z Zp = 0 Xp = X (
Where x,y,and z: represent coordinates of a point in 3-D world P(x,y,z). Xp,Yp, and Zp: represent coordinates of a point in projection plane (Xp,Yp,0). d: the distance between 3-D coordinates of a point, and projection plane.
H.W.:
Find Perspective Projection of cubic object :((0,0,0), (5,0,0), (5,5,0), (0,5,0), (0,5,5), (0,0,5), (5,0,5), (5,5,5)). Note that d=5 units?
88 Dr.Eng.Ziyad Al-Tai