33
Geometric transformations in 3D and coordinate frames Computer Graphics CSE 167 Lecture 3

Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

  • Upload
    others

  • View
    14

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Geometric transformations in 3D and coordinate frames

Computer Graphics

CSE 167

Lecture 3

Page 2: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

CSE 167: Computer Graphics

• 3D points as vectors

• Geometric transformations in 3D

• Coordinate frames

CSE 167, Winter 2020 2

Page 3: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Representing 3D points using vectors

• 3D point as 3-vector

• 3D point using affine homogeneous coordinates as 4-vector

CSE 167, Winter 2020 3

Page 4: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Geometric transformations

• Translation• Linear transformations

– Scale– Rotation

• 3D rotations• Affine transformation

– Linear transformation followed by translation

• Euclidean transformation– Rotation followed by translation

• Composition of transformations• Transforming normal vectors

CSE 167, Winter 2020 4

Page 5: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

3D translation

CSE 167, Winter 2020 5

Usinghomogeneous

coordinates

Page 6: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

3D uniform scale

CSE 167, Winter 2020 6

Usinghomogeneous

coordinates

Page 7: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

3D nonuniform scale

CSE 167, Winter 2020 7

Usinghomogeneous

coordinates

Page 8: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

3D rotation about X-axis

CSE 167, Winter 2020 8

Page 9: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

3D rotation about Y-axis

CSE 167, Winter 2020 9

Page 10: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

3D rotation about Z-axis

CSE 167, Winter 2020 10

Page 11: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Rotation matrix

• A rotation matrix is a special orthogonal matrix

– Properties of special orthogonal matrices

• Transformation matrix using homogeneous coordinates

CSE 167, Winter 2020 11

The inverse of a special orthogonal matrix is

also a special orthogonal matrix

Page 12: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

3D rotations

• A 3D rotation can be parameterized with three numbers

• Common 3D rotation formalisms– Rotation matrix

• 3x3 matrix (9 parameters), with 3 degrees of freedom

– Euler angles• 3 parameters

– Euler axis and angle• 4 parameters, axis vector (to scale)

– Quaternions• 4 parameters (to scale)

CSE 167, Winter 2020 12

Page 13: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

3D rotation, Euler angles

• A sequence of 3 elemental rotations

• 12 possible sequences

– Example: Roll-Pitch-Yaw (ZYX convention)

• Rotation about X-axis, followed byrotation about Y-axis, followed byrotation about Z-axis

CSE 167, Winter 2020 13

X-Y-XX-Y-ZX-Z-XX-Z-Y

Y-X-YY-X-ZY-Z-XY-Z-Y

Z-X-YZ-X-ZZ-Y-XZ-Y-Z

Tait-Bryan angles, also

Composition of rotations

Page 14: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

3D rotation, Euler axis and angle

• 3D rotation about an arbitrary axis

– Axis defined by unit vector

• Corresponding rotation matrix

CSE 167, Winter 2020 14

Cross product revisited

Page 15: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

3D affine transformation

• Linear transformation followed by translation

CSE 167, Winter 2020 15

Usinghomogeneous

coordinates

A is linear transformation

matrix

t is translation vector

Notes:1. Invert an affine transformation using a general 4x4 matrix inverse2. An inverse affine transformation is also an affine transformation

Page 16: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Affine transformation using homogeneous coordinates

• Translation

– Linear transformation is identity matrix

• Scale

– Linear transformation is diagonal matrix

• Rotation

– Linear transformation is special orthogonal matrix

CSE 167, Winter 2020 16

A is linear transformation

matrix

Page 17: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

3D Euclidean transformation

• Rotation followed by translation

CSE 167, Winter 2020 17

Usinghomogeneous

coordinates

A Euclidean transformation

is an affine transformation where

the linear component is a rotation

Page 18: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Inverse Euclidean transformation

CSE 167, Winter 2020 18

Usinghomogeneous

coordinates

An inverse Euclidean transformation

is also a Euclidean transformation

Euclidean transformation

Inverse Euclidean transformation

Use this instead of a general 4x4 matrix inverse

Page 19: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Composition of transformations

• Compose geometric transformation by multiplying 4x4 transformation matrices

CSE 167, Winter 2020 19

Composition of two transformations Composition of n transformations

Order of matrices is important!Matrix multiplication is not (in general) commutative

Page 20: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Transforming normal vectors

