Documente Academic
Documente Profesional
Documente Cultură
Computer--Aided Mechanical
Computer Programming
Design
• Graphics library
• Coordinate systems
Graphics Programming
1
History of Graphics Library
• CORE Graphics System (1977) by the Special Interest Group
on Computer Graphics.
• Calculate the projections of the object points on the – u-axis directing the right
– v-axis directing up
monitor system.
– Range of u and v from 0 to 1
2
Viewing Coordinate System Viewing Coordinate System
• Projection Types
• Origin is located at the viewsite
– Perspective
• Z-axis pointing to the viewpoint from the origin
– Parallel
• Screen is perpendicular to z-axis
3
Coordinate Transformation Common Coordinate
(Page 54 – 65) Transformation
• Translation
• Rotation
• Scaling
• Mirror-Reflection
Translation Translation
• In a coordinate system, when an object moves from Suppose an object moves from point V(x, y, z) by (dx, dy,
dz) to point V’(x’, y’, z’), the coordinate of V’ can be found
one location to a new location without changing its
as:
orientation, its motion is called translation. z
V’ ⎡ x ' ⎤ ⎡ x ⎤ ⎡d ⎤
⎢ y '⎥ = ⎢ y ⎥ + ⎢ d ⎥
x
• The coordinate of the new location can be calculated V dz
with a translation matrix. o
y ⎢ ⎥ ⎢ ⎥ ⎢ y ⎥
⎢⎣ z ' ⎥⎦ ⎢⎣ z ⎥⎦ ⎢⎣ d ⎥⎦
dy dx
z
x
⎣1 ⎦ ⎣⎢0 0 0 1 ⎦⎥ ⎣1 ⎦
• They unify the treatment of common graphical
transformations and operations.
Dummy (n+1)th coordinate to facilitate multiplication
4
Rotation Rotation
An object rotates around the x-axis from a point P to P’ in
Suppose an object rotates around the z-axis from a point
a coordinate system, the rotation is shown in the
P (x, y, z) to P’ (x’, y’, z’) in a coordinate system, the
following diagram and the coordinate of point P’ can be
coordinate of point P’ can be found as:
found.
y
P’ (x’, y’, z’) z' = z
P (x, y, z)
x ' = x cosθ − y sin θ
θ
φ x y ' = x sin θ + y cosθ
o
⎡ x ' ⎤ ⎡cosθ − sin θ 0⎤ ⎡x⎤ The rotation transformation matrix about x-axis:
⎢ y '⎥ = ⎢sin θ cosθ 0⎥ ⎢ y ⎥
⎢ ⎥ ⎢ ⎥⎢ ⎥
⎣⎢ z ' ⎦⎥ ⎣⎢ 0 0 1 ⎦⎥ ⎣⎢ z ⎦⎥
⎡ x ' ⎤ ⎡1 0 0 0⎤ ⎡ x ⎤
The rotation transformation matrix about z-axis: ⎢ y '⎥ ⎢0 cosθ − sin θ 0⎥ ⎢ y ⎥
⎢ ⎥=⎢ ⎥⎢ ⎥
⎡ x ' ⎤ ⎡ cos θ − sin θ 0 0⎤ ⎡ x ⎤
⎢ z ' ⎥ ⎢0 sin θ cosθ 0⎥ ⎢ z ⎥
⎢ y '⎥ ⎢ sin θ cosθ 0 0⎥ ⎢ y ⎥
⎢ ⎥=⎢ ⎥⎢ ⎥ ⎢ ⎥ ⎢ ⎥⎢ ⎥
⎢ z '⎥ ⎢ 0 0 1 0⎥ ⎢ z ⎥ ⎣ 1 ⎦ ⎣0 0 0 1⎦ ⎣ 1 ⎦
⎢ ⎥ ⎢ ⎥⎢ ⎥
⎣1⎦ ⎣ 0 0 0 1⎦ ⎣ 1 ⎦
⎡ x ' ⎤ ⎡ cosθ i θ
z
0 sin 0⎤ ⎡ x ⎤
⎢ y '⎥ ⎢ 0 ⎡ x ' ⎤ ⎡s 0 0 ⎤ ⎡ x ⎤
0⎥ ⎢ y ⎥
P’
⎢ y '⎥ = ⎢ 0 s 0 ⎥ ⎢ y ⎥
x
1 0 P
⎢ ⎥=⎢ ⎥⎢ ⎥ y
⎢ ⎥ ⎢ ⎥⎢ ⎥
o
⎢ z ' ⎥ ⎢ − sin θ 0 cosθ 0⎥ ⎢ z ⎥
y
z
⎣⎢ z ' ⎦⎥ ⎢⎣0 0 s ⎥⎦ ⎢⎣ z ⎦⎥
y z’
⎢ ⎥ ⎢ ⎥⎢ ⎥ z
⎣1⎦ ⎣ 0 0 0 1⎦ ⎣ 1 ⎦ x y’
5
Scaling Transformation Matrix Mirror--Reflection
Mirror
Transformation Matrix
⎡ x '⎤ ⎡S x
0 0 0⎤ ⎡ x ⎤ This transformation matrix is for the mirror reflection in
⎢ y '⎥ ⎢ 0 S 0 0⎥ ⎢ y ⎥
⎢ ⎥=⎢ y
⎥⎢ ⎥ term of xy plane.
⎢ z '⎥ ⎢ 0 0 S 0⎥ ⎢ z ⎥
⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎡ x ' ⎤ ⎡1 0⎤ ⎡ x ⎤
z
0 0
⎣1⎦ ⎣0 0 0 1⎦ ⎣ 1 ⎦ ⎢ y '⎥ ⎢ 0 1 0⎥ ⎢ y ⎥
0
⎢ ⎥=⎢ ⎥⎢ ⎥
This transformation matrix is used when the object is
⎢ z ' ⎥ ⎢0 0 −1 0⎥ ⎢ z ⎥
⎢ ⎥ ⎢ ⎥⎢ ⎥
scaled in term of the origin. ⎣ 1 ⎦ ⎣0 0 0 1⎦ ⎣ 1 ⎦
q
transformation matrices in the same sequence. coordinate is ((0,0,1)
, , ) in its model coordinate system
y at beginning.
g g
P ' = [ H ][ H
n n −1
] [ H ]P
1
6
Mapping Problem of Mapping
Corresponding to the viewpoint (-10,0,1), the viewsite (0,0,1), and the
Known:
up vector (0,0,1), the viewing coordinate system is drawn a shown in
1. Two coordinate systems, X1-Y1-Z1 and X2-Y2-Z2.
2. The coordinate of P in the system, X1-Y1-Z1. the accompanying figure. Note that all the coordinate and component
values are given in the world coordinates. From the relative position
Question: between the viewing coordinate system and the world coordinate
Calculate the coordinate of P in the system, X2-Y2-Z2
system,
Problem of Mapping
The viewpoint and the viewsite are set at (5,5,5) and Hidden-Line and Hidden-
Hidden- Hidden-
(0,0,0), respectively, to draw an isometric view, and the up
Surface Removal
vector is chosen to be (0,0,1). Derive the mapping
transformation matrix and the viewingg coordinates of a
point represented by (0,0,5) in the world coordinates.
7
Depth--Sorting Algorithm
Depth
Back--Face Removal Algorithm
Back
1. The surfaces of the objects are sorted by distance from
• The algorithm can be applied on an object bounded by
the viewer (z coordinate in the viewing system)
planar faces.
• The maximum z of a surface is smaller than the minimum z of
• The algorithm can be applied only to one convex object. the other surface.
g of z values of a surface overlaps with that of the
• The range
• The algorithm cannot handle an object shown
shown. others.
2. The surfaces are filled with different colors from the
farthest to the nearest face.
3. If two surfaces occupy the same region on screen, the
nearer surface (with the larger z coordinate) hides the
further surface.
– Step 4: Project the edge and the face to determine Z-buffer Method
whether they are overlap.
• No overlap • Principle: Any region of the screen is occupied by an
entity closest to the viewer. (Same as depth-sorting
• Overlap
algorithm)
• The amount of memory can hold a real for each pixel.
Find the visible segments and add they to the list. Then repeat
step 3 on these segments.
8
Procedure of Z-
Z-buffer Method
• Step 1: project a face. The memories of the projection are set
to the z values of the corresponding points on the face. Pixels
are colored with the color of the face. Rendering
• Step 2: the next face is projected. Compare the z values of the
projection pixels with their current values.
values The larger values
(Page 71 – 77)
will stay, and the color is the same as the face color with the
larger z value.
• Step 3: repeat step 2 on the
other faces.
Rendering Shading
• Rendering is a process of recreate the effects of light on • Each pixel is colored with the color and the intensity
surfaces of objects. of reflected light at the point of the surface.
• Shapes, textures, and colors of objects are determined • Light sources: direct illumination and ambient
from the reflected light. illumination.
illumination
• Some rendering functions are provided in the graphics
library.
• Two major rendering technologies: shading and ray
casting.
0
specular reflection.
KE
R = ( N iL )
d p
D+D
d
9
Intensity of Reflected Light
E
I=K I + p
[ K ( N i L) + K (V i R) n
]
D+D
d a d s
10