20 views

Uploaded by Deepika Reddy

This material describes about graphical processing and its basics.

- Rotate a Point
- Sadler-Specialist Mathematics-Unit 3A-Chapter 1-Solutions
- SpriteGraphics
- group project 1
- 2DAnniversaryEdition 1 Tutorial
- Detailed LP for Grade 8
- Advance Steel COM API Developer Training Guide
- Tensors an Introduction for Students Kolecki J NASA 26 RED
- Ect 111 Autocad Modul
- 4 Rectangular Concrete Tanks
- Computer Graphics
- 154-498-1-PB
- Touring
- Course Outline
- hw01
- Finite Wing
- 8622019_04_20_20_42_10
- Plotting, Loading and Saving
- 8-2 reflection mahmut koca 2 lesson plan
- Isotropic Design of a Parallel Machine-Tool Mechanism

You are on page 1of 88

Module: Geometry

P. J. Narayanan

Spring 2016

CSC251

Graphics Process

Graphics Process

World Convert to Framebuffer

Representation Graphics Graphics API

Primitives Image

• 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?

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

Graphics Primitives

world to a camera

• Only outer surface of objects important, not interiors!!

• Hence, uses only 1D and 2D primitives

• Lines: specified using end-points

• Triangles/Polygons: specified using vertices

• Why not circles, ellipses, hyperbolas?

CSC251 Basics of Computer Graphics

Graphics Attributes

CSC251 Basics of Computer Graphics

Point Representation

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

Translation

2D Rotation

– Rotate about origin CCW

by θ.

– x′ =?, y ′ =?

– Matrix notation: P ′ = R P

′

x ? ? x

=

y ? ? y

2D Rotation

– Rotate about origin CCW

by θ.

– x′ =?, y ′ =?

– Matrix notation: P ′ = R P

′

x ? ? x

=

y ? ? y

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

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.

3D Rotations

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!

cos θ −sin θ 0

Rz (θ) = sin θ cos θ 0

0 0 1

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 θ

that axes rotate into....

Coming soon ....

Non-uniform Scaling

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

′

x s 0 0 x

y = 0 u 0 y

z 0 0 t z

(Angles also for uniform scaling.)

CSC251 Basics of Computer Graphics

Shearing

′

x 1 xy xz x

y = y 1 y z y

x

z zx zy 1 z

parallelograms, but not general quadrilaterals

Reflection

′

x −1 0 0 x

y = 0 −1 0 y

z 0 0 1 z

Summary of Transformations

• Rotation: P′ = R P

• Scaling: P′ = S P

• Shearing: P′ = Sh P

• Reflection: P′ = Rf P

General Transformation

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!

Homogeneous Coordinates

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

Homogeneous Coordinates

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

product and a linear operation.

Homogeneous Coordinates

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

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

linear operations represented by 4×4 matrices.

using two such vectors, either as join of two points or

intersection of two planes!

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

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

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

composite matrix: M = RxTRy ST · · ·

• RT and TR??

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

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

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?

Commutativity

• 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:

Commutativity

• 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

CSC251 Basics of Computer Graphics

Objects Away from Origin

• Object “translates” when

rotated or scaled!!

Rotated

about the origin

• How do we transform

points “in place”?

• Rotate or scale about the Shape

• How?

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)

Object

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

R, T Operations on Points

– R(π/4): (Point stays at (0, 0))

– T(5, 0) : (Point goes to (5, 0))

– T(5, 0): (Point moves to (5, 0))

– R(π/4). (Point rotates about origin)

get new coordinates

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

R, T Operaions on Frames

– T(5, 0): (Origin shifted to (5, 0))

– R(π/4). (Axes rotated at new origin)

– R(π/4): (Axes rotate by 45 degrees))

– T(5, 0). (Point moves to (5, 0) in new axes)

on objects!!

I Am Where I Think I Am (IAWITIA)

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)

IAWITIA in Action

• Consider P4 = M4M3M2M1 P0

operations M1, M2, M3

in which a point has coordinates P4 to P0 respectively

Πi to Πi−1, resulting in new labels for the point.

CSC251 Basics of Computer Graphics

IAWITIA in TR

IAWITIA in RT

IAWITIA in Action in IIIT Campus

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

Consider a Desk

(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)

CSC251 Basics of Computer Graphics

Walking on Stage

• 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)?

P(t) = ??

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

Y’

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

Y’

Y’

’

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

Y’

Y’

’ Y’’’

Final Transformation

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

Given an object

drawObject(triangleObj)

(current) origin

CSC251 Basics of Computer Graphics

Draw it in a different configuration

Transformations

to

Translation, Rotation, Scaling!!

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

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.

fixed coordinate system coplanar with the plate?

yourself

CSC251 Basics of Computer Graphics

A Transformation Problem

C B

A

D

D

B

Transformation Computation

• 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

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

coordinate. So, whatever k is added first will be

subtracted later

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

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

3D Rotation about an axis α

• What is Rα(θ)?

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

CSC251 Basics of Computer Graphics

Z

β

α Y

γ

X P

Computing Rα

XY plane, with tip at point P.

• β = ?, tan β = ?

with the X axis.

• γ = ?, tan γ = ?

Computing Rα

αz

• tan β = αy

√ 2 2 √

αy +αz 1−α2x

