3D Mathematics - PowerPoint PPT Presentation

1 / 58
About This Presentation
Title:

3D Mathematics

Description:

3D Mathematics CIS 488/588 Bruce R. Maxim UM-Dearborn – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 59
Provided by: bma139
Category:

less

Transcript and Presenter's Notes

Title: 3D Mathematics


1
3D Mathematics
  • CIS 488/588
  • Bruce R. Maxim
  • UM-Dearborn

2
2D Polar Coordinates
  • Converting p(r,?) to p(x,y)
  • x r cos(?)
  • y r sin(?)
  • Converting p(x,y) to p(r,?)
  • x2 y2 r2
  • r sqrt(x2 y2)
  • ? tan-1(y/x)

3
3D Coordinates
  • Left-handed system
  • Negative z axis is points toward viewer
  • LaMothe uses LHS for most examples
  • Right-handed system
  • Positive z axis point toward viewer

4
3D Space
Y
Y
Z
Z
X
X
Right-handed system
Left-handed system
5
3D Cylindrical Coordinates
  • Converting p(r,?,z) to p(x,y,z)
  • x r cos(?)
  • y r sin(?)
  • z z
  • Converting p(z,x,y) to p(r,?,z)
  • r sqrt(x2 y2)
  • ? tan-1(y/x)
  • z z

6
3D Spherical Coordinates
  • Converting p(?,?,?) to p(x,y,z)
  • x ? sin(?) cos(?)
  • y ? sin(?) sin(?)
  • z ? cos(?)
  • Converting p(x,y,z) to p(?,?,?)
  • r sqrt(x2 y2 )
  • ? sqrt(x2 y2 z2)
  • ? sin-1(r/?) or ? cos-1(z/?)
  • ? tan-1(y/x)

7
Radians
  • C math library uses radians rather than degrees
    for the arguments to the trig functions
  • 1 radian 57.296 degrees
  • 1 degree 0.0175 radians
  • 2? radians 360 degrees
  • ? radians 180 degrees

8
Trigonometric Functions
  • hypotenuse2 adjacent2 opposite2
  • r2 x2 y2
  • cos(?) adj/hyp x/r 0 lt ? lt 2 ?
  • sin(?) opp/hyp y/r 0 lt ? lt 2 ?
  • tan(?) opp/adj y/x - ?/2 lt ? lt ?/2
  • ? cos-1(x) -1 lt x lt 1
  • ? sin-1(x) -1 lt x lt 1
  • ? tan-1(x) -? lt x lt ?

9
Use Trig Identities
  • csc(?) 1/sin(?)
  • sec(?) 1/cos(?)
  • cot(?) 1/tan(?)
  • sin2(?) cos2(?) 1
  • sin(?) cos(? - ?/2)
  • sin(-?) -sin(?)
  • cos(-?) cos(?)
  • sin(? ?)
  • sin(?)cos(?) cos(?)sin(?)
  • cos(? ?)
  • cos(?)cos(?) - sin(?)sin(?)
  • sin(? - ?)
  • sin(?)cos(?) - cos(?)sin(?)
  • cos(? - ?)
  • cos(?)cos(?) sin(?)sin(?)

10
Vectors - 1
  • Vector u from p1 (initial point) to p2 (terminal
    point) also written p1p2
  • u p2 p1 (x2 x1, y2 y1) ltux, uygt
  • In 3D vector space the initial point is always
    (0, 0, 0)
  • Length of 2D vector u ltux, uygt
  • u sqrt(ux2 uy2)
  • Length of 3D vector u ltux, uy, uzgt
  • u sqrt(ux2 uy2 uz2)

11
Vectors - 2
  • Vector u normalization
  • n n / n
  • Scalar multiplication vector
  • u ltux, uygt and k is real constant
  • u k ltux, uygt ltk ux, k uygt
  • Vector addition
  • u v ltux, uygt ltvx, vygt
  • ltux vx , uy vygt

