Anda di halaman 1dari 41

Me 502 Advanced Cad / CAM

Week # 2 Background Material

Geometry
Vector Algebra
Raster Graphics

Mastering CAD / CAM Ibrahim Zeid


INSTRUCTOR: DR. KUNWAR FARAZ AHMED
Lecture Sequence

Geometry
- What is
Geometry?
Geometry
What is Geometry?
Ancient branch of mathematics
Euclidean geometry deals with (measurement of)
distance, angle, area and volume.
Geometry is the study of Manifolds (spaces) Riemann
Geometry
Geometry is the study of those properties that are
invariant when the elements (points) are subjected to the
transformation of a given transformation group Kleins
geometry.
Affine geometry deals with points, lines etc. Affine space
is a set acted on by vector space.
Projective geometry includes all the above and in addition
a line at infinity.

Dr Kunwar Faraz Ahmed 2


Lecture Sequence

Geometry
What is Geometry?
Intuitive Geometry
Geometry
Intuitive Geometry
Consider the following rectangular piece of paper. Is it possible
to make a regular pentagon without using compass or any other
instruments?

Dr Kunwar Faraz Ahmed 3


Lecture Sequence

Geometry
What is Geometry?
Intuitive Geometry
Geometry
Limits of Intuitive Geometry?
Consider the problem of counting the diagonals in a
polygon. To what extent our intuition can stretch?

n(n-3)/2

Dr Kunwar Faraz Ahmed 4


Lecture Sequence

Geometry
What is Geometry?
Intuitive Geometry
Geometry
Computational
Geometry Limits of Intuitive Geometry?
Using finite precision
computing leads to
approximations and
incorrect answers.
We generally assume
geometric calculations to
be exact. However, it is
not so in computational
geometry. Consider the
following example

Consider a pentagon P in the plane. We draw the five diagonals of P; their intersections
define a contained, smaller pentagon Q. Let us call the operation of passing from P to Q
going in, and write symbolically Q = in(P ). Similarly, we extend the five sides of P to their
intersections, thus obtaining a larger pentagon Q that contains P. We call this operation
going out, and write Q = out(P ). Clearly, P = out(in(P )) and P = in(out(P )); see Figure
Beginning with P; let us iterate the going in operation m times, obtaining Q = in m (P ); and
then compute P = outm (Q). Ideally, the coordinates of the vertices of P and of P should
be equal. In practice, they may differ by a large error, even for small values of m..
Dr Kunwar Faraz Ahmed 5
Lecture Sequence

Geometry
Vector Algebra
Position Vector
Vector Algebra
Position Vector
A vector is an ordered triple
(a, b, c) where a, b, c are
real numbers. Also, ai + bj + Y
ck in component form where
P ( x, y , z ) x 2 y 2 z 2
i, j, k are unit vectors.

A position vector P(x, y,


X
z) implies a vector from
the origin (0, 0, 0) to the
point (x, y, z)
Z
Magnitude or Norm of
P is given by
P P x2 y2 z 2

Dr Kunwar Faraz Ahmed 6


Lecture Sequence

Geometry
Vector Algebra
Position Vector
Vector Algebra
Unit Vector /
Component Form Unit Vector and Component Form
The vector P(x, y, z) = xi + yj + zk can be pictorial
represented with respect to the Cartesian coordinate system
as follows. Y

P ( x, y , z )
j

k i X

Z zk

P( xi , y j , z k ) yj

xi

Dr Kunwar Faraz Ahmed 7


Lecture Sequence

Geometry
Vector Algebra
Position Vector
Vector Algebra
Unit Vector /
Component Form
Basic Terms
Basic Terms

A null vector (0,0,0)
0

P(x, y, z), x, y, z are called components of P.



A vector is denoted P or P (bold italic face) in print
Two vectors are equal if

Iff
Product of a scalar and a vector

Vector Addition: Consider 2 vectors

Dr Kunwar Faraz Ahmed 8


Lecture Sequence

Geometry
Vector Algebra
Position Vector
Vector Algebra
Unit Vector /
Component Form
Basic Terms
Basic Terms
Triangle Inequality

The Dot Product

Some Results

Dr Kunwar Faraz Ahmed 9


Lecture Sequence

Geometry
Vector Algebra
Position Vector
Vector Algebra
Unit Vector /
Component Form
Basic Terms
Basic Terms
The Cross Product

Some Results

Dr Kunwar Faraz Ahmed 10


Lecture Sequence

