第7章 座標変換

7
7.1
7.1.1
OpenGL
6
OpenGL
API
(
(
CPU
78)
)
100
GPU
(
79)
部品
配置
部品
配置
78
79
80
101
7.1.2
(
)
(
80)
7.1.3
(
81)
81
82
y
y
y
視点座標系
ローカル座標系
z
y
z
x
スクリーン
x
z
x
z
ローカル座標系
82
102
x
ワールド座標系
7.1.4
(View Volume)
2
(Canonical View Volume)
ビューボリューム (View Volume)
(
視野錐台 (View Frustum)
標準ビューボリューム
(Canonical View Volume)
1
-1
-1
直交投影
(Orthographic Projection)
1
1
-1
透視投影
(Perspective Projection)
83
(Orthogonal Projection)
(Perspective Projection)
(View Frustum,
)
84
103
(
19)
83)
7.2
7.2.1
!
x0 = ax + b
x
(1)
a
b
x0 = axx x + ayx y + bx
y 0 = axy x + ayy y + by
(2)
x0 = axx x + ayx y + azx z + bx
y 0 = axy x + ayy y + azy z + by
z 0 = axz x + ayz y + azz z + bz
(3)
(3)
1 0
axx
x0
@ y 0 A = @ axy
axz
z0
0
ayx
ayy
ayz
10
1 0
1
bx
azx
x
azy A @ y A + @ by A
bz
azz
z
ayx
ayy
ayz
0
azx
azy
azz
0
(4)
7.2.2
(4)
x, y, z
0
1 0
x0
axx
B y 0 C B axy
B 0 C=B
@ z A @ axz
1
0
x’, y’, z’
1
C
C
A
(5)
(3)
(
(
10
bx
x
B y
by C
CB
bz A @ z
1
1
)
(5)
)
(
)
(x, y, z, w)
104
(x*, y*, z*)
x⇤
=
y⇤
=
z⇤
=
x
w
y
w
z
w
(6)
(x, y, z)
w
CG
0
x
B y
B
@ z
1
0
x
B y
B
@ z
0
(x, y, z, 1)
0
(x, y, z)
(x, y, z, 0)
(x, y, z)
1
(7)
1
(8)
C
C ) (x, y, z)
A
C
C ) (x, y, z)
A
0
1 0
x
ax
B y C B ay
C B
aB
@ z A = @ az
w
aw
1
⇣
⌘ ⇣
⌘
C
C ) ax , ay , az = x , y , z
A
aw aw aw
w w w
(9)
CG
P 0, P 1
P0
P1
w1
P1
0
1
x1 /w1
B y1 /w1 C
P0
C
=B
@ z1 /w1 A
w0
1
w0
w 0 P1
P0 = (x0, y0, z0, w0), P1 = (x1, y1, z1, w1)
0
1 0
x0 /w0
x1 /w1 x0 /w0
B y0 /w0 C B y1 /w1 y0 /w0
B
C B
@ z0 /w0 A = @ z1 /w1 z0 /w0
1
0
w1
0
0
0
1
w 0 x1
B w 0 y1 C
C
w 1 P0 = B
@ w 0 z1 A
w0 w1
C
C
A
(10)
w 0w 1
1 0
w 1 x0
w 0 x1 w 1 x0
B w 1 y0 C B w 0 y 1 w 1 y0
B
C B
@ w 1 z 0 A = @ w 0 z1 w 1 z0
w1 w0
0
(11)
1
1
C
C
A
(11)
0
P0
P1
0
(11)
w 0w 1
105
7.3
7.3.1
(5)
0
v
M
0
v’ = Mv
(12)
(13)
m0 x
m1 x
m2 x
m3 x
1
m12
m13 C
C
m14 A
m15
m8
m9
m10
m11
m4
m5
m6
m7
v’
=
=
=
=
(15)
1
x
B y C
C
v=B
@ z A
w
0 0 1
x
B y0 C
0
C
v =B
@ z0 A
w0
0
m0 m4
B m1 m5
M=B
@ m2 m6
m3 m7
0 0 1 0
x
m0
B y 0 C B m1
B 0 C=B
@ z A @ m2
w0
m3
x0
y0
z0
w0
m8
m9
m10
m11
(14)
10
m12
x
B y
m13 C
CB
m14 A @ z
m15
w
1
C
C
A
(15)
(x’, y’, z’, w’)
+
+
+
+
m4 y
m5 y
m6 y
m7 y
+
+
+
+
m8 z
m9 z
m10 z
m11 z
+
+
+
+
v’
1 0
x0
m0
B y 0 C B m1
B 0 C=B
@ z A @ m2
w0
m3
m12 w
m13 w
m14 w
m15 w
(16)
M
x’ = (m0 m4 m8 m12)
0
1
m4
m5
m6
m7
m8
m9
m10
m11
(x y z w)
v
T
10
m12
x
B y
m13 C
CB
m14 A @ z
m15
w
((17)
1
C
C
A
)
(17)
7.3.2
t = (tx, ty, tz)
0
1
B 0
T(t) = T(tx , ty , tz ) = B
@ 0
0
0
1
0
0
0
0
1
0
T(tx, ty, tz)
1
tx
ty C
C
tz A
1
(18)
106
(x, y, z)
0
1
B 0
B
@ 0
0
0
1
0
0
10
0 tx
x
B y
0 ty C
CB
1 tz A @ z
0 1
1
1
1
x + tx
C B y + ty C
C=B
C
A @ z + tz A
1
T(7, 8, 0)
0
(19)
85
y
y
T(7, 8, 0)
O
8
x
O
x
7
85
0
1
B 0
B
@ 0
0
0
1
0
0
0
0
1
0
0
1
10
0
tx
x
x
B y C B y
ty C
CB
C=B
tz A @ z A @ z
1
0
0
1
C
C
A
(20)
7.3.3
s = (sx, sy, sz)
0
sx 0 0
B 0 sy 0
S(s) = S(sx , sy , sz ) = B
@ 0 0 sz
0 0 0
S(sx, sy, sz)
1
0
0 C
C
0 A
1
(21)
y
S(2, 2, 1)
O
x
86
107
s x, = s y, = s z = a
0
7.3.4
a
B 0
B
@ 0
0
0
1
B 0
B
@ 0
0
0
a
0
0
0
0
a
0
0
1
0
0
0
0
1
0
w
10
0
x
B y
0 C
CB
0 A@ z
1
1
10
0
B
0 C
CB
A
@
0
1/a
1
1/a
0
1
ax
C B ay C
C=B
C
A @ az A ) (ax, ay, az)
1
1 0
1
x
x
B
C
y C
C = B y C ) (ax, ay, az)
A
@
z
z A
1
1/a
(22)
(23)
y
1
O
s
1
x
87
87
Y
0
s
X
s
1
0
0
0
0
1
0
1
0
0 C
C
0 A
1
1
B 0
Hxy (s) = B
@ 0
0
s
1
0
0
0
0
1
0
1
0
0
B
0 C
C Hyz (s) = B
A
@
0
1
1
B s
Hyx (s) = B
@ 0
0
0
1
0
0
0
0
1
0
1
B 0
Hxy (s) = B
@ 0
0
(24)
(24)
x, y, z
0
0
0
1
0
B
0 C
C Hzy (s) = B
@
0 A
1
1
0
0
0
0
1
0
0
0
s
1
0
1
0
0
0
0
1
s
0
0
0
1
0
108
1
0
0
B
0 C
C Hzx (s) = B
A
@
0
1
1
0
0
B
0 C
C Hxz (s) = B
@
0 A
1
1
0
s
0
0
1
0
0
0
0
1
0
1
0
0
0
0
1
0
0
s
0
1
0
1
0
0 C
C
0 A
1
1
0
0 C
C
0 A
1
(25)
7.3.5
"X
θ!
88 X
0
1
0
B 0 cos ✓
Rx (✓) = B
@ 0 sin ✓
0
0
0
sin ✓
cos ✓
0
1
0
0 C
C
0 A
1
(20)
"Y
θ!
89 Y
0
cos ✓
B
0
Ry (✓) = B
@ sin ✓
0
0 sin ✓
1
0
0 cos ✓
0
0
1
0
0 C
C
0 A
1
(21)
109
"Z
θ!
90 Z
0
cos ✓
B sin ✓
Rz (✓) = B
@ 0
0
sin ✓
cos ✓
0
0
0
0
1
0
1
0
0 C
C
0 A
1
(22)
"
(l, m, n)
(l,m,n)
θ!
91
R(l,
0 m, n,2 ✓)
l + (1 l2 ) cos ✓
B lm(1 cos ✓) + n sin ✓
=B
@ ln(1 cos ✓) m sin ✓
0
lm(1 cos ✓) n sin ✓
m2 + (1 m2 ) cos ✓
mn(1 cos ✓) + l sin ✓
0
ln(1 cos ✓) + m sin ✓
mn(1 cos ✓) l sin ✓
n2 + (1 n2 ) cos ✓
0
1
0
0 C
C
0 A
1
(23)
7.4
i’, j’, k’
p
i, j, k
p
(x, y, z)
p
110
(x’, y’, z’)
p = xi + yj + zk = x0 i0 + y 0 j0 + z 0 k0
i
j
0
1
x
@ y A=
z
k
i0
j0
(30)
1
x0
@ y0 A
z0
0
k0
(31)
(x, y, z)
0
1
x
@ y A=
z
i
j
1
k
i0
j0
1
x0
@ y0 A
z0
0
k0
(32)
(i j k), (i’ j’ k’)
0
1
x
@ y A=
z
i
j
k
T
i0
j0
M
i
M=
j
k
T
i0
j0
(33)
(x’, y’, z’)
k0
M
k0
1
x0
@ y0 A
z0
0
0
i · i0
= @ j · i0
k · i0
(
(x, y, z)
i · j0
j · j0
k · j0
1
i · k0
j · k0 A
k · k0
(34)
)
r, s, t
0
1
1
0
1
tx
rx
sx
r = @ ry A , s = @ s y A , t = @ ty A
tz
rz
sz
0
X
Y
(35)
Z
x, y, z
0 1
1
0 1
0
1
0
x = @ 0 A, y = @ 1 A, z = @ 0 A
1
0
0
0
r, s, t
(36)
x, y, z
M
8
< x = Mr
y = Ms
:
z = Mt
x
y
z
(37)
=M
r
s
t
(38)
111
y
r
M
s
M
x
M
z
t
92
0
1
@ 0
0
0
1
0
1
0
0
rx
0 A = M @ ry
1
rz
sx
sy
sz
1
tx
ty A
tz
(39)
M
0
rx
M = @ ry
rz
sx
sy
sz
1
tx
ty A
tz
1
0
rx
= @ ry
rz
sx
sy
sz
1T 0
rx
tx
ty A = @ s x
tz
tx
ry
sy
ty
1 0 T 1
r
rz
sz A = @ sT A
tz
tT
(40)
7.5
7.5.1
93
4
y
3
(41)
T(4, 3, 0)
T(0, 3, 0)
T(4, 0, 0)
93
112
x
0
T(0, 3, 0)T(4, 0, 0)
1
B 0
=B
@ 0
0
0
1
0
0
0
0
1
0
1
B 0
=B
@ 0
0
0
1
0
0
0
0
1
0
0
10
0
1 0
B 0 1
3 C
CB
0 A@ 0 0
1
0 0
0
0
1
0
1
4
3 C
C = T(4, 3, 0)
0 A
1
1
4
0 C
C
0 A
1
(41)
7.5.2
0
r00
B r01
M = T(t)R(l, m, n, ✓) = B
@ r02
0
r10
r11
r12
0
r20
r21
r22
0
1
tx
ty C
C
tz A
1
(42)
!
M
0
r00
¯ = @ r01
R
r02
r10
r11
r12
0
1
0
1
¯
R
tx
r20
r21 A , t = @ ty A ) M = @
tz
r22
0T
t
1
t
1
A
(43)
7.5.3
7.3.5
M = T(p) Rz(θ) T(−p)
y
y
y
p
p
T( p)
O
T(p)
Rz(θ)
θ"
x
x
O
M = T(p) Rz(θ) T( p)
94
113
O
x
7.5.4
7.3.3
y
(移動)
O
x
95
M = T(p) S(s) T(−p)
y
y
y
p
p
T(-p)
x
O
T(p)
S(s)
x
O
x
O
M = T(p) S (s) T( p)
96
7.5.5
7.3.3
X
Y
Z
X
Y
Z
(x y z)
(r s t)
F
sr
S
ss
st
M = FSF
114
X
T
Y
Z
F=
✓
0
r s t 0
0 0 0 1
sr
B 0
S=B
@ 0
0
s
0
ss
0
0
0
0
st
0
y
◆
(44)
1
0
0 C
C
0 A
1
(45)
s
s
s
y
r
r
O
x
FT
r
O
S
O
r
F
O
x
M = F S FT
97
7.5.6
y
O
y
x
R(θ)
O
y
O
y
x
S(s)
y
x
S(s)
O
98
7.6
7.6.1
X, Y, Z
115
O
x
y
x
R(θ)
O
x
y
heading
pitch
roll
z
x
99
Z
(roll, bank)
X
(pitch)
Y
(heading, yaw)
r, p, h
! r: roll, bank (Z
)
! p: pitch (X
)
! h: heading, yaw (Y
)
E(h, p, r)
E(h, p, r) = Ry (h)Rx (p)Rz (r)
0
cos h
B
0
=B
@ sin h
0
0
1
0
0
sin h
0
cos h
0
0
10
0
1
B 0
0 C
CB
0 A@ 0
1
0
sin h sin p sin r + cos h cos r
B
cos p sin r
=B
@ cos h sin p sin r sin h cos r
0
0
cos p
sin p
0
0
sin p
cos p
0
10
0
cos r
B sin r
0 C
CB
0 A@ 0
1
0
sin h sin p cos r cos h sin r
cos p cos r
cos h sin p cos r + sin h sin r
0
sin r
cos r
0
0
sin h cos p
sin p
cos h cos p
0
0
0
1
0
1
0
0 C
C
0 A
1
(46)
1
0
0 C
C
0 A
1
7.6.2
p=
/2
sin p = 1, cos p = 0
(46)
0
sin h sin r + cos h cos r
B
0
E(h, ⇡/2, r) = B
@ cos h sin r sin h cos r
0
sin h cos r
cos h sin r
0
cos h cos r + sin h sin r
0
116
1
0 0
1 0 C
C
0 0 A
0 1
(47)
0
cos(h r) sin(h
B
0
0
E(h, ⇡/2, r) = B
@ sin(h r) cos(h
0
0
r)
r)
0
1
0
0
1
0
0 C
C
0 A
1
(48)
(h - r)
r
h
p=
r
(Z
)
/2
h
7.6.3
M
0
m0
B m1
M=B
@ m2
m3
m1
m4
m5
m6
m7
m5
(49)
! r = atan2(m5 , m1 )
(50)
m10
m8 = sin h cos p
m10 = cos h cos p
p
1
m12
m13 C
C = E(h, p, r)
m14 A
m15
m8
m9
m10
m11
r
m1 = cos p sin r
m5 = cos p cos r
m8
E(h, p, r)
h
(51)
! h = atan2(m10 , m8 )
m9
m9 =
sin p !
p = asin( m9 )
m1 = m5 = 0
cos p = 0
(50)
h=0
m0 = cos(h ⌥ r)
m4 = sin(h ⌥ r)
(52)
m0
p=
(51)
r
m14
! h = 0, r =
/2
h
h
atan2(m0 , m4 )
117
(53)
7.7
7.8
7.9 OpenGL
7.10
7.11
7.11.1
7.11.2
7.11.3
7.11.4
118