Sunteți pe pagina 1din 10

Basic Concepts of Graphics

Computer--Aided Mechanical
Computer Programming
Design
• Graphics library

• Coordinate systems

Chevy Z. Chen, Ph.D. • Coordinate transformation

Department of Mechanical and Industrial Engineering • Hidden-line and hidden-surface removal


Concordia University • Rendering

Graphics Programming

• Graphics programming includes graphics input and


output.
Graphics Libraries
• Some basic graphics software is required for graphics
(P
(Page 36 -38)
38)
programming.

• Graphics software is classified into two groups: device


drivers and graphics libraries.

Programming with Device Drivers Programming with Graphics Libraries


• A graphics library is a set of subroutines; each subroutine
• A device driver is a set of machine-dependent codes
has a specific function.
that directly controls the display processing unit of a
• Each subroutine consists of a set of device driver
graphics device.
commands.
• A graphics program need to be rewritten when a
• Subroutine names and parameters vary among the
different graphics device is used.
graphics libraries.
• Graphics programs are very long and their readability is • A graphics library is bundled with a limited number of
poor. different device drivers.

1
History of Graphics Library
• CORE Graphics System (1977) by the Special Interest Group
on Computer Graphics.

• Graphics Kernel System (GKS) and GKS-3D by the


Coordinate Systems
I t
International
ti l Standards
St d d O Organization.
i ti (P
(Page 38 – 47)
• Programmer’s Hierarchical Interactive Graphics System
(PHIGS) and PHIGS Extension to X (PEX)

• OpenGL - an extension of GL (a proprietary graphics library


for Silicon Graphics machines).

Image Display Procedure Coordinate Systems of Graphic


Devices
• Specify the points on an object in a spatial coordinate • Device Coordinate System
system.

• Understand the position relationship between the


spatial system and the monitor coordinate system on
• Virtual Device Coordinate System
the display monitor. – Origin at the lower left corner of the display monitor

• 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

World and Model Coordinate


Coordinate Systems for Objects
Systems

• World Coordinate System

• Model Coordinate System

• Viewing Coordinate System

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

• Y-axis (up vector) is parallel with the up direction on


the screen

• X-axis is the cross product of y and z-axis.

Relationship among Coordinate Window


Systems
• A window defines the
region in the virtual
device coordinate system
(on the screen) in which
the projections of objects
are shown.
• The view volume is
depends on the type of
projection.

Viewport Image Display Procedure


• A viewport is the area on the display screen where
the projections (images) of the objects appear.

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

Homogeneous Coordinates Homogeneous Transformation


Matrix
• Homogeneous coordinates have a natural application The translation operation can be expressed in the from of
to Computer Graphics; matrix multiplication with homogeneous representation.

• They form a basis for the projective geometry used ⎡ x ' ⎤ ⎡1 0 0 d ⎤ ⎡x ⎤


x

extensively to project a three-dimensional scene onto


⎢ y '⎥ ⎢ 0 1 0 d ⎥⎥ ⎢ y ⎥
⎢ ⎥=⎢ y
⎢ ⎥
a two dimensional image plane. ⎢ z ' ⎥ ⎢0 0 1 d ⎥ ⎢z ⎥
⎢ ⎥ ⎢ ⎥⎢ ⎥
z

⎣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

Rotation Transformation Matrix Rotation Transformation Matrix


The matrix form of the previous equations:

⎡ 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 ⎦

Rotation Transformation Matrix Scaling


We can change the scales in x, y, and z-axis by
The rotation transformation matrix about y-axis: multiplying the factors, Sx, Sy, and Sz, respectively.

⎡ 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 ⎦

Transformation Concatenation Problem of Transformation


An object at the origin of a world coordinate system is translated by 5
In a transformation process, the equivalent transformation
units in the y axis of the system, then rotated counter clockwise by 90
matrix of the process is the multiplication of the associated degrees about the x axis of the system. If a point on the object whose

q
transformation matrices in the same sequence. coordinate is ((0,0,1)
, , ) in its model coordinate system
y at beginning.
g g

What is the coordinate of the point after the transformations?


If the first transformation matrix is [H1], the second is [H2],

the nth transformation matrix is [Hn], the equivalent

transformation matrix is:

P ' = [ H ][ H
n n −1
] [ H ]P
1

Problem of Transformation Mapping


An object is rotated about an axis by 90 degrees; this axis is parallel
• To calculate the
to the x axis of the world coordinate system and passes through a
coordinate of a point in a
point (0,3,2) in the system. If the coordinate of a point on the object
system based on a known
is (0,0,1)
(0 0 1) in the model coordinate system,
system what is the coordinate of
coordinate of the same
this point in the world coordinate system after the rotation?
point in a different system.

• Mapping is different from


transformation.

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,

• calculate the mapping


transformation
• calculate the coordinate of a point
in viewing coordinate if it has the
world coordinate (5,0,1)?

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.

Hidden--Line Removal Methods


Hidden Back--Face Removal Algorithm
Back
• A face of an object is visible if the normal vector of the
• Back-Face Removal Algorithm face points outside of the object toward the viewer;
otherwise the face is invisible.
• Depth-Sorting
p g ((Painter’s)) Algorithm
g

• Hidden-Line Removal Algorithm If M•N > 0, then the face is visible;


If M•N = 0, then the face is displayed
• Z-buffer Method
as a line;
If M•N < 0, then the face is invisible.

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.

Hidden--Line Removal Algorithm


Hidden – Step 2: the edges of the faces in FACE-TABLE are
collected and stored as a list. Then the edges are
tested in sequence to determine whether they are
• The algorithm can eliminate all hidden lines obscured by each face in FACE-TABLE.
regardless of the number and the convexity of – Step 3: Compare the z-value range of an edge and
objects, and the existence of curved faces. the ranges of the faces.
• The edge is in front of a face
• Algorithm Procedure • The edge is behind of a face
– Step 1: the faces pointing to the viewer are collected • The edge passes a face

and stored in an array (FACE-TABLE). The


maximum and minimum z values of each face are
stored.

– 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.

– Step 5: The edges passing the test are collected to


form the visible edges.

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.

Intensity of Reflected Light Intensity of Reflected Light


• Intensity of the reflection of the ambient illumination
Intensity of specular reflection:
R = K I a a a
E
R = K (V i R )
p n

• Reflection of direction illumination: Diffuse and D+D


d s

0
specular reflection.

Intensity of diffuse reflection:

KE
R = ( N iL )
d p

D+D
d

9
Intensity of Reflected Light

Intensity of the reflection:

E
I=K I + p
[ K ( N i L) + K (V i R) n
]
D+D
d a d s

10

S-ar putea să vă placă și