Geometry
Vector Algebra
Position Vector
Vector Algebra
Unit Vector /
Component Form
Basic Terms
Basic Terms
Points and Vectors

A vertex or point denotes location whereas a vector has


length (magnitude) and direction

Dr Kunwar Faraz Ahmed 11


Lecture Sequence

Geometry
Vector Algebra
Position Vector
Vector Algebra
Unit Vector /
Component Form
Basic Terms
Basic Terms
Barycentric Conditions

For vectors both addition and subtraction are defined


Whereas for vertices (points) it results in convex
combination
This leads to the definition of convex hull of point sets

Dr Kunwar Faraz Ahmed 12


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Matrix Algebra
Matrix Addition
Matrix Addition
Consider the following 2 x 2 matrices

Matrix Addition

Dr Kunwar Faraz Ahmed 13


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Matrix Algebra
Matrix Addition
Matrix
Multiplication
Matrix Multiplication
Multiplication by a scalar quantity

Multiplication of 2 matrices

Defined for matrices of r x c, c x r dimensions


This operation is comparable to vector dot product

Dr Kunwar Faraz Ahmed 14


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Matrix Algebra
Matrix Addition
Matrix
Multiplication
Matrix Multiplication
Transpose of a matrix Reflection along leading diagonal

Identity matrix

Every matrix has a transpose. If A t =A -1 , such a matrix is


called orthonormal

Dr Kunwar Faraz Ahmed 15


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Graphics Standards
Graphics Standards
Schematic Diagram Schematic Diagram

Dr Kunwar Faraz Ahmed 16


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Graphics Standards
Graphics Standards
Schematic Diagram
Types of Standards
Types of Standards
GKS an ISO and ANSI standard. Device independent host
system independent and application independent
PHIGS Programmers Hierarchical interactive Graphics
System
VDM Virtual Device Metafile. Defines the function to
represent a picture.
VDI Virtual Device Interface. Lies between GKS and
PHIGS
IGES initial graphics exchange specification. It is an
ANSI standard
NAPLPS North American Presentation Level Protocol
Syntax

Dr Kunwar Faraz Ahmed 17


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Coordinate Systems
Graphics Standards
Coordinate Systems
Types of Systems
Types of Systems
Three types of coordinate systems are generally used in
CAD/CAM operations
Model Coordinate System (MCS) or Database CS/
World CS
Working Coordinate System (WCS)
Screen Coordinate System (SCS) or Device CS

Dr Kunwar Faraz Ahmed 18


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Coordinate Systems
Graphics Standards
Coordinate Systems
Types of Systems
Model Coordinate System
o Model Coordinate
System
It is the reference space of the model with respect to which
all the model geometrical data is stored. It is a Cartesian
system with its X, Y, Z aligned with the characteristics
dimension of the model under consideration. The choice of
origin is arbitrary

Dr Kunwar Faraz Ahmed 19


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Coordinate Systems
Graphics Standards
Coordinate Systems
Types of Systems
Working Coordinate System
o Model Coordinate
System
This is basically an auxiliary coordinate system used in
o Working place of MCS. For convenience while we develop the
Coordinate
System geometry by data input this kind of coordinate system is
useful. It is very useful when a plane (face) in MCS is not
aligned along any orthogonal planes. It is a user defined
system that facilitates the geometrical construction.

While user inputs data in WCS the software transforms it to


MCS
Dr Kunwar Faraz Ahmed 20
Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Coordinate Systems
Graphics Standards
Coordinate Systems
Types of Systems
Screen Coordinate System
o Model Coordinate
System
In contrast to MCS and WCS, Screen Coordinate System is
o Working a two-dimensional device-independent system whose origin
Coordinate
System is usually located at the lower left corner of the display
o Screen
Coordinate screen.
System
The SCS is important for display, screen input and digitizing
tasks.

For Raster Graphics, the pixel grid serves as the range of


SCS. For a 1024x1280, the range is (0,0) to (1024,1280)

Dr Kunwar Faraz Ahmed 21


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Coordinate Systems
Graphics Standards
Coordinate Systems
Types of Systems
Digital Image
Digital Image We know that the SCS is important for display, screen input
and digitizing tasks.
A digital image or image on the screen is represented using
pixels.
The size of representation depends on the size of the image,
the horizontal and the vertical resolution of the screen which
are usually indicated as so many pixels per unit length. E.g.
dots per inch, pixels per inch etc.