12
Vectors - 3
  • Vector subtraction
  • u - v ltux, uygt - ltvx, vygt
  • ltux - vx , uy - vygt
  • Vector multiplication
  • u ? v ltux vx , uy vygt
  • Dot product (can compute vector angle)
  • u ? v ux vx uy vy
  • u ? v u v cos(?)

13
Vectors - 4
  • Length of Parallel Projection of u onto v
  • Projv u (u ? v) v / u v
  • Dot Product Multiplicative Laws
  • u ? v v ? u
  • u ? (v w) (u ? v u ? w)
  • k (u ? v) (k u) ? v (u ? (k v))

14
Vectors - 5
  • Cross Product
  • u x v u v sin(?) n
  • Cross Product Multiplication Laws
  • u x v -(v x u)
  • u x (v w) (u x v) (u x w)
  • (u v) x w (u x w) (v x w)
  • k (u x v) (k u) x v u x (k v)

15
Vectors - 6
  • Normal Vector Between u and v
  • n (uyvz vyuz, -uxvz vxuz, uxvy
    vxuy)
  • Displacement Vector p1 to p2
  • p p1 t v
  • v is unit vector in direction of p1 to p2

16
(No Transcript)
17
Matrices - 1
  • Matrix Addition and Subtraction
  • A B 1 5 13 7 14 12
  • -2 0 5 10 3 -10
  • A - B 1 5 - 13 7 -12 -2
  • -2 0 5 10 -7 10
  • Transpose
  • 5 6
  • A 2 3 AT 5 2 1
  • 1 4 6 3 4

18
Matrices - 2
  • Scalar Multiplication
  • A 1 5 2A 21 25
  • 3 0 23 20
  • Matrix Multiplication
  • A 2 3 B 5 2 1
  • 1 4 6 3 4
  • A B 2536 2233 2134
  • 1546 1243 1144
  • B A is not defined

19
Matrices - 3
  • Matrix Arithmetic Laws
  • A B B A
  • A (B C) (A B) C
  • A (B C) (A B) C
  • A (B C) A B A C
  • k (A B) k A k B
  • (A B) C A C B C
  • A I I A A

20
Matrices - 4
  • 2x2 Determinant
  • A a b Det(A) (ab bc)
  • c d
  • If Det(A) 0 system is not solvable
  • Cramers Rule for Inverse
  • A-1 1/Det(A) d b
  • -c a

21
Matrices - 4
  • Solving 2D Linear Systems
  • 3x 5y 6
  • -2x 2y 4
  • A 3 5 X x B 6
  • -2 2 y 4
  • AX B so X A-1B

22
Matrices - 5
  • Solving 3D Linear Systems
  • A X B
  • a b c j
  • A d e f B k
  • g h i l
  • Det(A) (aei bfg cdh)
  • (ceg bdi afh)

23
Matrices - 5
  • Solving 3D Linear Systems (cont)
  • j b c
  • x Det(k e f) / Det(A)
  • l h i
  • a j c
  • y Det(d k f) / Det(A)
  • g l i
  • a b j
  • z Det(d e k) / Det(A)
  • g h l

24
Homogeneous Coordinates
  • In graphics work transformation as accomplished
    by matrix multiplication
  • Customary to add an extra term w to convert
    point coordinates to homogeneous coordinates (w
    1 is common)
  • To convert from homogeneous coordinates to point
    coordinates
  • x y z w (x/w, y/w, z/w)

25
2D Matrix Transformations - 1
  • Translation
  • 1 0 0
  • x y 1 0 1 0
  • dx dy 1
  • Scaling
  • sx 0 0
  • x y 1 0 sy 0
  • 0 0 1

26
2D Matrix Transformations - 2
  • Rotation
  • cos(a) -sin(a) 0
  • x y 1 sin(a) cos(a) 0
  • 0 0 1
  • (S R) T
  • sxcos(a) sxsin(a) 0
  • x y 1 sysin(a) sycos(a) 0
  • dx dy 1

