Anda di halaman 1dari 88

CSC251

Basics of Computer Graphics


Module: Geometry
P. J. Narayanan
Spring 2016

CSC251
Graphics Process

CSC251 Basics of Computer Graphics


Graphics Process
World Convert to Framebuffer
Representation Graphics Graphics API
Primitives Image

• Model the desired world in your head.


• Represent it using natural structures in the program.
Convert to standard primitives supported by the API
• Processing is done by the API. Converts the primitives
in stages and forms an image in the framebuffer
• The image is displayed automatically on the device
CSC251 Basics of Computer Graphics
How to Draw A House?

CSC251 Basics of Computer Graphics


Drawing A House
• Compose using basic shapes

// Main part
drawRectangle(v1, v2, v3, v4);
drawTriangle(v2, v3, v5); // Roof
drawRectangle( ... ); // Door
drawRectangle( ... ); // Window
drawRectangle( ... ); // Chimney
drawCircle( ... ); // Sun

• That’s all there is, really!

CSC251 Basics of Computer Graphics


Graphics Primitives

• Graphics is concerned with the appearance of the 3D


world to a camera
• Only outer surface of objects important, not interiors!!
• Hence, uses only 1D and 2D primitives

• Points: 2D or 3D. (x, y) or (x, y, z).


• Lines: specified using end-points
• Triangles/Polygons: specified using vertices
• Why not circles, ellipses, hyperbolas?
CSC251 Basics of Computer Graphics
Graphics Attributes

• Colour, Point width.

• Line width, Line style, Line Colour.

• Fill, Fill Pattern.

• Line: Give two endpoints

• Triangle: Give three vertices

• Point is the most basic primitive


CSC251 Basics of Computer Graphics
Point Representation

• A point is represented using 2 or 3 numbers (x, y, [z]) that


are the projections on to the respective coordinate axes.
– Could also be reprsented as a 2 or 3 vector P.
• Fundamental shape-defining primitive in most Graphics
APIs. Everything else is built from it!
• Represented using byte, short, int, float, double, etc.
• The scale and unit are application dependent.
Could be angstroms or lightyears!
• Points undergo transformations:
Translations, Rotations, Scaling, Shearing.
CSC251 Basics of Computer Graphics
3D Coordinates
– Vector P
– Cartesian: (x, y, z)
Z
– Polar: (ρ, θ, φ)
z
– z=
y= P
x= ρ
θ y
– ρ= Y
φ
φ= x
θ=
X
– Elevation: θ, Azimuthal: φ
CSC251 Basics of Computer Graphics
3D Coordinates
– Vector P
– Cartesian: (x, y, z)
Z
– Polar: (ρ, θ, φ)
z
– z = ρ cos θ,
y = ρ sin θ sin φ P
x = ρ sin θ cos φ ρ
θ y
2 2 2 2 Y
– ρ =x +y +z , φ
φ = tan−1(y/x),
p x
θ = tan ( x2 + y 2/z)
−1
X
– Elevation: θ, Azimuthal: φ
CSC251 Basics of Computer Graphics
Translation

• Translate a point P = (x, y, [z]) by (a, b, [c]).

• Points coordinates become P ′ = (?, ?, ?).

• In vector form, P ′ =?.

CSC251 Basics of Computer Graphics


Translation

• Translate a point P = (x, y, [z]) by (a, b, [c]).

• Points coordinates become P ′ = (x + a, y + b, [z + c]).

• In vector form, P ′ = P + T , where T = (a, b, [c]).

• Distances, angles, parallelism are all maintained.

CSC251 Basics of Computer Graphics


2D Rotation
– Rotate about origin CCW
by θ.
– x′ =?, y ′ =?
– Matrix notation: P ′ = R P
 ′   
x ? ? x
=
y ? ? y

CSC251 Basics of Computer Graphics


2D Rotation
– Rotate about origin CCW
by θ.
– x′ =?, y ′ =?
– Matrix notation: P ′ = R P
 ′   
x ? ? x
=
y ? ? y

CSC251 Basics of Computer Graphics


2D Rotation
– Rotate about origin CCW
by θ.
– x′ = x cos θ − y sin θ,
y ′ = x sin θ + y cos θ.

