Question

So this wikipedia page shows you how to make a perspective projection of a point in 3d space onto the x/y plane. Does anyone know how to do the equivalent onto the y/z plane? This is what I am doing right now (just the wikipedia pages stuff.):

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

You can see all of the code at in the github repo.The file in particular that this is in is shapes.py .

Was it helpful?

Solution

I ended up making a guess that turned out to be correct. I used t4 = a/x_, newx = t4*y_ - b, and newy = t4*z_ - c; which turned out to be correct. I just used algebra!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top