27
3D Transformations - 1
  • Translation
  • x y z 1 x y z 1 1 0 0 0
  • 0 1 0 0
  • 0 0 1 0
  • dx dy dz 1
  • Constant Axis Scaling
  • x y z 1 x y z 1 sx 0 0 0
  • 0 sy 0 0
  • 0 0 sz 0
  • 0 0 0 1

28
3D Transformations - 2
  • Inverse Translation
  • x y z 1 x y z 1 1 0 0 0
  • 0 1 0 0
  • 0 0 1 0
  • -dx -dy -dz 1
  • Inverse Constant Axis Scaling
  • x y z 1 x y z 1 1/sx 0 0 0
  • 0 1/sy 0 0
  • 0 0 1/sz 0
  • 0 0 0 1

29
3D Transformations - 3
  • Rotation Parallel to x-axis
  • x y z 1 x y z 1 1 0 0 0
  • 0 cos r sin r 0
  • 0 -sin r cos r 0
  • 0 0 0 1
  • Rotation Parallel to y-axis
  • x y z 1 x y z 1 cos r 0 -sin r 0
  • 0 1 0 0
  • sin r 0 cos r 0
  • 0 0 0 1

30
3D Transformations - 3
  • Rotation Parallel to z-axis
  • x y z 1 x y z 1 cos r sin r 0 0
  • -sin r cos r 0 0
  • 0 0 1 0
  • 0 0 0 1

31
Orthogonal Matrices
  • Each row column of the matrix is orthogonal to
    the previous for a given basis
  • Two vectors are orthogonal if
  • u v 0
  • An interesting property of orthogonal matrics is
    that MT M-1
  • Inverse rotations is simply a matter of making
    use of the transpose of the rotation matrix

32
Points and Lines
  • Points
  • x y w
  • Lines - Slope Intercept Form
  • y m x b
  • m slope
  • b y-intercepts
  • Lines General Form
  • ax by c 0
  • c (mx0 y0) for any line point (x0, y0)

33
3D Lines
  • Consider a line passing through p0 and p1
  • p0(x0, y0, z0)
  • p1(x1, y1, z1)
  • v ltx1-x0, y1-y0, z1-z0gt lta, b, cgt
  • v v / v where v ltp1 p0gt
  • Line - Parametric Vector Form
  • p(x, y, z) p0 v t
  • Line Explicit Form
  • (x x0) / a (y y0) / b (z z0) / c

34
Figure 4.38
35
Planes
  • Plane - Point-Normal Form
  • n lta, b, cgt is the plane normal vector
  • n ? p0-gtp
  • lta, b, cgt ? ltx x0, y y0, z z0gt
  • a (x x0) b (y y0) c (z z0) 0
  • Plane - General Form
  • a x b y c z d 0

36
Testing for Half-Space Containing Point
  • Use the following equation of the plane
  • hs a (x x0) b (y y0) c (z z0)
  • These are the outcomes
  • If hs 0 then point lies in plane
  • If hs gt 0 then point lies in positive half-space
  • If hs lt 0 then point lies in negative half-space
  • This can also be used for a polygon point
    containment test

37
Parametric Lines - 1
  • Line Segment
  • p p0 v t for t in a, b
  • v ltvx, vygt p0-gtp1 (x1-x0, y1-y0)
  • Segment with Standard Direction Vector v
  • p p0 v t for t in 0, 1
  • Segment with Unit Direction Vector v 1
  • p p0 v t for t in 0, v

38
Parametric Lines - 2
  • Line Segment
  • p p0 v t for t in a, b
  • v ltvx, vy, vzgt (x1-x0, y1-y0, z1 z0)
  • Intersection of Two Parametric Lines (same
    technique used for 2D and 3D)
  • Ship1 traveling p0(x0,y0) to p1(x1,y1)
  • Ship2 traveling p2(x2,y2) to p3(x3,y3)
  • v1 ltx1-x0, y1-y0gt
  • v2 ltx3-x2, y3-y2gt