– Matrix notation: P ′ = R P
 ′   
x cos θ − sin θ x
=
y sin θ cos θ y

CSC251 Basics of Computer Graphics


2D Rotation: Observations
 
cos θ − sin θ
R=
sin θ cos θ
– Orthonormal: R−1 = RT
– Rows: vectors that
rotate to coordinate axes
– Cols: vectors coordinate
axes rotate to
– Invariants: distances,
angles, parallelism.

CSC251 Basics of Computer Graphics


3D Rotations

• Rotation could be about any axis in 3D! What does it


mean?
– Distance of each point to the axis of rotation remains
same.
– Each points moves in a circle on a plan perpendicular to
the axis of rotation, with the centre on the axis
• About Z-axis: Just like 2D rotation case. Z-coordinates
don’t change anyway.
• X-Y coordinates change exactly the same way as in 2D.
• CCW +ve, looking into the arrowhead: Rz (θ) =??
CSC251 Basics of Computer Graphics
3D Rotations
• Rotation could be about any axis in 3D!

• About Z-axis: Z-coordinates don’t change anyway


 
cos θ −sin θ 0
Rz (θ) = sin θ cos θ 0
 
0 0 1

• CCW +ve; orthonormal; length preserving

• Rows: vectors that rotate onto axes; columns: vectors


that axes rotate into....
CSC251 Basics of Computer Graphics
3D Rotations
   
cos θ 0 sin θ 1 0 0
Ry =  0 1 0  Rx = 0 cos θ −sin θ
   
−sin θ 0 cos θ 0 sin θ cos θ

• CCW +ve; orthonormal

• Rows: vectors that rotate onto axes; columns: vectors


that axes rotate into....

• Rotation about an arbitrary axis, for example, [1, 1, 1]T ??


Coming soon ....

CSC251 Basics of Computer Graphics


Non-uniform Scaling

• Scale along X, Y, Z directions by s, u, and t.

• x′ = s x, y ′ = u y, z ′ = t z.

• We are more comfortable with P ′ = S P or


 ′   
x s 0 0 x
 y  =  0 u 0  y 
    
z 0 0 t z

• Invariants: parallelism, ratios of lengths in any direction


(Angles also for uniform scaling.)
CSC251 Basics of Computer Graphics
Shearing

• Add a little bit of x to y or other combinations


 ′   
x 1 xy xz x
y = y 1 y z  y 
    
   x
z zx zy 1 z

• One of xy , xz , yx, yz , zx, zy 6= 0. Rectangles can become


parallelograms, but not general quadrilaterals

• Invariants: parallelism, ratios of lengths in any direction.

CSC251 Basics of Computer Graphics


Reflection

• Negative entries in a matrix indicate reflection.


 ′   
x −1 0 0 x
 y  =  0 −1 0   y 
    
z 0 0 1 z

• Reflection needn’t be about a coordinate axis alone

CSC251 Basics of Computer Graphics


Summary of Transformations

• Translation: New coordinates P′ = P + t

• Rotation: P′ = R P

• Scaling: P′ = S P

• Shearing: P′ = Sh P

• Reflection: P′ = Rf P

• Each is a matrix-vector product, except ....

CSC251 Basics of Computer Graphics


General Transformation

• Rotation, scaling, shearing, and reflection: Matrix-vector


product. Vectors get tranformed into other vectors
• Translation alone is a vector-vector addition
• Sequence of: Translation, rotation, scaling, translation
and rotation: P′ = R2 [S R1 (P + t1) + t2]
• If translation is also a matrix-vector product, we can
combine above transformations into a single matrix:
P′ = R2 T2 S R1 T1 P = M P
• How? Answer: homogeneous coordinates!

CSC251 Basics of Computer Graphics


Homogeneous Coordinates

• Add a non-zero scale factor w to each coordinate.


A 2D point is represented by a vector [x y w]T
• [x y w]T ≡ (x/w, y/w).
• Simplest value of w is obviously 1
• Translate [x y]T by [a b]T to get [x + a y + b]T
    
x+a ? ? ? x
 y + b  =  ? ? ?  y 
    
1 ? ? ? 1

CSC251 Basics of Computer Graphics


Homogeneous Coordinates

