Computer Graphics Homogenous Coordinate

Posted by Packy on August 9, 2019

平移和齐次坐标

Translation:

平移矩阵

E.g. move x by +5 units, leave y, z unchanged  We need appropriate matrix. What is it?

平移矩阵中不包含 X y z 所以是一个很有挑战的问题

图形学中用齐次坐标来表达,加入多一个轴

Add a fourth homogeneous coordinate (w=l)  4x4 matrices very common in graphics, hardware  • Last row always 0 00 1 (until next lecture)  x'  z'  100  010  001  5  o  x  z  z

最后一行都是0001

w=0 表示一个向量, 无穷远点

齐次坐标的有点是,只需要在渲染管线 最后一步 做一次除法 就可以将齐次坐标转化为非齐次坐标。中间没有人恶化除法

GeneraI TransIation Matrix  1  --—3ъЭ= о  1  1  1  х  1  Х+Тх

-3下수=  1  0  0  0  0  1  0  0  0  0  1  0  T  T  T  1  3

组合 RT TR 不同, 平移旋转 不可以交换顺序

Combining Translations, Rotations  P' = (TR)P = MP = RP + T

)죄 5 `

P' = (TR)P  1  0  o  0  0  1  1  R 21  R31  o  R12  R32  o  RI 3  R  R33  O  0  o  1  Ril  R21  R31  0  23  1  0  1

先平移 后旋转

+ d& " (u + d)H " dl"V " d(ÆH) 』 d

P' = (RT)P = — + T) —  RII  R21  R  31  o  R12  R  R  o  R13  R23  R33  o  o  1  o  o  1  o  R3x3  1  3x1  1  1

import numpy as np

def rotation_matrix_2d(deg):

cosi = np.cos(deg*np.pi/180)

sini = np.sin(deg*np.pi/180)

rotation = np.matrix([[cosi,-sini],[sini, cosi]])

return rotation

i = np.matrix([0,0]).T

translation_matrix = np.matrix([1.0,1.0]).T

rotation_matrix = rotation_matrix_2d(215.0)

print(rotation_matrix*i + translation_matrix)

print(rotation_matrixi + rotation_matrixtranslation_matrix)