1 of 162

Nima Kalantari

CSCE 441 - Computer Graphics

Transformations 3D & Coordinates

Some slides from Ren Ng and Shinjiro Sueda; Some inspired by Steve Seitz

2 of 162

3D Transformations

  • Use homogeneous coordinates again:
    • 3D point = (x, y, z, 1)T
    • 3D vector = (x, y, z, 0)T
  • Use 4×4 matrices for affine transformations

3 of 162

3D Transformations

  • Scale
  • Translation

4 of 162

3D Transformations

  • Rotation around x-, y-, or z-axis

y

z

x

Rotation �around �x-axis

5 of 162

3D Rotations

  • Compose any 3D rotation from Rx, Ry, Rz?
    • So-called Euler angles
    • Often used in flight simulators: roll (x), pitch (y), yaw (z)
    • Order matters!

z

y

x

6 of 162

Rodrigues’ Rotation Formula

  • Rotation by angle α around axis n

7 of 162

Transformations

  • Transform point and vectors
    • E.g., move an object in the scene

  • Transform coordinates
    • E.g., transform coordinate of the driver from car coordinate to the world coordinate

8 of 162

How do we transform a mesh?

  • Transform each one of the vertex positions by a transformation matrix

p1

M

p’1

p’1 = Mp1

9 of 162

How do we transform a mesh?

  • Transform each one of the vertex positions by a transformation matrix

p2

M

p’2

p’2 = Mp2

10 of 162

How do we transform coordinates?

11 of 162

Coordinate Frames

  • Any set of 3 vectors (in 3D) so that

12 of 162

Coordinate Change: 2D Example

World

13 of 162

Coordinate Change: 2D Example

World

14 of 162

Coordinate Change: 2D Example

15 of 162

Coordinate Change: 2D Example

16 of 162

Coordinate Change: Extension to 3D

17 of 162

Chain coordinate transforms

1

2

3

4

18 of 162

Hierarchical transformation

19 of 162

Make a Robot Arm

20 of 162

Make a Robot Arm

  • We start from a box
  • Shrink vertically by 50%

Target

S

21 of 162

Make a Robot Arm

Target

S

22 of 162

Make a Robot Arm

Target

S

S

23 of 162

Make a Robot Arm

Target

S

S

T

24 of 162

Make a Robot Arm

Target

S

S

T

25 of 162

Make a Robot Arm

Target

S

S

T

S

26 of 162

Make a Robot Arm

Target

S

S

T

S

T

27 of 162

Make a Robot Arm

Target

S

S

T

S

T

R

28 of 162

Make a Robot Arm

Target

S

S

T

S

T

R

29 of 162

Make a Robot Arm

  • Find a point you want to fix
  • Move it to origin
  • Then apply the transform
    • Rotation in this case

30 of 162

Make a Robot Arm

Target

S

S

T

S

31 of 162

Make a Robot Arm

Target

S

S

T

S

T

32 of 162

Make a Robot Arm

Target

S

S

T

S

T

33 of 162

Make a Robot Arm

Target

S

S

T

S

T

R

34 of 162

Make a Robot Arm

Target

S

S

T

S

T

R

T

35 of 162

Make a Robot Arm

Target

S

S

T

S

T

R

T

36 of 162

Problems

  • We need to come up with the matrices manually!!

TRTRTS

37 of 162

Problems

  • Redo all the transformations!!

38 of 162

Hierarchical Modeling

Global Coordinate

39 of 162

Hierarchical Modeling

  • Perform transformation in local (joint) coordinates!

40 of 162

Hierarchical Modeling

Sp

Sp

Sp

41 of 162

Hierarchical Modeling

Tp

Tp

Tp

Sp

Sp

Sp

42 of 162

Hierarchical Modeling

  • How do we get the local (joint) coordinates?

Sp

Sp

Sp

Tp

Tp

Tp

43 of 162

Hierarchical Modeling

Sp

Sp

Sp

Tp

Tp

Tp

44 of 162

Hierarchical Modeling

Sp

Sp

Sp

Tp

Tp

Tp

Rc

45 of 162

Hierarchical Modeling

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

46 of 162

Hierarchical Modeling

  • Opposite does not work!

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

47 of 162

Hierarchical Modeling

Sp

Sp

Sp

Tp

Tp

Tp

Tc

48 of 162

Hierarchical Modeling

Sp

Sp

Sp

Tp

Tp

Tp

Tc

Rc

49 of 162

Hierarchical Modeling

  • Incorrect!

Sp

Sp

Sp

Tp

Tp

Tp

Tc

Rc

50 of 162

Hierarchical Modeling

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

51 of 162

Hierarchical Modeling

  • Coordinate transformations are relative

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

52 of 162

Hierarchical Modeling

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

53 of 162

Hierarchical Modeling

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

54 of 162

Hierarchical Modeling

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

55 of 162

Hierarchical Modeling

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

56 of 162

Hierarchical Modeling

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

Part Transforms

Independent

Coord. Transforms

Children inherits parent’s transform

57 of 162

Effect of each term

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

58 of 162

Effect of each term

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

59 of 162

Effect of each term

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

60 of 162

