Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Projection- Transforming 3d to 2d

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 know how to transform them into 2d so I can move them onto my axis.

enter image description here

I have been looking around wiki and google, howevever I'm not quite sure which matrix transformations should I use to get wanted result.

like image 901
user2141889 Avatar asked Apr 05 '13 21:04

user2141889


People also ask

What is 3D to 2D projection?

For a 3D-to-2D projection, there is a finite plane on which the world is projected. For 2D to 1D, there is a bounded line that is the result of the projection. An orthographic projection is a very simplistic projection.

How do you convert 3D coordinates to 2D coordinates?

short answer : divide by z. If x is horizontal, y vertical and z the distance orthogonal to the screen (from your eye) then coordinates will be s⋅xz and s⋅yz with s a scaling factor proportional to (say) vertical resolution of screen.

Is used to transform 3D object on to a 2D plane?

A 3D projection (or graphical projection) is a design technique used to display a three-dimensional (3D) object on a two-dimensional (2D) surface. These projections rely on visual perspective and aspect analysis to project a complex object for viewing capability on a simpler plane.

What is the need of projection explain ways of projection 3D objects onto 2D screen in detail?

It is the process of converting a 3D object into a 2D object. It is also defined as mapping or transformation of the object in projection plane or view plane. The view plane is displayed surface.


1 Answers

Let's first assume the camera looking at your scene is centered at the origin, and looking at the -z direction. Then:

  • a perspective projection is given by:
    x' = x/z
    y' = y/z

  • an orthographic projection is given by:
    x' = x
    y' = y
    (i.e., just discard the z component)

Now that you have applied the step above, you might obtain a point that is at (x',y') = (-28.4, +134.5). You now need to scale and center them based on your screen resolution and camera "zoom factor" and aspect ratio : for instance, you might want to multiply by Zoom and add screen_center to both your x and y components (beware: most graphics rendering systems have the y direction pointing down, so you might need to swap signs for the y component). You might still end up with pixels with negative coordinates or whose coordinates are greater than your canvas size. Just discard them : it means that they are outside of your view frustum.

Finally, you might wonder what to do if your camera is not pointing toward -z or not centered at the origin. For the later, it is simple: just subtract the camera coordinates to the component of all your 3D points prior to doing anything else. For the camera rotation, it is also actually quite easy : you just need to rotate your points in the inverse way your camera is rotated prior to doing anything else as well. That just means that you need to multiply all your 3D coordinates by the transpose of the camera rotation matrix. The idea behind this step is that moving the camera around is exactly the same as moving your points in the reverse direction (and it happen that the inverse of a rotation matrix is the transpose of that same matrix).

like image 75
nbonneel Avatar answered Nov 10 '22 05:11

nbonneel