• tan γ = αx = αx if |α| = 1.

1

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

αx = Rx(β)Rz(γ)

direction cosines that go to/from coordinate axes?

CSC251 Basics of Computer Graphics

Final

Z

β

α Y

γ

X P

Alternate Rαx

• After rotation, α will align with X-axis. Hence that is the

first row r1 of the rotation matrix

α 0

α×v 0

• Lastly, r3 = r1 × r2 and Rαx =

r1 × r2 0

0 1

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)

β = ?, γ=?

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

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

Computing Rαx: Method 2

3 3

]

2 2

] = [ √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

Rαx Method 2: Contd

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

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

(1, 1, 0)

Rotation: Arbitrary Axis, Point

• Apply Rα.

3D Transformations

and ending configurations.

different perspectives.

Another Example

Z Z

B

A

C

B’

Y A’ Y

C’

X X

Working the Example

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

Transforming Lines

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!

Transforming Planes

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.

Understanding Geometric

Transformations

compose graphics environments

your mind and compose the series of transformations

a simpler situtation from the current one.

- Rotate a PointUploaded byanveshkk04
- Sadler-Specialist Mathematics-Unit 3A-Chapter 1-SolutionsUploaded byRolou15
- SpriteGraphicsUploaded bykjngstars
- group project 1Uploaded byapi-272009783
- 2DAnniversaryEdition 1 TutorialUploaded byJaime Leonardo Amaya
- Detailed LP for Grade 8Uploaded byJocelyn Lanting
- Advance Steel COM API Developer Training GuideUploaded byRoger Maycon Cuti Nuñoncca
- Tensors an Introduction for Students Kolecki J NASA 26 REDUploaded byEduardo Castañeda
- Ect 111 Autocad ModulUploaded byRegarz Arrow
- 4 Rectangular Concrete TanksUploaded byajitgijare
- Computer GraphicsUploaded byNitish Sand
- 154-498-1-PBUploaded byEduardo Carrasco
- TouringUploaded byGanesh Arora
- Course OutlineUploaded byAli Hassan Rizvi
- hw01Uploaded byPaola Arbelaez
- Finite WingUploaded byChegrani Ahmed
- 8622019_04_20_20_42_10Uploaded byAnkit Suryavanshi
- Plotting, Loading and SavingUploaded byamdocm
- 8-2 reflection mahmut koca 2 lesson planUploaded byapi-357803051
- Isotropic Design of a Parallel Machine-Tool MechanismUploaded byHareesha N G
- Beginner Ansys TutorialUploaded byNGUYEN
- Many SyllabusUploaded byrajivslce
- Cad Ex12.PDFUploaded byAmir Amiri
- Chapter 8 CoordinatesUploaded byMadihah Ramly
- 2020B Cnc Machine ManualUploaded byFelipeAndrésLondoñoGranda
- 10.1.1.90Uploaded bynewzet
- Comparisons of CAD Jewellery Software - CAD Jewellery SkillsUploaded byVadym S.
- Gm Orient PptUploaded bySenthil R
- Engg Mechanics Non Coplanar Force SystemUploaded byAkash Wea
- Homework 1Uploaded bybatuhany90

- Add Math TerengganuUploaded byanon-29285
- HW7SolUploaded bymetmet476
- HW6_solUploaded byAnonymous Zz1bV7H59y
- Tutorial IIIUploaded byMyameSirame
- 13_Rate_of_Change.pdfUploaded byJashandeep Singh Kochhar
- SageMath FunctionsUploaded bySelk
- Conic Section Part 6 of 8Uploaded bymajji satish
- An Introduction to Numerical Methods and Analysis, 2nd EditionUploaded byRicardo
- Process Modelling and Simulation Chapter 6 Soln Strategies for Lumped Parameter ModelUploaded byjeygar12
- Ode 45Uploaded bymynameisbill
- Self-Descriptive SequencesUploaded bymitchesius3824
- Metric and Topological SpacesUploaded byViktor Han
- 00218Uploaded byVlad Lazãr
- 1st PUC Maths Model QP 2.pdfUploaded byPrasad C M
- Translate Algebra ExpressionUploaded byLARRY
- Table-of-Specification-Math-Grades-7-10.docxUploaded byFranklin Lirazan
- Klar Et Al. - 2005 - Soil-pipe Interaction Due to Tunnelling Comparison Between Winkler and Elastic Continuum SolutionsUploaded byalibaaziz
- Persamaan CremeeerUploaded byHorasman P Simarmata
- Solutions PDEUploaded byRizwan 106
- Chapter5 DecimalsUploaded byismael63322
- HFTUploaded byasg_rus
- Topic 2 FractionsUploaded byGollip Pasok
- CH_1Uploaded byjhgfd33
- A Matrix System for Computing the Coefficients of the Adams Bashforth-Moulton Predictor-Corrector FormulaeUploaded byDavid Mbikayi
- McGrawHill Grade 11 Functions Unit 3Uploaded byblabdude123
- NumericalUploaded byishqi92
- ECE2610 Lab1 ReportUploaded byRituparna Das
- Lecture 14Uploaded byYamaneko Shin
- Hunters Hill 2016 3U Trials & SolutionsUploaded byKingom 885
- A-Level-Maths-C4Uploaded bymalp23