39
Parametric Lines - 3
  • Intersection (continued)
  • p01 p0 v1 t1 ? 0 , 1
  • p23 p2 v2 t2 ? 0 , 1
  • For Ship1 (1,1)-gt(8,5) and Ship2 (3,6)-gt(8,3)
  • v1 lt8 1, 5 1gt lt7, 4gt
  • v2 lt8 3, 3 6gt lt5, -3gt
  • p01(x,y) (1,1) lt7,4gt t1
  • p23(x,y) (3,6) lt5, -3gt t2

40
Parametric Lines - 4
  • Intersection (continued)
  • Rewriting the equations
  • x 1 7 t1 and y 1 4 t1
  • x 3 5 t2 and y 6 3 t2
  • Eliminating x and y, then solving this system
  • 7t1 5t2 2
  • 4t1 3t2 5
  • t1 0.756 t2 0.658
  • Lines intersect if t1 ? 0,1 and t2 ? 0,1

41
Intersection Plane and Parametric Line
  • Parametric Line with t ? 0, 1
  • p(x, y, z) p0(x0,y0,z0) vltvx,vy,vzgt t
  • x x0 vxt
  • y y0 vyt
  • z z0 vzt
  • 3D Plane
  • n ? (p p0) 0
  • nx (x x0) ny (y y0) nz (z z0) 0
  • nxx nyy nzz (-nxx0 nyy0 - nzz0) 0

42
Intersection Plane and Parametric Line
  • Solving for t
  • t -(ax0 by0 cz0 d)/
  • (avx bvy cvz)
  • a nx
  • b ny
  • c nz
  • d (-nxx0 nyy0 - nzz0)
  • All this was so that we can do 3D collision
    detection

43
Complex Numbers - 1
  • Let i sqrt(-1) then sqrt(-9) 3i
  • Complex numbers have the form
  • z (a b i)
  • a is the real part and b is the imaginary part
  • Complex numbers of the form (a,b) can be graphed
    on the complex plane, a is the real axis (x) and
    b is the imaginary axis (y)

44
Complex Numbers - 2
  • Scalar Multiplication
  • k z k (a bi) ka kbi
  • Addition
  • z1 a b i
  • z2 c d i
  • z1 z2 (ac) (b d) i
  • Additive Indentity
  • (0 0i)
  • Additive Inverse
  • (a b i) (-a b i) (0 0i)

45
Complex Numbers - 3
  • Multiplication
  • z1 z2 (ac bd) (ad bc) i
  • Division
  • z1/z2 (a b i) / (c d i)
  • Need to multiply by conjugate of denominator
  • (a b i) / (c d i) (c -
    d i) / (c - d i)
  • (ac bd)/( a2 b2) (bc
    ad)/( a2 b2) i
  • Multiplicative Inverse
  • 1/z 1/(a b i) a/( a2 b2) b/( a2 b2)
    i

46
Complex Numbers - 4
  • Vector Representation
  • z a b 1
  • z lta, bgt
  • Norm of Complex Number
  • z sqrt(z z) sqrt(a2 b2)

47
Quaterions - 1
  • Hyper-Complex Numbers of the Form
  • q q0 q1 i q2 j q3 k
  • or
  • q q0 qv, where qv q1 i q2 j q3 k
  • i lt1,0,0gt, jlt0,1,0gt, klt0,0,1gt
  • ltq0,q1,q2,q3gt are all real numbers
  • i,j,k are imaginary numbers forming the basis of
    the quaterion
  • i2 j2 k2 -1 ijk

48
Quaterions - 2
  • Quaternion Addition
  • q q0 qv
  • p p0 pv
  • p q (q0 p0) (qv pv)
  • lt3,4,5,6gt lt-5,2,2,-3gt lt-2,6,7,3gt
  • Additive Inverse
  • - q -q0 - qv
  • q - q lt0,0,0,0gt