Effect of each term

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

61 of 162

Effect of each term

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

62 of 162

Effect of each term

  • Rc: rotation around joint

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

63 of 162

Effect of each term

  • Rc: rotation around joint

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

64 of 162

Effect of each term

  • Rc: rotation around joint

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

65 of 162

Effect of each term

  • Rc: rotation around joint

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

66 of 162

Effect of each term

  • Rc: rotation around joint

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

67 of 162

Effect of each term

  • Rc: rotation around joint

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

68 of 162

Effect of each term

  • Rc: rotation around joint

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

69 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

70 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

71 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

72 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

73 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

74 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

75 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

76 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent
  • Sp: shape of part

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

77 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent
  • Sp: shape of part

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

78 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent
  • Sp: shape of part

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

79 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent
  • Sp: shape of part
  • Tp: location of joint

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

80 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent
  • Sp: shape of part
  • Tp: location of joint

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

81 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent
  • Sp: shape of part
  • Tp: location of joint

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

82 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent
  • Sp: shape of part
  • Tp: location of joint

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

83 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent
  • Sp: shape of part
  • Tp: location of joint

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

84 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent
  • Sp: shape of part
  • Tp: location of joint

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

85 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent
  • Sp: shape of part
  • Tp: location of joint

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

86 of 162

Effect of each term

  • Rc: rotation around joint
  • Tc: connection to parent
  • Sp: shape of part
  • Tp: location of joint

Sp

Sp

Sp

Tp

Tp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

87 of 162

Putting it all together

  • First, part

Sp

88 of 162

Putting it all together

  • First, part

Sp

Tp

89 of 162

Putting it all together

  • First, part

Sp

Tp

90 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

91 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

92 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

93 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

Sp

Tp

94 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

Sp

Tp

95 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

Sp

Tp

Rc

96 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

Sp

Tp

Rc

Tc

97 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

Sp

Tp

Rc

Tc

Rc

98 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

99 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

100 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

Sp

Tp

101 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

Sp

Tp

Rc

Tc

102 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

Sp

Tp

Rc

Tc

103 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

104 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

105 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

106 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

107 of 162

Putting it all together

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

108 of 162

Robot – Assignment 2

  • torso
    • head
    • right upper arm
      • right lower arm
    • left upper arm
      • left lower arm
    • right upper leg
      • right lower leg
    • left upper leg
      • left lower leg

109 of 162

Robot – Assignment 2

  • Parts connected at joints
  • Each joint has 3 degrees of freedom
    • Rotation around 3 axis (Rc)

110 of 162

Robot – Assignment 2

  • Parts connected at joints
  • Each joint has 3 degrees of freedom
    • Rotation around 3 axis (Rc)

Torso

Head

R Upper Arm

L Upper Arm

R Upper Leg

L Upper Leg

R Lower Arm

L Lower Arm

R Lower Leg

L Lower Leg

Tp, Sp, Tc, Rc

User Controlled

111 of 162

Implementation using a stack

112 of 162

Stack

Push

113 of 162

Stack

Push

Push

114 of 162

Stack

Push

Push

Push

115 of 162

Stack

Push

Push

Push

Pop

116 of 162

Stack

Push

Push

Push

Pop

Pop

117 of 162

Stack

Push

Push

Push

Pop

Pop

Push

118 of 162

Matrix Stack for Graph Traversal

  • The 1st element is the identity matrix

119 of 162

Matrix Stack for Graph Traversal

  • The 1st element is the identity matrix

I

120 of 162

Matrix Stack for Graph Traversal

  • The 1st element is the identity matrix
  • Push:
    • Copy the previous top matrix
    • Push it to the stack

I

I

I

Push

121 of 162

Matrix Stack for Graph Traversal

  • The 1st element is the identity matrix
  • Push:
    • Copy the previous top matrix
    • Push it to the stack
  • Pop:
    • Remove the top element

I

I

I

A

A

A

Push

Push

122 of 162

Matrix Stack for Graph Traversal

  • Each element in stack is an array of 16 numbers
    • Corresponding to the elements of a 4x4 matrix

I

I

I

A

A

A

Push

Push

123 of 162

Matrix Stack for Graph Traversal

  • New matrices are right-multiplied to the top matrix
    • translate(), scale(), rotate(), etc.

A

124 of 162

Matrix Stack for Graph Traversal

  • New matrices are right-multiplied to the top matrix
    • translate(), scale(), rotate(), etc.

A

A

A

Push

125 of 162

Matrix Stack for Graph Traversal

  • New matrices are right-multiplied to the top matrix
    • translate(), scale(), rotate(), etc.

A

A

A

Push

A

A T

Translate

126 of 162

Matrix Stack for Graph Traversal

  • New matrices are right-multiplied to the top matrix
    • translate(), scale(), rotate(), etc.

A

A

A

Push

A

A T

Translate

A

A T S

Scale

127 of 162

Matrix Stack for Graph Traversal

  • New matrices are right-multiplied to the top matrix
    • translate(), scale(), rotate(), etc.

A

A

A

Push

A

A T

Translate

A

A T S

Scale

A

A T S R

