+ All Categories
Home > Documents > ComputerGraphics 09

ComputerGraphics 09

Date post: 20-Feb-2018
Category:
Upload: rajyalakshmi-jammalamadaka
View: 218 times
Download: 0 times
Share this document with a friend
35
Computer Graphics Spring 2007, #9 3D graphics
Transcript
Page 1: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 1/35

Computer Graphics

Spring 2007, #9

3D graphics

Page 2: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 2/35

Page 3: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 3/35

Computer graphics in 3D• Define 3D objects

– geometry – translations, rotations, scalings

• Calculate their appearance

– lighting• Project onto camera plane

– perspective transformation

– in 2D: parallel projection – depth cueing: light intensities, removal of hiddenlines, shadows

Page 4: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 4/35

3D Objects• Typically defined by specifying the

surfaces enclosing a non-zero volume• Properties of 3D objects:

– vertices – edges – polygons, plane or non-plane

– plane normals

Page 5: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 5/35

3D Objects

V1

V2

V3

V4

V5

V6

E1 E2

E3E4

E5

E6

E7

E8

Polygon list:

P1: E

1, E

2, E

3

P 2: E 2, E 4, E 5

P 3: E 6, E 7, E 8, E 4

Edge list:

E1: V1, V2

E2: V2, V3

E3: V3, V1

E9

Page 6: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 6/35

2D Plane in 3D• Defined by three points in a plane, not

along a line:P 1 = (x 1,y1,z 1), P 2= (x 2,y2,z 2), P 3 = (x 3,y3,z 3)

• Equation for any point in the plane:A∗x+B∗y+C∗z+D=0• Actually a three parameter equation:

A/D∗x+B/D∗y+C/D∗z=-1

Page 7: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 7/35

2D Plane in 3D• Solve for parameters:

• Succeeds if Det | | ≠ 0. If determinant iszero then points are collinear.

z3y3x3

z2y2x2

z1y1x1

C/DB/DA/D

-1-1-1

=

Page 8: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 8/35

2D Plane in 3D• Solutions:

A/D = [y2z3-y3z2 –(y 1z3-y3z1)+y1z2-y2z1](-1/det)

D = -(x 1y2z3- x1y3z2- x2y1z3+

x2y3z1+ x 3y1z2- x3y2z1)

Page 9: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 9/35

Normal to Plane• We calculate a normal to the plane as follows:

• Denote the vector from the origin to V 1 by V 1

• (V2 - V1) and (V 3 - V1) lie in the plane defined bythe three vertices V 1,V2,V3

• Their cross product is perpendicular to the plane= a normal

N = (V2-V1)x(V3-V1) = Ai + Bj +Ckwhere i = (1,0,0), j = (0,1,0), k = (0,0,1)

Page 10: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 10/35

Points In and Outisde the Plane• Denote any point in space by P = (x,y,z)• N · P = -D for points in the plane• A∗x+B∗y+C∗z+D > 0 for points above the

plane• A∗x+B∗y+C∗z+D < 0 for point below the

plane

Page 11: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 11/35

File Formats• Files defining 3D objects should contain

– vertex information – edges, polygons

– colour information – normal, tangent, binormal

• Choose your favourite file format!

Page 12: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 12/35

.ply File Formatplyformat ascii 1.0 { ascii/binary, format version number }comment made by Greg Turk { comments keyword specified, like all lines }

comment this file is a cubeelement vertex 8 { define "vertex" element, 8 of them in file }property float x { vertex contains float "x" coordinate }property float y { y coordinate is also a vertex property }property float z { z coordinate, too }element face 6 { there are 6 "face" elements in the file }property list uchar int vertex_index { "vertex_indices" is a list of ints }end_header { delimits the end of the header }0 0 0 { start of vertex list }0 0 10 1 10 1 01 0 01 0 11 1 1

1 1 04 0 1 2 3 { start of face list }4 7 6 5 44 0 4 5 14 1 5 6 24 2 6 7 34 3 7 4 0

Page 13: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 13/35

Linear Algebra• Given two vectors in n-dimensional space

a = (a 1,a 2,..,a n) and b = (b 1,b 2,..,b n)• Vector addition

a + b = (a 1+b 1,a 2+b 2, ..., a n+b n)• Length |a| = (a 1∗a 1+a 2∗a 2+ ... +a n∗a n)1/2

• Dot product (a.k.a. inner product)a·b = a 1∗b1 + a 2∗b2 + ... + a n∗bn

= |a| ∗|b|∗cos( θab )

Page 14: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 14/35

Linear Algebra: Dot Product• Angle θab between vectors a and b• a and b define a plane and a normal n

x

z

ab

a

b

n

Page 15: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 15/35

3D Linear Algebra: Cross Product• The following applies only in 3D.• The normal to the plane formed by a and b

according to a RH coordinate system is

denoted by n• Cross product: a ×b = |a| ∗|b|∗sin( θab )∗ni j ka 1 a 2 a 3b1 b2 b3

Page 16: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 16/35

3D Translations• A translation of a point at (x,y,z) by the

amount t = (t x,ty,tz) to the position(x+tx,y+t y,z+t z) is given by a translationmatrix in homogeneous coordinates:

1000tz100

ty010tx001

wz

yx

w’z’

y’x’

=

Page 17: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 17/35

3D Translations• Translation from red to green by t

x

z

y

t =(tx,ty,tz)

Page 18: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 18/35

3D Translations• The inverse translation T -1(t) is such that

