ubi 516 advanced computer graphics

34
Mathematical Foundations UBI 516 Advanced Computer Graphics Aydın Öztürk [email protected] http://www.ube.ege.edu.tr/~ozturk

Upload: bruno-lott

Post on 01-Jan-2016

19 views

Category:

Documents


2 download

DESCRIPTION

UBI 516 Advanced Computer Graphics. Aydın Öztürk ozturk @ ube.ege.edu.tr http://www. ube.ege.edu.tr/~ozturk. Mathematical Foundations. Mathematical Foundations. Hearn and Baker (A1 – A4) appendix gives good review - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: UBI 516 Advanced Computer Graphics

Mathematical Foundations

UBI 516 Advanced Computer Graphics

UBI 516 Advanced Computer Graphics

Aydın Öztürk

[email protected]://www.ube.ege.edu.tr/~ozturk

Page 2: UBI 516 Advanced Computer Graphics

Mathematical Foundations

Hearn and Baker (A1 – A4) appendix gives good review

I’ll give a brief, informal review of some of the mathematical tools we’ll employ– Geometry (2D, 3D)– Trigonometry– Vector spaces

Points, vectors, and coordinates

– Dot and cross products– Linear transforms and matrices– Complex numbers

Page 3: UBI 516 Advanced Computer Graphics

2D Geometry

Know your high school geometry:– Total angle around a circle is 360° or 2π radians

– When two lines cross: Opposite angles are equivalent Angles along line sum to 180°

– Similar triangles: All corresponding angles are equivalent

Page 4: UBI 516 Advanced Computer Graphics

Trigonometry

Sine: “opposite over hypotenuse” Cosine: “adjacent over hypotenuse” Tangent: “opposite over adjacent” Unit circle definitions:

– sin () = y

– cos () = x

– tan () = y/x

– Etc…

(x, y)

Page 5: UBI 516 Advanced Computer Graphics

Slope-intercept Line Equation

Slope:

Solve for y:

or:

y = mx + b

) - x) / (x - y (y

) ) / (x - xy - ym

1212

11(

x

y

111212

1212

)]()([

)]()[(

y x - xx/-yy-

x - xx/ - yyy

)(x, y P

),( 111 yxP

)( 222 , yx P

Page 6: UBI 516 Advanced Computer Graphics

Parametric Line Equation Given points and

When:– u=0, we get – u=1, we get– (0<u<1), we get points

on the segment between and

),( 111 yxP

x

y

),( 222 yxP

)(

)(

121

121

yyuyy

xxuxx

),( 111 yxP

),( 222 yxP ),( 11 yx

),( 11 yx

),( 22 yx

),( 22 yx

Page 7: UBI 516 Advanced Computer Graphics

Other helpful formulas

Length =

Two lines perpendicular if:

Cosine of the angle between them is 0.

212

212 )()( yyxx

2

,2

: and between Midpoint

3131 yyxx2

312

P

PPP

21 /1 MM

Page 8: UBI 516 Advanced Computer Graphics

Coordinate Systems

2D systems Cartesian system Polar coordinates

3D systems Cartesian system

1) Right-handed

2) Left handed

Cylindiric system Spherical system

Page 9: UBI 516 Advanced Computer Graphics

Coordinate Systems(cont.)

Z

X

YY

X

Z

Right-handedcoordinatesystem

Left-handedcoordinatesystem

Grasp z-axis with handRoll fingers from positive x-axis towards positive y-axisThumb points in direction of z-axis

Page 10: UBI 516 Advanced Computer Graphics

Points

Points support these operations:– Point-point subtraction: Q - P = v

Result is a vector pointing from P to Q

– Vector-point addition: P + v = Q Result is a new point

– Note that the addition of two points

is not defined

P

Q

v

Page 11: UBI 516 Advanced Computer Graphics

Vectors

We commonly use vectors to represent:– Points in space (i.e., location)– Displacements from point to point– Direction (i.e., orientation)

Page 12: UBI 516 Advanced Computer Graphics

Vector Spaces

Two types of elements:– Scalars (real numbers): … – Vectors (n-tuples): u, v, w, …

Operations:– Addition– Subtraction– Dot Product– Cross Product– Norm

Page 13: UBI 516 Advanced Computer Graphics

Vector Addition/Subtraction

– operation u + v, with: Identity 0 v + 0 = v Inverse - v + (-v) = 0

– Vectors are “arrows” rooted at the origin– Addition uses the “parallelogram rule”:

u+vy

xu

v

u-v

y

x

uv

-v

Page 14: UBI 516 Advanced Computer Graphics

Scalar Multiplication

– Scalar multiplication: Distributive rule:(u + v) = (u) + (v)

( + )u = u + u

– Scalar multiplication “streches” a vector, changing its length (magnitude) but not its direction

Page 15: UBI 516 Advanced Computer Graphics

Dot Product The dot product or, more generally, inner product of

two vectors is a scalar:v1 • v2 = x1x2 + y1y2 + z1z2 (in 3D)

Useful for many purposes– Computing the length (Euclidean Norm) of a vector: length(v)

= ||v|| = sqrt(v • v)

– Normalizing a vector, making it unit-length: v = v / ||v||– Computing the angle between two vectors:

u • v = ||u|| ||v|| cos(θ)

– Checking two vectors for orthogonality u • v = 0

v

Page 16: UBI 516 Advanced Computer Graphics

u

Dot Product

Projecting one vector onto another– If v is a unit vector and we have another vector, w– We can project w perpendicularly onto v

– And the result, u, has length w • v

w

v

wv

wv

wvw

θwu

