44
Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi

Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Computer Graphics

Subodh Kumar

Dept of Computer Sc. & Engg. IIT Delhi

Page 2: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Projection of Points

! Intersection of a path with a shape ! Linear projection: path is a line ! Path originates at the point ! We will consider planar shape ! Line is given by a direction

! Perspective ! Line to a given ‘center of projection’

! Parallel ! Line in a given direction ! Orthographic, Oblique

19

Page 3: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Perspective Projection

20

Parallelism is not preserved

Page 4: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Parallel Projection

! Transform plane of projection to Z = -1

Z = -1

Y

Z

yy'

z

y' = y, z' = -1 x' = x O

(x,y,z)(x’, y’, z')

z' = -1?

1 0 0 0 0 1 0 0 0 0 0 -1 0 0 0 1

x y z 1

Page 5: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Perspective

! Transform plane of projection to Z = -1

Z = -1

Y

Z O

yy'

zy'/-1 = y/z ⇒ y' = -y/z x' = -x/z

(x,y,z)

(x’, y’, z')

z' = -1?

Page 6: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

! Also normalize the image space ! Image X, Y lie in [-1:1]

Perspective II

Z = -zv

y

ZO

zv tanθ

z

Normalized y': y'' = y'/(zv tanθ) = -y/z cotθ

θ FOV/2

Image Plane

y'

(x,y,z)

(x’, y’, z')

y' = -zv y/z

x'' = -y/z cotθ

Page 7: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Viewport

! Further, if we want ! X to lie in [0:Screen-Width] ! Y to lie in [0:Screen-Height]

! Xscreen = (Ximage + 1)/2 * Width

! Yscreen = (Yimage + 1)/2 * Height

Page 8: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Projective Space

! n-dimensional projective space is constructed from an n+1-dimensional vector space ! Where, aP = P ! (0,0,0,…) is undefined

! The original space is a projection of this n+1-dimensional vector space ! x, y, z, w = x/w, y/w, z/w, 1 = affine space ! Except when w=0: x, y, z, 0 = x/z, y/z, 1, 0

! Except when z = 0 …

! w is called the homogeneous coordinate

Page 9: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Projective Plane

x

yw

w=1

x = uw, y = vw, ie, uw u vw = v w 1

Page 10: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Perspective

! Transform plane of projection to Z = -1

Z = -1

Y

Z O

yy'

zy'/-1 = y/z ⇒ y' = -y/z x' = -x/z

(x,y,z)

(x’, y’, z')

z' = -1?

2

664

1 0 0 00 1 0 00 0 1 00 0 �1 1

3

775

x y z 1

x y z -z

=

Image Plane

Page 11: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

! Also normalize the image space ! Image X, Y lie in [-1:1]

Perspective

Z = -zv

y

ZO

zv tanθ

z

Normalized y': y'' = y'/(zv tanθ) = -y/z cotθ

θ FOV/2

y'

(x,y,z)

(x’, y’, z')

x'' = -y/z cotθ

Image Plane

Page 12: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Perspective III

! What if we also want Z to lie in [0:1] ! -Znear ➔ 0

! -Zfar ➔ 1

Page 13: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

2

664

1 0 0 dx0 1 0 dy0 0 1 dz0 0 0 1

3

775

2

664

xyz1

3

775=

2

664

x+ dxx+ dyz + dz

1

3

775

2

664

sx 0 0 00 sy 0 00 0 sz 00 0 0 1

3

775

2

664

xyz1

3

775=

2

664

x.sxx.syz.sz1

3

775

2

664

cos↵ sin↵ 0 0� sin↵ cos↵ 0 0

0 0 1 00 0 0 1

3

775

2

664

xyz1

3

775=

2

664

x cos↵+ y sin↵�x sin↵+ y cos↵

z1

3

775

Examples of Xform Matrices

Translation by dx, dy, dz Scaling by sx, sy, sz

Rotation by α (about Z)

Page 14: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Change of Basis

! New basis: ! Orthonormal axes:

V1, V2, V3 ! Origin: O

O

v1v2

Page 15: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Change of Basis

! New basis: ! Orthonormal axes:

V1, V2, V3 ! Origin: O

O

v1v2

Page 16: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Change of Basis

! New basis: ! Orthonormal axes:

V1, V2, V3 ! Origin: O

O

v1v2

Page 17: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Change of Basis

! New basis: ! Orthonormal axes:

V1, V2, V3 ! Origin: O

2

664

— V1 — 0— V2 — 0— V3 — 0

0 0 0 1

3

775

2

664

1 0 0 �Ox

0 1 0 �Oy

0 0 1 �Oz

0 0 0 1

3

775

O

v1v2

Page 18: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Change of Basis

! New basis: ! Orthonormal axes:

V1, V2, V3 ! Origin: O

2

664

— V1 — 0— V2 — 0— V3 — 0

0 0 0 1

3

775

2

664

1 0 0 �Ox

0 1 0 �Oy

0 0 1 �Oz

0 0 0 1

3

775

O

v1v2

— V1 — — V2 — — V3 —

0 0 0 1

-V1 · O-V2 · O-V3 · O

Page 19: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Change of Basis

! New basis: ! Orthonormal axes:

V1, V2, V3 ! Origin: O

2

664

— V1 — 0— V2 — 0— V3 — 0

0 0 0 1

3

775

2

664

1 0 0 �Ox

0 1 0 �Oy

0 0 1 �Oz

0 0 0 1

3

775

O

v1v2

1,0

0,1

1,00,1

0,0

Page 20: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Change of Basis

! New basis: ! Orthonormal axes:

V1, V2, V3 ! Origin: O

2

664

— V1 — 0— V2 — 0— V3 — 0

0 0 0 1

3

775

2

664

1 0 0 �Ox

0 1 0 �Oy

0 0 1 �Oz

0 0 0 1

3

775

O

v1v2

1,0

0,1

1,00,1

0,0

Page 21: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Change of Basis

! New basis: ! Orthonormal axes:

V1, V2, V3 ! Origin: O

2

664

— V1 — 0— V2 — 0— V3 — 0

0 0 0 1

3

775

2

664

1 0 0 �Ox

0 1 0 �Oy

0 0 1 �Oz

0 0 0 1

3

775

O

v1v2

1,0

0,1

1,00,1

0,0

Page 22: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Change of Basis

! New basis: ! Orthonormal axes:

V1, V2, V3 ! Origin: O

2

664

— V1 — 0— V2 — 0— V3 — 0

0 0 0 1

3

775

2

664

1 0 0 �Ox

0 1 0 �Oy

0 0 1 �Oz

0 0 0 1

3

775

O

v1v2

1,0

0,1

1,00,1

0,0

Page 23: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

World to Camera

! Centre of projection/Camera position! O

! Reference point/Lookat point: L! V3 = (O-L)/|O-L|

! Camera orientation/Up vector! T = U/|U|! V1 = T x V3! V2 = V3 x V1

33

Page 24: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

World to Camera

! Centre of projection/Camera position! O

! Reference point/Lookat point: L! V3 = (O-L)/|O-L|

! Camera orientation/Up vector! T = U/|U|! V1 = T x V3! V2 = V3 x V1

33

M: Model ➔ World V: World ➔ Camera P: Camera ➔ Normalized Screen ModelView, VM: Model ➔ Camera? PVM: Model ➔ Normalized Screen?

Page 25: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Composition: Fixed frame

! T(1,0) ! R(90) ! R T p

Page 26: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Composition: Fixed frame

! T(1,0) ! R(90) ! R T p

Page 27: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Composition: Fixed frame

! T(1,0) ! R(90) ! R T p

Page 28: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Composition: Fixed frame

! T(1,0) ! R(90) ! R T p

Page 29: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Composition: Local frame

! R(90) ! T(1,0) ! R T p?

! T(1,0) ! R(90) ! R T p

x

y

Page 30: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Composition: Local frame

! R(90) ! T(1,0) ! R T p?

! T(1,0) ! R(90) ! R T p

x

y

Page 31: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Composition: Local frame

! R(90) ! T(1,0) ! R T p?

! T(1,0) ! R(90) ! R T p

x

y

Page 32: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Composition: Local frame

! R(90) ! T(1,0) ! R T p?

! T(1,0) ! R(90) ! R T p

x

y

Page 33: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

World to Camera

! Centre of projection/Camera position ! O

! Reference point/Lookat point: L ! V3 = (O-L)/|O-L|

! Camera orientation/Up vector ! T = U/|U| ! V1 = T x V3 ! V2 = V3 x V1

37

M: Model ➔ World V: World ➔ Camera P: Camera ➔ Normalized Screen ModelView, VM: Model ➔ Camera PVM: Model ➔ Normalized Screen

Page 34: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Transformation of Normals

Page 35: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Transformation of Normals

Page 36: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Transformation of Normals

Page 37: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Transformation of Normals

n.d = 0nTd = 0=> n'T Md must be 0=> (M'n)T Md = 0=> nTM'T Md = 0=> M'T M = k I=> M'T = k M-1

=> M' = (M-1)T (Choose k = 1)

n

d

Page 38: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Transformation Recap

! General transformation = ! Composition of known special transformations

! Transformation is equivalent to an inverse change of basis

! Be mindful of space in which ! the transformation is specified ! the vertex/vector is specified

! [M1 M2 M3 … Mk] V = ! Mk then Mk-1 until M1 in world-coordinates

! M1, then M2, until Mk in object-coordinates

Page 39: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

3D Interaction

! Specify point (3 DOF) ! Specify orientation (3 DOF) ! Navigate (6 DOF)

! Manipulate object ! Manipulate eye/walk ! Specify path

! Select an object or region in space ! Find out its location and orientation

40

Page 40: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

3D Interface! Mouse provide a 2D input (+ buttons)

! 2D location ! Up-down, Left-right motion ! 2D rotation

! 3D navigation has 6 DOF ! Up / Down ! Forward / Backward ! Left / Right ! Pitch (transverse axis) ! Yaw (normal axis) ! Roll (longitudinal axis)

41

cf Hoffman

Yaw

Pitch

Roll

Page 41: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Rotation by Euler angles

42

Yaw

Pitch

Roll

Gimbal Lock

! Interpolation, Composition is non-intuitive

Page 42: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Trackball Interface

! Inspect an object ! Imagine rotating a sphere by a handle

! Map planar 2D motion onto unit sphere ! Raise old position <x0, z0> to <x0, y0, z0>

! Raise new position <x1, z1> to <x1, y1, z1>

! Find rotation that moves handle from old to new

Page 43: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Trackball

! p1: x12+y1

2+z12 = 1

! p2: x22+y2

2+z22 = 1

! Ball rotates about the axis formed by p1 and p2

! p1 X p2

! Rotation angle proportional to the distance p1p2

! Or simply ||p1 X p2||

Page 44: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhisubodh/courses/CSL781/pdf... · Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi. Projection of Points! Intersection of a path

Trackball

! p1: x12+y1

2+z12 = 1

! p2: x22+y2

2+z22 = 1

! Ball rotates about the axis formed by p1 and p2

! p1 X p2

! Rotation angle proportional to the distance p1p2

! Or simply ||p1 X p2||

! What happens if the object is not at the origin?