Rotate

128 of 162

Matrix Stack for Graph Traversal

  • New matrices are right-multiplied to the top matrix
    • translate(), scale(), rotate(), etc.

A

A

A

Push

A

A T

Translate

A

A T S

Scale

A

A T S R

Rotate

A

Pop

129 of 162

Robot

130 of 162

Robot

131 of 162

Robot

  • Depth first traversal

I

Stack

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

132 of 162

Robot

  • Depth first traversal

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

I

Stack

133 of 162

Robot

  • Depth first traversal

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

I

Stack

134 of 162

Robot

  • Depth first traversal

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

I

Stack

135 of 162

Robot

  • Depth first traversal

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

I

Stack

136 of 162

Robot

  • Depth first traversal

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

I

Stack

137 of 162

Robot

  • Depth first traversal

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

Tc

Rc

Tp

Sp

I

Stack

138 of 162

Recap

  • First, part
  • Second, coordinate

Sp

Tp

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

Sp

Tp

Rc

Tc

Rc

Tc

Rc

Tc

139 of 162

Robot

I

Stack

C

P

C

P

C

P

C

P

C

P

140 of 162

Robot

C

P

C

P

C

P

C

P

C

P

I

Stack

141 of 162

Robot

I

Stack

Push()

Pop()

I

C

P

C

P

C

P

C

P

C

P

142 of 162

Robot

I

Stack

C

Push()

Coordinate transform(C)Pop()

C

P

C

P

C

P

C

P

C

P

143 of 162

Robot

I

Stack

C

Push()

Coordinate transform(C)

Push()

Pop()

C

C

P

C

P

C

P

C

P

C

P

144 of 162

Robot

I

Stack

C

Push()

Coordinate transform(C)

Push()

Part transform(P)

Pop()

CP

C

P

C

P

C

P

C

P

C

P

145 of 162

Robot

I

Stack

C

Push()

Coordinate transform(C)

Push()

Part transform(P)

DRAWCUBE

Pop()

CP

C

P

C

P

C

P

C

P

C

P

146 of 162

Robot

I

Stack

C

Push()

Coordinate transform(C)

Push()

Part transform(P)

DRAWCUBE

Pop()

Pop()

C

P

C

P

C

P

C

P

C

P

147 of 162

Robot

I

Stack

C

Push()

Pop()

C

C

P

C

P

C

P

C

P

C

P

148 of 162

Robot

I

Stack

C

Push()

Coordinate transform(C)

Pop()

CC

C

P

C

P

C

P

C

P

C

P

149 of 162

Robot

I

Stack

C

Push()

Coordinate transform(C)

Push()

Pop()

CC

CC

C

P

C

P

C

P

C

P

C

P

150 of 162

Robot

I

Stack

C

Push()

Coordinate transform(C)

Push()

Part transform(P)

Pop()

CC

CCP

C

P

C

P

C

P

C

P

C

P

151 of 162

Robot

I

Stack

C

Push()

Coordinate transform(C)

Push()

Part transform(P)

DRAWCUBE

Pop()

CC

CCP

C

P

C

P

C

P

C

P

C

P

152 of 162

Robot

I

Stack

C

Push()

Coordinate transform(C)

Push()

Part transform(P)

DRAWCUBE

Pop()

Pop()

CC

C

P

C

P

C

P

C

P

C

P

153 of 162

Robot

I

Stack

C

Push()Pop()

CC

CC

C

P

C

P

C

P

C

P

C

P

154 of 162

Robot

I

Stack

C

Push()P

Coordinate transform(C)

op()

CC

CCC

C

P

C

P

C

P

C

P

C

P

155 of 162

Robot

I

Stack

C

Push()P

Coordinate transform(C)

Push()

op()

CC

CCC

CCC

C

P

C

P

C

P

C

P

C

P

156 of 162

Robot

I

Stack

C

Push()P

Coordinate transform(C)

Push()

Part transform(P)

op()

CC

CCC

CCCP

C

P

C

P

C

P

C

P

C

P

157 of 162

Robot

I

Stack

C

Push()P

Coordinate transform(C)

Push()

Part transform(P)

DRAWCUBE

op()

CC

CCC

CCCP

C

P

C

P

C

P

C

P

C

P

158 of 162

Robot

Stack

Push()P

Coordinate transform(C)

Push()

Part transform(P)

DRAWCUBE

Pop()

op()

C

P

C

P

C

P

C

P

C

P

I

C

CC

CCC

159 of 162

Robot

Stack

Push()P

Coordinate transform(C)

Push()

Part transform(P)

DRAWCUBE

Pop()

Pop()

op()

C

P

C

P

C

P

C

P

C

P

I

C

CC

160 of 162

Robot

I

Stack

TcRc

C

P

C

P

C

P

C

P

C

P

Push()P

Coordinate transform(C)

Push()

Part transform(P)

DRAWCUBE

Pop()

Pop()

Pop()

op()

161 of 162

Robot

Stack

Push()op()

C

P

C

P

C

P

C

P

C

P

I

C

162 of 162

Robot

I

Stack

C

Push()

op()

C

C

P

C

P

C

P

C

P

C

P