2013-12-23 156 views
0

因此,這個wikipedia page向您展示瞭如何將三維空間中的點透視投影到x/y平面上。有誰知道如何在y/z平面上做等效物?這就是我現在在做什麼(就在維基百科頁面的東西。):透視投影到y/z平面上

class Shape(object): 
    ... 
    def apply_perspective(self, camera_pos, orientation, viewer_pos): 
     a, b, c = viewer_pos 
     cx, cy, cz = map(cos, orientation) 
     sx, sy, sz = map(sin, orientation) 
     transformed_vertices = [] 
     append = transformed_vertices.append 
     for v in self.vertices: 
      x, y, z = v - camera_pos 
      t1 = sz*y + cz*x 
      t2 = cz*y - sz*x 
      x_ = cy*t1 - sy*z 
      t3 = cy*z + sy*t1 
      y_ = sx*t3 + cx*t2 
      z_ = cx*t3 - sx*t2 
      t4 = c/z_ 
      newx = t4*x_ - a 
      newy = t4*y_ - b 
      append((newx, newy)) 
    return transformed_vertices 

可以在github repo看到所有的代碼在.The文件特別指出,這是在爲shapes.py。

回答

0

我最終猜出結果是正確的。我用t4 = a/x_,newx = t4*y_ - bnewy = t4*z_ - c;結果證明是正確的。我只是用代數!