(

)cos(

Page 17: UBI 516 Advanced Computer Graphics

Dot Product

Is commutative– u • v = v • u

Is distributive with respect to addition– u • (v + w) = u • v + u • w

Page 18: UBI 516 Advanced Computer Graphics

Cross Product

The cross product or vector product of two vectors is a vector:

The cross product of two vectors is orthogonal to both

Right-hand rule dictates direction of cross product

),,( 21212121212121 xyyxzxxzyzzy vv

Page 19: UBI 516 Advanced Computer Graphics

Cross Product Right Hand Rule

See: http://www.phy.syr.edu/courses/video/RightHandRule/index2.html

Orient your right hand such that your palm is at the beginning of A and your fingers point in the direction of A

Twist your hand about the A-axis such that B extends perpendicularly from your palm

As you curl your fingers to make a fist, your thumb will point in the direction of the cross product

Page 20: UBI 516 Advanced Computer Graphics

Cross Product Right Hand Rule

See: http://www.phy.syr.edu/courses/video/RightHandRule/index2.html

Orient your right hand such that your palm is at the beginning of A and your fingers point in the direction of A

Twist your hand about the A-axis such that B extends perpendicularly from your palm

As you curl your fingers to make a fist, your thumb will point in the direction of the cross product

Page 21: UBI 516 Advanced Computer Graphics

Cross Product Right Hand Rule

See: http://www.phy.syr.edu/courses/video/RightHandRule/index2.html

Orient your right hand such that your palm is at the beginning of A and your fingers point in the direction of A

Twist your hand about the A-axis such that B extends perpendicularly from your palm

As you curl your fingers to make a fist, your thumb will point in the direction of the cross product

Page 22: UBI 516 Advanced Computer Graphics

Cross Product Right Hand Rule

See: http://www.phy.syr.edu/courses/video/RightHandRule/index2.html

Orient your right hand such that your palm is at the beginning of A and your fingers point in the direction of A

Twist your hand about the A-axis such that B extends perpendicularly from your palm

As you curl your fingers to make a fist, your thumb will point in the direction of the cross product

Page 23: UBI 516 Advanced Computer Graphics

Cross Product Right Hand Rule

See: http://www.phy.syr.edu/courses/video/RightHandRule/index2.html

Orient your right hand such that your palm is at the beginning of A and your fingers point in the direction of A

Twist your hand about the A-axis such that B extends perpendicularly from your palm

As you curl your fingers to make a fist, your thumb will point in the direction of the cross product

Page 24: UBI 516 Advanced Computer Graphics

Triangle Arithmetic

Consider a triangle, (a, b, c)– a,b,c = (x,y,z) tuples

Surface area = sa = ½ * ||(b –a) X (c-a)||

Unit normal = (1/2sa) * (b-a) X (c-a)

a c

b

Page 25: UBI 516 Advanced Computer Graphics

Vector Spaces

A linear combination of vectors results in a new vector:

v = 1v1 + 2v2 + … + nvn

If the only set of scalars such that

1v1 + 2v2 + … + nvn = 0

is 1 = 2 = … = 3 = 0

then we say the vectors are linearly independent The dimension of a space is the greatest number of

linearly independent vectors possible in a vector set For a vector space of dimension n, any set of n

linearly independent vectors form a basis

Page 26: UBI 516 Advanced Computer Graphics

Vector Spaces: Basis Vectors

Given a basis for a vector space:– Each vector in the space is a unique linear

combination of the basis vectors– The coordinates of a vector are the scalars from

this linear combination– If basis vectors are orthogonal and unit length:

Vectors comprise orthonormal basis

– Best-known example: Cartesian coordinates– Note that a given vector v will have different

coordinates for different bases

Page 27: UBI 516 Advanced Computer Graphics

Matrices

Matrix addition

Matrix multiplication

Matrix tranpose

Determinant of a matrix

Matrix inverse

Page 28: UBI 516 Advanced Computer Graphics

Complex numbersA complex number z is an ordered pair of real

numbers

z = (x,y), x = Re(z), y = Im(z)

Addition, substraction and scalar multiplication of complex numbers are carried out using the same rules as for two-dimensional vectors.

Multiplication is defined as (x1 , y1 )(x2, y2) = (x1 x2 – y1 y2 , x1y2+ x2 y1)

Page 29: UBI 516 Advanced Computer Graphics

Complex numbers(cont.)

Real numbers can be represented as

x = (x, 0)

It follows that (x1 , 0 )(x2 , 0) = (x1 x2 ,0)

i = (0, 1) is called the imaginary unit.

We note that i2 = (0, 1) (0, 1) = (-1, 0).

Page 30: UBI 516 Advanced Computer Graphics

Complex numbers(cont.)

Using the rule for complex addition, we can write any complex number as the sum

z = (x,0) + (0,y)

= x + iy

Which is the usual form used in practical applications.

Page 31: UBI 516 Advanced Computer Graphics

Complex numbers(cont.)The complex conjugate is defined as

z , = x -iy

Modulus or absolute value of a complex number is

|z| = z z , = √ (x2 +y2)

Division of of complex numbers:

21

21

2

1~

~

zz

zz

z

z

Page 32: UBI 516 Advanced Computer Graphics

Complex numbers(cont.)Polar coordinate representation

ire

iSinCosr

riSinrCosz

)(

Page 33: UBI 516 Advanced Computer Graphics

Complex numbers(cont.)

Complex multiplication

)(

2

121

)(2121

21

21

/

i

i

er

rzz

errzz

Page 34: UBI 516 Advanced Computer Graphics

Conclusion

Read Chapters 1 – 3 of OpenGL Programming Guide