• Add a non-zero scale factor w to each coordinate.


A 2D point is represented by a vector [x y w]T
• Translate [x y]T by [a b]T to get [x + a y + b]T
    
x+a 1 0 a x
 y + b  =  0 1 b  y 
    
1 0 0 1 1

• Now, translation is also: P′ = T P, a matrix-vector


product and a linear operation.

CSC251 Basics of Computer Graphics


Homogeneous Coordinates

• Add a non-zero scale factor w to each coordinate.


A 2D point is represented by a vector [x y w]T
• [x y w]T ≡ (x/w, y/w).
• Now, translation is also: P′ = T P
• For a point: Rotation followed by translation followed by
scaling, followed by another rotation: P′ = R2STR1 P.
• Similarly for 3D. Points represented by: [x y z w]T .
• All matrices are 3 × 3 in 2D. Last row is [0 0 1].
• All matrices are 4 × 4 in 3D. Last row is [0 0 0 1].
CSC251 Basics of Computer Graphics
Homogeneous Representation

• Convert to a 4-vector with a scale factor as fourth.


(x, y, z) ≡ [kx ky kz k]T for any k 6= 0.

• Translation, rotation, scaling, shearing, etc. become


linear operations represented by 4×4 matrices.

• What does [x y z 0]T mean?

• [a b c d]T could be a point or a plane. Lines are specified


using two such vectors, either as join of two points or
intersection of two planes!

CSC251 Basics of Computer Graphics


Transformation Matrices: Rotations
 
1 0 0 0
0 cos θ −sin θ 0
 
Rx(θ) = 
 
0 sin θ cos θ 0

0 0 0 1
   
cos θ 0 sin θ 0 cos θ −sin θ 0 0
0 1 0 0 sin θ cos θ 0 0
   
Ry =   Rz = 
 
−sin θ 0 cos θ 0  0 0 1 0

0 0 0 1 0 0 0 1

• CCW +ve; orthonormal; length preserving; rows give


direction vectors that rotate onto each axis; columns ....

CSC251 Basics of Computer Graphics


Translation, Scaling, Composite
   
1 0 0 a a 0 0 0
0 1 0 b 0 b 0 0
   
T (a, b, c) =  , S(a, b, c) = 
0 0 1 c 0 0 c 0

0 0 0 1 0 0 0 1

• A sequence of transforms can be represented using a


composite matrix: M = RxTRy ST · · ·

• Operations are not commutative, but are associative.

• RT and TR??

CSC251 Basics of Computer Graphics


Rotation and Translation
   
I t R 0
• T4×4 = and R4×4 =
0 1 0 1
  
I t R 0
• T R= = ?
0 1 0 1
  
R 0 I t
• RT = = ?
0 1 0 1

CSC251 Basics of Computer Graphics


Rotation and Translation
   
I t R 0
• T4×4 = and R4×4 =
0 1 0 1
    
I t R 0 R t
• T R= =
0 1 0 1 0 1
    
R 0 I t R Rt
• RT = =
0 1 0 1 0 1

• T R = R T if: (a) R = I or (b) t = 0 or (c) Rt =?

CSC251 Basics of Computer Graphics


Rotation and Translation
   
I t R 0
• T4×4 = and R4×4 =
0 1 0 1
    
I t R 0 R t
• T R= =
0 1 0 1 0 1
    
R 0 I t R Rt
• RT = =
0 1 0 1 0 1
• T R = R T if: (a) R = I or (b) t = 0 or (c) Rt = t
• When is Rt = t? t is an eigenvector of R
• Question: Are transformations commutative?

CSC251 Basics of Computer Graphics


Commutativity

• Translations are commutative: T1T2 = T2T1


• Scaling is commutative: S1S2 = S2S1
?
• Are rotations commutative? R1R2 = R2R1
?
• Rotation and Scaling commute? SR = RS
• What would be an example?
Consider the effect on Z-axis of:

CSC251 Basics of Computer Graphics


Commutativity

• Translations are commutative: T1T2 = T2T1