• Tangent vector v at surface point X is orthogonal to normal vector n at X

• Transformed tangent vector and transformed normal vector must also be orthogonal

CSE 167, Winter 2020 20

Page 21: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Transforming normal vectors

• Tangent vector can be thought of as a difference of points, so it transforms the same as a surface point

• Normal vector does not transform the same as tangent vector

CSE 167, Winter 2020 21

How is M related to A?

We are only concerned about direction of vectors, so do not

add translation vector

Page 22: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Transforming normal vectors

• How is M related to A?

• Solve for M

• Transform normal vectors using

CSE 167, Winter 2020 22

Page 23: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Coordinate frames

• In computer graphics, we typically use at least three coordinate frames

– Object (or Model) coordinate frame

– World coordinate frame

– Camera (or Eye) coordinate frame

CSE 167, Winter 2020 23World coordinates

Object

coordinates

Camera

coordinates

Based on slides courtesy of Jurgen Schulze

Page 24: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Object (or Model) coordinates

• Local coordinates in which points and other object geometry are given

• Often origin is the geometric center, on the base, or in a corner of the object

– Depends on how object is generated or used

CSE 167, Winter 2020 24

World coordinates

Object

coordinates

Camera

coordinates

Source: http://motivate.maths.org

Page 25: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

World coordinates

• Common reference frame for all objects in the scene

• No standard for coordinate frame orientation

– If there is a ground plane, usually X-Y plane is horizontal and positive Z is up

– Otherwise, X-Y plane is often screen plane and positive Z is out of the screen

CSE 167, Winter 2020 25World coordinates

Object

coordinates

Camera

coordinates

Page 26: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Object (or Model) transformation

• The transformation from object (or model) coordinates to world coordinates is different for each object

• Defines placement of object in scene

• Given by “model matrix” (model-to-world transformation) M

CSE 167, Winter 2020 26World coordinates

Object

coordinates

Camera

coordinates

Page 27: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Camera (or eye) coordinates

• Origin defines center of projection of camera (or eye)

• X-Y plane is parallel to image plane

• Z-axis is orthogonal to image plane

CSE 167, Winter 2020 27

World coordinates

Object

coordinates

Camera

coordinates

Page 28: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Camera (or eye) coordinates

• The “camera matrix” defines the transformation from camera (or eye) coordinates to world coordinates

– Placement of camera (or eye) in world

CSE 167, Winter 2020 28

World coordinates

Object

coordinates

Camera

coordinates

Page 29: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Camera matrix

• Given:

– Center point of projection e

– Look at point d

– Camera up vector u

CSE 167, Winter 2020 29

World coordinates

Camera

coordinates

u

e

d

Page 30: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Camera matrix• Construct xc, yc, zc

World coordinates

Camera

coordinates

30

u

e

d

CSE 167, Winter 2020

Page 31: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Camera matrix

• Step 1: Z-axis

• Step 2: X-axis

• Step 3: Y-axis

• Camera Matrix:

CSE 167, Winter 2020 31

𝒛𝐶 =𝒆 − 𝒅

𝒆 − 𝒅

𝒙𝐶 =𝒖 × 𝒛𝐶𝒖 × 𝒛𝐶

𝒚𝐶 = 𝒛𝐶 × 𝒙𝐶 =𝒖

𝒖

𝑪 =𝒙𝐶 𝒚𝐶 𝒛𝐶 𝒆0 0 0 1

Page 32: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Transforming object (or model) coordinates to camera (or eye) coordinates

• Object to world coordinates: M

• Camera (or eye) to world coordinates: C

CSE 167, Winter 2020 32

Use inverse of Euclidean

transformation (slide 18) instead of a general 4x4 matrix inverse

World coordinates

Object

coordinates

Camera

coordinatesThe “view matrix” defines the transformation from

world coordinates to camera (or eye) coordinates

Page 33: Geometric transformations in 3D and coordinate framescseweb.ucsd.edu/classes/wi20/cse167-a/lec3.pdf · Geometric transformations in 3D and coordinate frames Computer Graphics CSE

Objects in camera (or eye) coordinates

• We have things lined up the way we like them on screen– The positive X-axis points to the right

– The positive Y-axis points up

– The positive Z-axis points out of the screen

– Objects to look at are in front of us, i.e., have negative Z values

• But objects are still in 3D

• Next step: project scene to 2D plane

CSE 167, Winter 2020 33