Dr Kunwar Faraz Ahmed 22


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
Ideal Line
Ideal Line
We can only do a discrete approximation

Illuminate pixels as close to the true path as possible,


consider bi-level display only
Pixels are either lit or not lit

Dr Kunwar Faraz Ahmed 23


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
Ideal Line
Ideal Line
Must appear straight and continuous
Only possible axis-aligned and 45o lines
Must interpolate both defining end points
Must have uniform density and intensity
Consistent within a line and over all lines
What about antialiasing?
Must be efficient, drawn quickly
Lots of them are required!!!

Dr Kunwar Faraz Ahmed 24


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
Ideal Line - Algorithm
Ideal Line
Programmer specifies (x,y) values of end pixels
Need algorithm to figure out which intermediate pixels are
on line path
Pixel (x,y) values constrained to integer values
Actual computed intermediate line values may be floats
Rounding may be required. E.g. computed point
(10.48, 20.51) rounded to (10, 21)
Rounded pixel value is off actual line path (jaggy!!)
Sloped lines end up having jaggies
Vertical, horizontal lines, no jaggies

Dr Kunwar Faraz Ahmed 25


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
Ideal Line - Algorithm
Ideal Line 8

7
6
5
4
?
3
2
1

0 1 2 3 4 5 6 7 8 9 10 11 12

Line: (3,2) -> (9,6)


Which intermediate pixels to turn on?

Dr Kunwar Faraz Ahmed 26


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
Ideal Line
Ideal Line Based on slope-intercept algorithm from algebra:
y = mx + b
Simple approach:
increment x, solve for y
Floating point arithmetic required
dy y1 y0
m
dx x1 x0
62 4
0.67 (x1,y1)
93 6
b y0 m * x0 dy
2 0.67 * 3 0
(x0,y0)
dx

Dr Kunwar Faraz Ahmed 27


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
DDA Algorithm
Ideal Line DDA Line Drawing Algorithm (Case a: m < 1)
DDA Algorithm y k 1 y k m
(x1,y1) x = x0 y = y0
x = x0 + 1 y = y0 + 1 * m
=3+1=4 = 2 + 0.67 = 2.67
Illuminate pixel (x, round(y)) = (4, 3)
x=x+1 y=y+1*m
=4+1=5 = 2.67 + 0.67
= 3.34
Illuminate pixel (x, round(y)) = (5, 3)
x=x+1 y=y+1*m
=5+1=6 = 3.34 + 0.67
= 4.01
Illuminate pixel (x, round(y)) = (6, 4)
(x0, y0) x=x+1 y=y+1*m
=6+1=7 = 4.01 + 0.67
Line: (3,2) -> (9,6) = 4.68
m = 0.67 b = 0.0 Illuminate pixel (x, round(y)) = (7, 5)
Until x = = x1
Dr Kunwar Faraz Ahmed 28
Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
Ideal Line
Ideal Line It seems to work okay for lines
with a slope of 1 or less,
but doesnt work well for lines
with slope greater than 1 lines
become more discontinuous in
appearance and we must add
more than 1 pixel per column to
make it work.
Solution? - use symmetry.

Dr Kunwar Faraz Ahmed 29


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
Ideal Line
Ideal Line
Modify algorithm per quadrant

OR, increment along x-axis if dy<dx else increment along y-axis

Dr Kunwar Faraz Ahmed 30


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
DDA Algorithm
Ideal Line DDA Line Drawing Algorithm (Case b: m > 1)
DDA Algorithm
1
x k 1 xk (x1,y1)
x = x0 y = y0
m
Illuminate pixel (round(x), y)

y = y0 + 1 x = x0 + 1 * 1/m

Illuminate pixel (round(x), y)

y=y+1 x = x + 1 /m

Illuminate pixel (round(x), y)


(x0,y0)

Until y == y1
Dr Kunwar Faraz Ahmed 31
Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
DDA Algorithm
Ideal Line
DDA Algorithm DDA = Digital Differential Analyser
finite differences
Treat line as parametric equation in t :
Start point - ( x1 , y1 )
End point - ( x2 , y2 )

x(t ) x1 t ( x2 x1 )
y (t ) y1 t ( y2 y1 )

Dr Kunwar Faraz Ahmed 32


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
DDA Algorithm
Ideal Line
DDA Algorithm Start at t = 0
x(t ) x1 t ( x2 x1 )
y (t ) y1 t ( y2 y1 )
At each step, increment t by dt
Choose appropriate value for dt
dx
xnew xold dx x2 x1
dt
ynew yold
dy dy y2 y1
dt
Ensure no pixels are missed:
Implies: dx and dy 1
1
dt dt
Set dt to maximum of dx and dy