• Scaling is commutative: S1S2 = S2S1
• Are rotations commutative? R1R2 6= R2R1
• Rotation and Scaling commute. SR = RS
• Consider the effect on Z-axis of
Rx(90)Ry (90) and Ry (90)Rx(90)
• RT 6= TR. (If translation is not parallel to rotation axis)
• Consider: R(π/4) and T (5, 0).
Where does the origin (0, 0) go in TR and RT?
CSC251 Basics of Computer Graphics
TR and RT

TR

RT

TR keeps it on X axis to (5, 0). TR takes it to ( √52 , √52 ).


CSC251 Basics of Computer Graphics
Objects Away from Origin
• Object “translates” when
rotated or scaled!!
Rotated

• Default: Perform these


about the origin
• How do we transform
points “in place”?
• Rotate or scale about the Shape

centroid of the object. Or Scaled

about an arbitrary point


• How?

CSC251 Basics of Computer Graphics


Transformations About A Point
• Rotating about point P
– Align P with origin
– Rotate/scale about origin
– Translate back
• Rotation:
RC(θ) = T(C) R T(−C)
• Scaling:
SC() = T(C) S() T(−C)
• A transformation M:
MC = T(C) M T(−C)

CSC251 Basics of Computer Graphics


Object

• Object has a coordinate frame of its own.

CSC251 Basics of Computer Graphics


Object and Translation

′ ′
P =P P =T P
CSC251 Basics of Computer Graphics
Object, Translation, Rotation

′ ′
P =P P =R P
CSC251 Basics of Computer Graphics
Understanding Transformations

TR

RT

CSC251 Basics of Computer Graphics


R, T Operations on Points

• T(5,0) R(π/4): Impact on a point:


– R(π/4): (Point stays at (0, 0))
– T(5, 0) : (Point goes to (5, 0))

• R(π/4) T(5,0): Impact on the point:


– T(5, 0): (Point moves to (5, 0))
– R(π/4). (Point rotates about origin)

• All points on the shape undergo the same motions and


get new coordinates

CSC251 Basics of Computer Graphics


Relating Coordinate Frames
• T (5, 0) and R(π/4)
• Start: Black axes TR
Next: Blue axes
Last: Red axes
RT

Black Blue
• P′ = | T | R P

Black Blue
• P′ = | R | T P

CSC251 Basics of Computer Graphics


R, T Operaions on Frames

• T(5,0) R(π/4): Impact on coordinate frame:


– T(5, 0): (Origin shifted to (5, 0))
– R(π/4). (Axes rotated at new origin)

• R(π/4) T(5,0): Impact on coordinate frame:


– R(π/4): (Axes rotate by 45 degrees))
– T(5, 0). (Point moves to (5, 0) in new axes)

• Frames move around, giving new coordinates to points


on objects!!

CSC251 Basics of Computer Graphics


I Am Where I Think I Am (IAWITIA)

• What am I? Different entities at different times.


student, friend, brother, enemy, daughter, neighbour, ...
• Let us stick to easier 3D geometry!
What are my coordinates (if I am a point)?
• Coordinates of a point depend on the viewpoint used
(similar to life; evaluation depends on the viewer)
• Nothing really “happens”. Nothing “moves”.
There are only changes in viewpoints (in geometry)!!
• IAWITIA: Pronounced ayA-wI-shia (rhymes with dementia)

CSC251 Basics of Computer Graphics


IAWITIA in Action

• Consider P4 = M4M3M2M1 P0

• Point P0 undergoes 4 operations and get coordinates P4

• Imagine the point having coordinates P1, P2, P3 after


operations M1, M2, M3

• We can also visualize coordinate frames Π4, Π3, Π2, Π1, Π0


in which a point has coordinates P4 to P0 respectively

• Operation Mi represents a change in coordinates from


Πi to Πi−1, resulting in new labels for the point.
CSC251 Basics of Computer Graphics
IAWITIA in TR

• Frame translates first.

• Frame rotates next, in the current frame!!

CSC251 Basics of Computer Graphics


IAWITIA in RT

• Frame rotates first

• Frame translates next, in the current frame!!

CSC251 Basics of Computer Graphics


IAWITIA in Action in IIIT Campus

• Model IIIT Campus as a whole. Campus is our “world”


