Projection- Transforming 3d to 2d

后端 未结 3 600
北海茫月
北海茫月 2021-02-14 21:51

I have problem or well, I do not know how to transform 3d point with x,y,z values to 2d point, I have to draw projection, where I do have x,y,z values for points but I don\'t kn

3条回答
  •  天涯浪人
    2021-02-14 22:50

    You only need to take camera angle into account if you intend to rotate your shape in 3 dimensions. If you have a firm understanding of linear algebra and trigonometry, it's worth the extra effort since it makes your program more flexible, but if your not too string in mathematics I would recommend the following solution.

    What you need to be able to do to project a 3D image into a 2D plain is create and equation that will map.

    (x,y,z) -> (x',y')
    

    You can do this by defining three mappings form a 3D point to a 2D point.

    (1,0,0) -> (  1,  0)
    (0,1,0) -> (  0,  1)
    (0,0,1) -> (-.7,-.7)
    

    I used (-.7,-.7) for the z access because that point is approximately 1 unit from the origin and half way between the x and y access.

    After you have these three points you have enough information to calculate any arbitrary point x,y,z.

    (x,y,z) -> (1*x - .7*z, 1*y - .7*z)
    

    In computer graphics the origin of a grid is not in the center of the screen but instead in the top left hand corner. In order use the equation we just generated in our program we must define an offset to move the origin to the center of the screen. We will call this offset point(Ox, Oy).

    With the offset our equation becomes the following.

    (x,y,z) -> (Ox + 1*x - .7*z, Oy + 1*y - .7*z)
    

提交回复
热议问题