49
Quaternions - 3
  • Quaternion Multiplication
  • p p0 p1 i p2 j p3 k
  • q q0 q1 i q2 j q3 k
  • p q (p0q0 - (pv qv))
  • (p0qv q0pv pv x qv)
  • Multiplicative Identity
  • q1 1 0 i 0 j 0 k
  • q q1 q1 q q

50
Quaternions - 4
  • Quaternion Multiplication
  • q q0 q1 i q2 j q3 k q0 qv
  • q q0 q1 i q2 j q3 k q0 (- qv)
  • q q q02 q12 q22 q32
  • Norm of a Quaternion
  • q sqrt(q02 q12 q22 q32) sqrt(q q)
  • q2 (q q)
  • Quaternion Inverse
  • q-1 q / q2
  • q q-1 1 q-1 q
  • for unit Quaternion q-1 q

51
Quaternion Uses
  • Can be for ordinary 3D rotatiosn and
    interpolation of rotation
  • LaMothe uses quaternions to interpolate between
    different camera angles
  • Quaternions with their 4D character can handle
    rotation of a 3D object around an arbitrary axis
    more easily than vectors
  • So if you have lots of matrix multiplication in a
    loop switch to quaternions

52
Figure 4.44
53
Quaternion Rotation
  • v ltx,y,zgt
  • vq lt0,x,y,zgt note q0 0
  • q is unit quaternion
  • Right-handed System
  • vq q vq q clockwise rotation
  • vq q vq q counter-clockwise rotation
  • Left-handed System
  • vq q vq q clockwise rotation
  • vq q vq q counter-clockwise rotation

54
Figure 4.45
55
Conversion of Axis and Angle
  • For a unit quaternion
  • vq is the vector being rotated
  • q q0 qv cos(?/2) sin(?/2) vq
  • qv is the axis of rotation sin(?/2) vq
  • q0 contains angle of rotation cos(?/2)
  • If you dont have an vector to rotate around you
    can compute a product like
  • qfinal qz0 qy0 qx0
  • roll yaw pitch

56
Euler Angles for Quaternion - 1
  • qx0 cos(x0 / 2) sin(x0 / 2) i 0 j 0
    k
  • q0 cos(x0 / 2) , qv ltsin(x0 / 2) , 0, 0gt
  • qy0 cos(y0 / 2) 0 i sin(y0 / 2 j 0
    k
  • q0 cos(y0 / 2) , qv lt0, sin(y0 / 2) , 0gt
  • qz0 cos(z0 / 2) 0 i 0 j sin(z0 / 2)
    k
  • q0 cos(z0 / 2) , qv lt0, 0, sin(z0 / 2)gt
  • Rotation
  • vq(0,x,y,z) (qz0 qy0 qx0) vq (qz0
    qy0 qx0)
  • vq lt0,y,y,zgt

57
Euler Angles for Quaternion - 2
  • Each of the factors qx? qy? qz?
  • q(i,j,k) cos(? / 2) sin(x0 / 2) (i , j , k)
  • The product qz? qy? qx? ends up as
  • q0 cos(z?/2) cos(y?/2) cos(x?/2)
  • sin(z?/2) sin(y?/2) sin(x?/2)
  • q1 cos(z?/2) cos(y?/2) sin(x?/2) -
  • sin(z?/2) sin(y?/2) cos(x?/2)
  • q2 cos(z?/2) sin(y?/2) cos(x?/2)
  • sin(z?/2) cos(y?/2) sin(x?/2)
  • q0 sin(z?/2) cos(y?/2) cos(x?/2) -
  • cos(z?/2) sin(y?/2) sin(x?/2)

58
Calculus Rdeview
  • Pages 337 to 361
Write a Comment
User Comments (0)
About PowerShow.com