• Global coordinate frame ΠG for the campus: at the Gate
• Buildings: Himalaya, Vindhya, Bakul, Parul, ..., Palash.
Each has a natural coordinate frame. ΠH is Himalaya’s
• Himalaya has several rooms: H105, H204, H304, etc.,
with own coordinate frames. ΠC is of H205 (our class)
• H205 has 75 desks, with coord frames ΠDi for desk i
• Desks are identical in geometry; the coord frame ΠDi
places each in its location.

CSC251 Basics of Computer Graphics


Consider a Desk

• Consider a corner point P of desk 37, with coordinates


(200, 30, 100) in ΠD37. That is: PD37 = (200, 30, 100)
• Since our world is the campus, we have to ultimately
describe everything in the coordinate frame ΠG
PG = MGH MHC MCD37 PD37
• MGH aligns ΠG to ΠH. MHC aligns ΠH to ΠC.
MCD37 aligns ΠC to ΠD37
PH PC PD37
• PG = MGH | MHC | MCD37 | P (for any point P on Desk37)

• We can place a given desk in any building, room, place!


CSC251 Basics of Computer Graphics
Walking on Stage

• Person walking horizontally on stage, with swinging arms


• How does the hand-tip move w.r.t each student? How?
• Student knows own position in room’s reference frame
• Start at a student’s eye. (That provides the viewpoint!)
• Align to room’s reference frame using M1. Different
matrix for each student, but everyone same now....
• Walk: pure translation. M2 aligns to person coord frame
• Arm swing: Simple harmonic motion with angle θ(t)
Simpler viewpoints in newer coord frames. IAWITIA !!
CSC251 Basics of Computer Graphics
Rolling Wheel
Coordinates P(t)?

CSC251 Basics of Computer Graphics


P(t) = ??

CSC251 Basics of Computer Graphics


P(t) = T1(r, θ(t)) P’(t)

Y’

CSC251 Basics of Computer Graphics


P(t) = T1(r, θ)R(θ(t)) P”(t)

Y’
Y’

CSC251 Basics of Computer Graphics


P(t) = T1RT2(p(t)) P”’

Y’
Y’
’ Y’’’

CSC251 Basics of Computer Graphics


Final Transformation

• P(t) = T1(t) R(θ(t)) T2(p(t)) P”’


• T1(t) = T(r θ(t), 0) = T(r ω t, 0) (A translation matrix)

• R(θ(t)) = RZ(ω t) (A normal rotation matrix)

• T2(t) = T(p(t), 0) = T(v t, 0) (A translation matrix)

• P”’ = [0, 0, 1]T (Origin of the bead)

• Lot simpler than thinking about it all together.

• What if we have a pendulum swinging freely on the bead?

CSC251 Basics of Computer Graphics


Given an object

• An object traingleObj is given. Can be drawn using


drawObject(triangleObj)

• drawObject(triangleObj) draws the object at


(current) origin
CSC251 Basics of Computer Graphics
Draw it in a different configuration

• Use drawObject(triangleObj), with right transformations

CSC251 Basics of Computer Graphics


Transformations

to

• What are the transformations? Combination of


Translation, Rotation, Scaling!!

• Operations involved: S( 21 , 21 ), T(3, 2), R(90)

CSC251 Basics of Computer Graphics


Which combination?
Envision and sketch the impact of each of:

1. S( 21 , 12 ) R(90) T(3, 2)

2. S( 21 , 12 ) T(3, 2) R(90)

3. T(3, 2) R(90) S( 21 , 12 )

4. T(3, 2) S( 21 , 12 ) R(90)

5. R(90) S( 21 , 12 ) T(3, 2)

6. R(90) T(3, 2) S( 21 , 12 )
CSC251 Basics of Computer Graphics
CSC251 Basics of Computer Graphics
Several Correct Situations

CSC251 Basics of Computer Graphics


Another Situation
• A clock is hanging from a nail fixed to a flat plate. The
plate is being translated with a velocity ~v and acceleration
~a. The pendulum of the clock swings back and forth with
a time period of 5 seconds and a max angle of ±θ. An
ant travels from the bottom tip of the pendulum up to the
centre.

• How do we compute the ant’s position with respect to a


fixed coordinate system coplanar with the plate?

Please sketch the situation and work it out for


yourself
CSC251 Basics of Computer Graphics
A Transformation Problem

C B
A
D
D
B