Dr Kunwar Faraz Ahmed 33


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
DDA Algorithm - Drawbacks
Ideal Line
DDA Algorithm
DDA is the simplest line drawing algorithm
Not very efficient
Round operation is expensive
Optimized algorithms typically used.
Integer DDA
E.g.Bresenham algorithm (Hill, 10.4.1)
Bresenham algorithm
Incremental algorithm: current value uses previous value
Integers only: avoid floating point arithmetic
Several versions of algorithm: well describe midpoint
version of algorithm

Dr Kunwar Faraz Ahmed 34


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
Bresenham Algorithm
Ideal Line
DDA Algorithm
Testing for the side of a line
Bresenham
Algorithm
o Testing for the
Need a test to determine which side of a line a pixel lies.
Side of a Line
Write the line in implicit form:

F ( x, y ) ax by c 0
If (b<0) F<0 for points above the line, F>0 for points
below.

35
Dr Kunwar Faraz Ahmed 35
Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
Bresenham Algorithm
Ideal Line
DDA Algorithm
Testing for the side of a line
Bresenham
Algorithm
F ( x, y ) ax by c 0
o Testing for the
Side of a Line
Need to find coefficients a,b,c.
Recall explicit, slope-intercept form :
dy
y mx b and so y xb
dx
So:
F ( x, y ) dy.x dx. y c 0

Dr Kunwar Faraz Ahmed 36


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
Bresenham Algorithm
Ideal Line
DDA Algorithm
Decision Variable
Bresenham
Algorithm
Lets assume dy/dx < 0.5 (we can use symmetry)
o Testing for the
Side of a Line 1
o Decision Variable Evaluate F at point M d F ( x p 1, y p )
2
Referred to as decision variable

NE

M
E

Previous Choices for Choices for


Pixel Current pixel Next pixel
(xp,yp) 37
Dr Kunwar Faraz Ahmed
Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
Bresenham Algorithm
Ideal Line
DDA Algorithm
Decision Variable
Bresenham Evaluate d for next pixel, Depends on whether E or NE Is chosen :
Algorithm
o Testing for the
Side of a Line
o Decision Variable If E chosen :
1 1
d new F ( x p 2, y p ) a ( x p 2) b( y p ) c
2 2
But recall :
1
d old F ( x p 1, y p )
NE
2
1
M
a( x p 1) b( y p ) c
2
E So : d new d old a
Previous Choices for
Choices for
Pixel
(xp,yp) Current pixel
Next pixel d old dy

Dr Kunwar Faraz Ahmed 38


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
Bresenham Algorithm
Ideal Line
DDA Algorithm
Decision Variable
Bresenham
Algorithm If NE was chosen :
o Testing for the
3 3
Side of a Line
o Decision Variable d new F ( x p 2, y p ) a ( x p 2) b( y p ) c
2 2
So :

M
d new d old a b
NE d old dy dx

E
Previous Choices for
Pixel Choices for Next pixel
(xp,yp) Current pixel

Dr Kunwar Faraz Ahmed 39


Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
Bresenham Algorithm
Ideal Line
DDA Algorithm
Summary
Bresenham
Algorithm
Choose between 2 pixels at each step based upon the sign
o Testing for the
Side of a Line
of a decision variable.
o Decision Variable
o Summary
Update the decision variable based upon which pixel is
chosen.
Start point is simply first endpoint (x1, y1).
Need to calculate the initial value for d

40
Dr Kunwar Faraz Ahmed 40
Lecture Sequence

Geometry
Vector Algebra
Matrix Algebra
Raster Graphics
Graphics Standards

Coordinate Systems
Raster Graphics
Bresenham Algorithm
Ideal Line
DDA Algorithm
Start Point
Bresenham Start point is (x1,y1)
Algorithm
o Testing for the 1 1
Side of a Line d start F ( x1 1, y1 ) a ( x1 1) b( y1 ) c
o Decision Variable
2 2
b
ax1 by1 c a
2
b
F ( x1 , y1 ) a
2
But (x1,y1) is a point on the line, so F(x1,y1) =0

d start dy dx / 2
Conventional to multiply by 2 to remove fraction doesnt
effect sign.

41
Dr Kunwar Faraz Ahmed 41