Projecting 3d space to 2d

in Genius Bar edited January 2014
Does anyone know where to find formulae for projecting a point in 3-dimensional Euclidean space to a 2-d plane? The formula for cases when the plane is centered at the origin is trivial: (x',y') = (x/z,y/z) . Any information on cases where the plane is not centered at the origin would be appreciated,as well as any information on n -> n-1 dimensional cases.

[ 04-16-2002: Message edited by: Rick1138 ]</p>


  • Reply 1 of 12
    allinoneallinone Posts: 279member
    MacOSX or Classic?
  • Reply 2 of 12
    rick1138rick1138 Posts: 938member
    I'm mainly interested in the math,but if you know where to find code for Cocoa,that would be very cool.
  • Reply 3 of 12
    Quick answer: rotate the world space such that the plane you want to project to is alligned with the xy-plane (such that they are one in the same). Perform your projections. Rotate back if you need to.

    I'm afraid I am only familiar in working in 3d space with homogenous coordinates (x, y, z, w).

    For parallel projection, first divide all the components by w. Then plot (x,y) components (assuming the model has been transformed to screen space).

    Perspective projection is a bit more complicated. I can type that out if you need that too.
  • Reply 4 of 12
    airslufairsluf Posts: 1,861member
  • Reply 5 of 12
    rick1138rick1138 Posts: 938member
    It would be easier in homogenous coordinates,basically that is what I am looking for.It's not necessarily a change of basis problem but in most cases it would be.I need to be able to specify

    a) the position of the perspective frame

    b) its orientation,or basis

    c) the position of the projection point,if the projection is non-parallel

    [ 04-16-2002: Message edited by: Rick1138 ]</p>
  • Reply 6 of 12
    Come again?
  • Reply 7 of 12
    rick1138rick1138 Posts: 938member
    What I mean by the projection point is the point of view,and by frame I mean the 2d plane that is being projected onto-it has a position in space and an orientation.Up until the 19th century artists used to use what are called perspective frames,which were mechanical devices used to draw scenes in perspective-that's where I got the terminology from.
  • Reply 8 of 12
    I am still a bit at a loss to help you. My background is an intro programming class to low-level graphics. I think I am a little tripped up on your terms. What is it you are trying to do exactly? What's your project?
  • Reply 9 of 12
    rick1138rick1138 Posts: 938member
    In particular I want to be able to calculate a perspective projection from any viewpoint in 3d space,analogous to displaying a 3d scene on a computer screen.

    What I mean by the point of view is called in computer graphics the camera position.In Open GL the pyramid constructed by the camera position and the projection plane is called the view frustrum.

    In general I am interested in types of transforms created when the camera is a scanner,and either the camera is moving,or objects in the scene are moving.I think I am dealing with a new type of geometry that is based on rotation groups and projective geometry,but also different from both.
  • Reply 10 of 12
    I'm afraid my experience with OpenGL is very limited. However, in my class, we have done quite a bit of perspective projections and rotations.

    The basic for idea for rotation is like what I said before. Working in homogenous coords:

    1) Translate all objects such that the eye position is now at the origin.

    2) Rotate the objects such that the vector from the eye to the center of interest is aligned with the z-axis. This done by what is called the "general rotation matrix".

    3) Divide all x,y,z values of a point by it's w.

    Here is a bit of code I wrote for my last project. It calculated the GRM. (note: y is up, x is back and forth, z is out -- different from typical mathematical 3d space [where z is up])


    void calculateGRM(double grm[4][4])


    double Vx[3], Vy[3], Vz[3]; // three vectors that form a right 3d space

    double topVector[3] = {0, 1, 0}; // some vector that is points straight up.

    Vz[0] = coiX - posX; // let Vz = the vector from the eye to the center of interest

    Vz[1] = coiY - posY;

    Vz[2] = coiZ - posZ;

    /*Cross Vz with straight up vector to find Vx*/

    VectorOps3d::cross(topVector, Vz, Vx);\t// cross of topVector and Vz stored to Vx

    /* Cross Vz w/ Vx to find Vy */

    VectorOps3d::cross(Vz, Vx, Vy);\t\t// cross of Vz and Vx stored to Vy




    for(int i = 0; i &lt; 3; i++)


    grm[0][i] = Vx[i];

    grm[1][i] = Vy[i];

    grm[2][i] = Vz[i];




    Note that the forth row and columns are all = 0 except for grm[3][3] -- that is = 1.

    Now simply take all your points and multiply them by grm (grm should be on the left).
  • Reply 11 of 12
    rick1138rick1138 Posts: 938member
    OK Thanks a lot.I'll check oout that code.
  • Reply 12 of 12
    One last thing, the above GRM switches your points from a right-handed system to left-handed one. You can either tweek the above grm (I think by swapping the order of one of the cross-products-- I think swapping topvector and Vz). OR you can use this GRM and then mirror the x-values (multiply all x's by -1).
Sign In or Register to comment.