Bring D to origin and BC parallel to the Y axis as shown

CSC251 Basics of Computer Graphics


Transformation Computation

• Step 1: Translate by −D. What is the orientation of BC?


• Step 2: Rotate to have unit vector ~u = [ux uy ]T from B to
C on the Y axis. That is the second row of R matrix
• The matrix for the total operation: M = R T(−D)

• Two options for first row. [uy −ux]T and [−uy ux]T
   
uy −ux −uy ux
• R matrix: (a) or (b) ?
ux uy ux uy
• Difference? The direction aligned to the X-axis!
• Option (a) is correct. Why? Draw Option (b)!
CSC251 Basics of Computer Graphics
Rotation about an axis parallel to Z

• An axis parallel to Z axis, passing through point (x, y, 0).

• Translate so that the axis passes through the origin:


T(−x, −y, k) for any k!!

• Overall: M = T(x, y, −k) RZ(θ) T(−x, −y, k)

• Why shouldn’t k matter? RZ doesn’t affect the z


coordinate. So, whatever k is added first will be
subtracted later

CSC251 Basics of Computer Graphics


Easy 3D Transformations
   
1 00 a a 0 0 0
0 10 b 0 b 0 0
T (a, b, c) = 
0
 , S(a, b, c) =  
01 c 0 0 c 0
0 00 1 0 0 0 1
 
1 0 0 0
0 cos θ −sin θ 0
Rx(θ) = 
0 sin θ

cos θ 0
0 0 0 1
   
cos θ 0 sin θ 0 cos θ −sin θ 0 0
 0 1 0 0  sin θ cos θ 0 0
Ry =   Rz =  
−sin θ 0 cos θ 0  0 0 1 0
0 0 0 1 0 0 0 1

• CCW +ve; orthonormal; length preserving; rows give


direction vectors that rotate onto each axis; columns ....

CSC251 Basics of Computer Graphics


3D Rotation about an axis α

• What is Rα(θ)?

• How do we reduce it to something we know?

• What do we know? RX(θ), RY (θ), RZ(θ)

CSC251 Basics of Computer Graphics


3D Rotation about an axis α

• What is Rα(θ)?

• 3-step process:
1. Apply Rαx to align α with the X axis.
2. Rotate about X by angle θ.
1
3. Undo the first rotation using R−
αx
1
• Net result: Rα(θ) = R−
αx Rx (θ) Rαx

• Quite simple!? What is Rαx(θ)?

• (We can align α with Y or Z axis also)


CSC251 Basics of Computer Graphics
Z

β
α Y

γ
X P

CSC251 Basics of Computer Graphics


Computing Rα

• First rotate by −β about X axis. Vector α would lie in the


XY plane, with tip at point P.

• β = ?, tan β = ?

• Next rotate by −γ about Z axis. Vector α would coincide


with the X axis.

• γ = ?, tan γ = ?

CSC251 Basics of Computer Graphics


Computing Rα

• Rotate by −β about X axis to bring α to XY plane


αz
• tan β = αy

• Rotate by −γ about Z axis to bring α to X axis


√ 2 2 √
αy +αz 1−α2x
• tan γ = αx = αx if |α| = 1.

1
• Rαx = Rz(−γ)Rx(−β) and R−
αx = Rx(β)Rz(γ)

• Alternative: Don’t we know about rotation matrices and


direction cosines that go to/from coordinate axes?
CSC251 Basics of Computer Graphics
Final

• Rα(θ) = Rx(β)Rz(γ) Rx(θ) Rz(−γ)Rx(−β)


Z

β
α Y

γ
X P

CSC251 Basics of Computer Graphics


Alternate Rαx
• After rotation, α will align with X-axis. Hence that is the
first row r1 of the rotation matrix

• Find a direction orthogonal to α to be row r2. How?

• Take any vector v not parallel to α. r2 = α × v will work!!


 
α 0
 α×v 0 
 
• Lastly, r3 = r1 × r2 and Rαx = 
 r1 × r2 0 

0 1

• Many possibilities, all with the same result (hopefully...)


CSC251 Basics of Computer Graphics
Example: Rotation about [1 1 1]T

(0, 1, 1)

(1, 0, 1) (1, 1, 1)