T-1(t) T(t) = 1 4x4

• Explicitly T -1(t) = T(-t)

1000 -tz100

-ty010-tx001

=T-1(t)

Page 19: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 19/35

3D Rotations: Z-Axis• Rotation w.r.t z-axis

x

z

y

1000010000cos( θ)sin( θ)

00-sin( θ)cos( θ)

wzy

x

w’z’y’

x’

=

θ

Page 20: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 20/35

3D Rotations: X-Axis• Rotation w.r.t x-axis

x

z

y

10000cos( θ)sin( θ)00-sin( θ)cos( θ)0

0001

wzy

x

w’z’y’

x’

Page 21: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 21/35

3D Rotations: Y-Axis• Rotation w.r.t y-axis

x

z

y

10000cos( θ)0-sin( θ)0010

0sin( θ)0cos( θ)

wzy

x

w’z’y’

x’

Page 22: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 22/35

3D Rotations: Inverse• The inverse rotation R -1(θ) is such that

R -1(θ)R(θ) = R ( θ)R -1(θ) = 1 4x4

• Explicitly,R -1(θ) = R T(θ)

• The transpose of a matrix is such thatMT

ij = M ji

• This holds true for arbitrary pure rotations.For matrix products

[R1(α )R2(β)]T = R T2(β)RT

1(α )

Page 23: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 23/35

General Rotation in 3D• Given a rotation axis u and a rotation

angle θ: rotate by θ around u• Basic idea:

– Translate and rotate u to align it with acoordinate axis, e.g. z-axis – Rotate around the coordinate axis by θ

– Rotate and translate u back

Page 24: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 24/35

General Rotation in 3D• Given the rotation axis u (normalized) and

the positive sense rotation angle θ

z

y

x

u =(a,b,c)

P 1 = (x 1,y1,z 1)

P 2 = (x 2,y2,z 2)

Page 25: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 25/35

General Rotation in 3D1: Translate u to the origin by T(-P 1)

1000-z1100-y1010-x1001

=T (-P 1)

Page 26: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 26/35

General Rotation in 3D2: Project u onto yz-plane ≡ u’, and obtain α3: Rotate u w.r.t x-axis by α and u will be

rotated into the xz-plane with positive z-

component. Not needed if u || u x.

z

y

x

u =(a,b,c)u’ =(0,b,c)

α

u’’ = (a,0,d)

Page 27: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 27/35

General Rotation in 3D4: Denote u x = (1,0,0) and u z = (0,0,1),

u’= (0,b,c) and let |u’| = (b 2+c 2)1/2 = d.uz·u’ = c = |u’| ∗cos( α ) = d∗cos( α )u’×u

z= d∗sin( α ) n = b ∗u

x

10000c/db/d0 0-b/dc/d0

0001

Rx(α ) =

Page 28: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 28/35

General Rotation in 3D5: Rotate u´´ w.r.t. y-axis by β s.t. u’’||u z

– u’’ has the same x-component as u: (a, , ) – u’’ has y-component zero: (a,0, ) – u’’ has as z-component |u’| because u’ has

been rotated onto the xz-plane: (a,0,d)

z

y

x

u’’ = (a,0,d)

β

Page 29: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 29/35

General Rotation in 3D• We now calculate cos( β) and sin( β):

|u’’| = (a 2+d 2)1/2 = (a 2+b 2+c 2)1/2 = 1uz·u’’ = d = |u’’| ∗cos( β) = cos( α )u’’×uz = sin( β) n = -a ∗ux

10000d0a0010

0-a0d

Ry(β) =

Page 30: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 30/35

General Rotation in 3D• Now rotate by θ w.r.t the z-axis, then

rotate back first by R y-1(β) then by R x-1(α ),and finally translate back by P 1

-1:

R(θ) = T -1(-P 1)R x-1(α )Ry

-1(β)R z(θ)R y(β)R x(α )T(-P 1)

Page 31: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 31/35

Quaternions• Another representation of rotations in

three dimensions• Other representations have advantages

and disadvantages!• Quaternions originally developed as

extensions of real numbers to complex

numbers to ???

Page 32: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 32/35

Quaternions• Quaternion number given by

q = s+a ∗i+b∗ j+c∗k = (s,a,b,c) = (s, v)• s,a,b,c ∈ℜ

• i,j,k satisfy the algebra:i∗i = j∗ j = k∗k = -1i∗ j = -j∗i = k

j∗k = -k∗ j = ik∗i = -i∗k = j

Page 33: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 33/35

Quaternions• Algebra:

|q| 2 = s 2 + a 2 + b 2 + c 2 = s 2 + v·v|q| -1∗|q| = (1,0)|q| -1 = (s,-v)/|q| 2

• Not commutative: q 1∗q2 generally unequalq2∗q1

• A point P = (x,y,z) in 3D space is repre-sented by the quaternion (0,P) = (0,x,y,z)

Page 34: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 34/35

Quaternions: Rotations• For any rotation by θ along an axis u

through the origin :

P’ = (0,x’) = q ∗P∗q -1

where q = (cos( θ /2),u∗sin( θ /2))

Page 35: ComputerGraphics 09

7/24/2019 ComputerGraphics 09

http://slidepdf.com/reader/full/computergraphics-09 35/35

3D Scaling• With the origin as fixed point, scale by s x in

the x-direction, s y in the y-direction and s zin the z-direction:

10000s

z00

00s y0000s x

wzyx

w’z’y’x’

=


Recommended