(1, 1, 0) (1, 2 , 0)

β = ?, γ=?

CSC251 Basics of Computer Graphics


Example: Rotation about [1 1 1]T

(0, 1, 1)

(1, 0, 1) (1, 1, 1)

(1, 1, 0) (1, 2 , 0)

tan β = 1, tan γ = 2

CSC251 Basics of Computer Graphics


Computing Rαx: Method 1
 
1 0 0
π  0
• Rotate by −π/4 about X. RX(− 4 ) =  √1 √1 
2 2 
0 −1
√ √1
2 2
 1 2

√ √ 0
√ 3
 −2 √1 6
• RZ(− arctan( 2)) =  √ 0 

6 3
0 0 1
 
√1 √1 √1 0
3 3 3
 
√  −2
√ √1 √1 0 
I −1 π 6 6 6
• Rαx = RZ(−tan ( 2)) RX(−4 ) = 
 
√1
−1

 0 √ 0 
 2 2 
0 0 0 1

CSC251 Basics of Computer Graphics


Computing Rαx: Method 2

• [1 1 1]T will lie on X-axis. First row r1 = [ √13 √1 √1 ]T.


3 3

• Second row: r2 = α × [1 0 0]T = [0 √1 √−1 T


]
2 2

• Third row: r3 = α × [0 √1 √−1 T


] = [ √26 −1 √
√ −1 T
]
2 2 6 6
 
√1 √1 √1 0
3 3 3
 
 0 √1 −1
√ 0  √
2 2
• RII =  2  = RY (tan ( 2)) RX( π4 )
−1
 
αx −1 −1
 √
 6

6

6
0 

0 0 0 1

CSC251 Basics of Computer Graphics


Rαx Method 2: Contd

(1, 0, 2) (0, 1, 1)

(1, 0, 1) (1, 1, 1)

(1, 1, 0)

Question: Which vector v yields the matrix of Method 1?

CSC251 Basics of Computer Graphics


Rotation: Arbitrary Axis, Point

• An arbitrary axis may not pass through the origin.

• Translate by T so that it passes through the origin.

• Apply Rα.

• Translate back using T−1.

• Composite transformation: T−1 Rα T.

CSC251 Basics of Computer Graphics


3D Transformations

• Many ways to think about a given transform.

• Ultimately, there is only one transform given the starting


and ending configurations.

• Different methods let us analyze the problem from


different perspectives.

CSC251 Basics of Computer Graphics


Another Example
Z Z

B
A
C
B’
Y A’ Y
C’

X X

CSC251 Basics of Computer Graphics


Working the Example

• Translate by -A to bring it to the origin.


• After the rotation, AC sits on the X axis.
• The first row of the rotation matrix is AC / |AC|.
• The vector normal to the plane ABC sits on the Y axis.
• The second row of the rotation matrix is the unit vector
along AB × AC = (AB × AC) / |AB × AC|.
• Third row is a cross product of the first two.

• Final transformation: R T(−A)

CSC251 Basics of Computer Graphics


Transforming Lines

• A composite transformation can be seen as changing


points in the coordinate system.
• These transformations preserve collinearity. Thus, points
on a line remain on a (transformed) line.
• Take two points on the line, transform them, and compute
the line between new points.
• Lines are defined as a join of 2 points or intersection of 2
planes in 3D. The same holds for transformed lines using
transformed points or planes!

CSC251 Basics of Computer Graphics


Transforming Planes

• A plane is defined by a 4-vector n (called the normal


vector) in homogeneous coordinates.
• The plane consists of points p such that nTp = 0.
• Let Q transform n when points are transformed by M.
• Coplanarity is preserved: (Qn)TMp = 0 = nTQTMp.
• True when QTM = I, or Q = M−T.
• Q is the Matrix of cofactors of M in the general case when
M−1 doesn’t exist.

CSC251 Basics of Computer Graphics


Understanding Geometric
Transformations

• Geometry transformation of objects is very important to


compose graphics environments

• Understand what you want to be achieved, visualize it in


your mind and compose the series of transformations

• Needs getting used to the ideas. Think about getting into


a simpler situtation from the current one.

CSC251 Basics of Computer Graphics

Anda mungkin juga menyukai