Projecting 4D points into 3D space using matrices

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Webb

    Projecting 4D points into 3D space using matrices

    I am writing some visualisation code for 4 dimensional geometric shapes.
    This is to run in the C# .NET XNA environment, so I am cross posting a maths
    and C# group.

    My software runs just fine for 3D objects - for example I can draw cubes,
    tetrahedrons, icosahedrons etc and rotate them on screen. All of the "heavy
    lifting" is done by the XNA libraries, which have transformation libraries
    to map 3D constructs onto 2D with perspective. Using the standard XNA
    libraries, I can draw the 3D objects as seen from any point of view in 3D
    space, rotate them, etc.

    My plan is to construct my 4D objects using a series of 4 Vectors specifying
    each vertex. I then project these vertices onto 3D space from a particular
    viewpoint and feed these 3D objects into my existing 3D code.

    In 3D, to convert to 2D, I do this by defining the viewpoint as a Vector3
    (say x,y,z), the point I am looking towards (which can be (0,0,0)), and an
    "up" unit vector (perpendicular to (x,y,z)) which defines which way is "up"
    in the presented view. XNA then does the Matrix transformation 3D -2D for
    me.

    I need to create a similar transformation matrix for 4D to 3D.

    I have a viewpoint in space - say (x1, y1, z1, w1). I need to know the
    co-ordinates of another point - (x2, y2, z2, w2) as a Vector3 (a,b,c) if I
    am looking from my viewpoint towards (say) the origin. By analogy with the
    3D to 2D case, I will need to define one or possibly two unit vectors
    perpendicular to (x1,y1,z1,w1) - though not necessarily perpendicular to
    each other (?) - that define the "up" direction and maybe the "left"
    direction.

    So I need a transformation matrix T, based on (x1,y1,z1,w1) and one or
    possibly two unit vectors perpendicular to (x1,y1,z1,w1) which will map any
    point (x2,y2,z2,t2) onto a 3D point (a,b,c), corresponding to where it
    appears in 3D space from that 4D viewpoint.

    I am pretty sure that I just need a constant 4x3 matrix T, and I multiply
    each of my 4D vectors (representing vertices) by this matrix T to get the 3D
    projection.

    Does anybody know what T will look like? I haven't been able to find an
    example on Google, and my math skills/visualisation ability is not
    sufficient to construct T explicitly myself.

    Alternatively, any other way to skin this cat?

    TIA


    Peter Webb









  • Tim Little

    #2
    Re: Projecting 4D points into 3D space using matrices

    On 2008-06-04, Peter Webb <webbfamily@DIE SPAMDIEoptusnet .com.auwrote:
    By analogy with the 3D to 2D case, I will need to define one or
    possibly two unit vectors perpendicular to (x1,y1,z1,w1) - though
    not necessarily perpendicular to each other (?) that define the
    "up" direction and maybe the "left" direction.
    You definitely want them perpendicular to each other, or your
    projection will be "skewed".

    Yes, you'll need a "forward" direction, an "up", and a "left" (or
    "right"). The other 4D direction (whatever you want to call it) will
    just be perpendicular to those.

    I am pretty sure that I just need a constant 4x3 matrix T
    A 4x3 matrix will handle rotation and orthographic projection.
    However, it will not handle translation or perspective projection.

    To accomplish the translation, you either need to go to 5-component
    homogeneous coordinates and hence a 5x3 matrix, or subtract your eye
    coordinates from the points before you apply the transformation.

    For perspective, you'll need a 4x4 matrix (or 5x5 for homogeneous
    coords) and clipping planes, then divide the results by the z
    ("forward") coordinate.

    Does anybody know what T will look like? I haven't been able to find
    an example on Google, and my math skills/visualisation ability is
    not sufficient to construct T explicitly myself.
    Consider the inverse of (a 4x4) T: it will map the y-axis to your "up"
    vector, the x-axis to your "right" vector, the z-axis to your
    "forward" vector, and the w-axis to your "other" vector. So the
    columns of this matrix will just be your view directions. Invert
    that, and you have T. In the case of rotation matrices, the inverse
    is just the transpose.

    If you just want orthographic projection, drop the "forward" vector
    giving a 4x3 matrix. Otherwise leave it in, clip the resulting
    shapes, and divide by the resulting z value.


    - Tim

    Comment

    • Peter Webb

      #3
      Re: Projecting 4D points into 3D space using matrices

      >
      >Does anybody know what T will look like? I haven't been able to find
      >an example on Google, and my math skills/visualisation ability is
      >not sufficient to construct T explicitly myself.
      >
      Consider the inverse of (a 4x4) T: it will map the y-axis to your "up"
      vector, the x-axis to your "right" vector, the z-axis to your
      "forward" vector, and the w-axis to your "other" vector. So the
      columns of this matrix will just be your view directions. Invert
      that, and you have T. In the case of rotation matrices, the inverse
      is just the transpose.
      This is the case that I think I want!

      So I am looking from V1= (x1, y1, z1, t1). I generate two other unit vectors
      V2 and V3 with the property that V1.V2=V1.V3=V2. V3 = 0. These are where I
      want "up" and "right" to be. (Is there an easy way to generate these
      vectors?).

      This gives me the first three columns of T^-1 as: [V1,V2,V3 ?] - what's the
      fourth column? The zero vector?

      That would appear to make sense, because after applying the transformation
      one of the dimensions disappears.

      So, before I code all this up, I:

      1. Construct the matrix T^(-1) comprising [V1,V2,V3,0] - (do I have to
      divide by the determinant to normalise it)?

      2. Invert the matrix to form T. Then T*(x,y,z,t) = (a,b,c,d)

      The a, b, and c are my new x, y and z; the d should be zero plus or minus
      rounding errors.

      Is that it?


      >
      If you just want orthographic projection, drop the "forward" vector
      giving a 4x3 matrix. Otherwise leave it in, clip the resulting
      shapes, and divide by the resulting z value.
      >
      No, if I am trying to assist visualisation then perspective is important. I
      can always move my viewpoint a thousand times further back and use a
      thousand times smaller viewing angle to get this anyway.

      >
      - Tim
      Really helpful response. Thank you.


      Comment

      • Peter Webb

        #4
        Re: Projecting 4D points into 3D space using matrices


        "Peter Webb" <webbfamily@DIE SPAMDIEoptusnet .com.auwrote in message
        news:48468628$0 $13945$afc38c87 @news.optusnet. com.au...
        >>Does anybody know what T will look like? I haven't been able to find
        >>an example on Google, and my math skills/visualisation ability is
        >>not sufficient to construct T explicitly myself.
        >>
        >Consider the inverse of (a 4x4) T: it will map the y-axis to your "up"
        >vector, the x-axis to your "right" vector, the z-axis to your
        >"forward" vector, and the w-axis to your "other" vector. So the
        >columns of this matrix will just be your view directions. Invert
        >that, and you have T. In the case of rotation matrices, the inverse
        >is just the transpose.
        >
        This is the case that I think I want!
        >
        So I am looking from V1= (x1, y1, z1, t1). I generate two other unit
        vectors V2 and V3 with the property that V1.V2=V1.V3=V2. V3 = 0. These are
        where I want "up" and "right" to be. (Is there an easy way to generate
        these vectors?).
        >
        This gives me the first three columns of T^-1 as: [V1,V2,V3 ?] - what's
        the fourth column? The zero vector?
        >
        That would appear to make sense, because after applying the transformation
        one of the dimensions disappears.
        >
        So, before I code all this up, I:
        >
        1. Construct the matrix T^(-1) comprising [V1,V2,V3,0] - (do I have to
        divide by the determinant to normalise it)?
        >
        2. Invert the matrix to form T. Then T*(x,y,z,t) = (a,b,c,d)
        >
        The a, b, and c are my new x, y and z; the d should be zero plus or minus
        rounding errors.
        >
        Is that it?
        >
        This can't be correct. The determinant of a matrix with a column comprising
        the zero vector can't be inverted, because the determinant is zero. This is
        exactly the behaviour we want in the transformation matrix, as it reduces 4
        dimensions down to 3, but we can't form it from [V1, V2, V3, 0] as its not
        invertable.

        Help ... please ... I've almost got it (I think).

        >
        >
        >>
        >If you just want orthographic projection, drop the "forward" vector
        >giving a 4x3 matrix. Otherwise leave it in, clip the resulting
        >shapes, and divide by the resulting z value.
        >>
        >
        No, if I am trying to assist visualisation then perspective is important.
        I can always move my viewpoint a thousand times further back and use a
        thousand times smaller viewing angle to get this anyway.
        >
        >
        >>
        >- Tim
        >
        Really helpful response. Thank you.
        >
        >

        Comment

        • Tim Little

          #5
          Re: Projecting 4D points into 3D space using matrices

          On 2008-06-04, Peter Webb <webbfamily@DIE SPAMDIEoptusnet .com.auwrote:
          So I am looking from V1= (x1, y1, z1, t1). I generate two other unit
          vectors V2 and V3 with the property that V1.V2=V1.V3=V2. V3 =
          0. These are where I want "up" and "right" to be. (Is there an easy
          way to generate these vectors?).
          There is a lot of freedom in their choice. Given V1, you can treat
          V1.V2 = 0 as a linear equation in the coefficients of V2, which you
          can solve - ending up with 3 free variables, though then you need to
          normalize. Likewise for V3 you can treat V1.V3 = V2.V3 = 0 as a
          system of two linear equations, which can also be solved, and so on.

          This gives me the first three columns of T^-1 as: [V1,V2,V3 ?] -
          what's the fourth column? The zero vector?
          The fourth vector is uniquely determined from the other three by the
          condition that it be orthogonal, unit, and the matrix having
          determinant +1. (The -1 solution corresponds to a reflection rather
          than a rotation)


          2. Invert the matrix to form T. Then T*(x,y,z,t) = (a,b,c,d)
          >
          The a, b, and c are my new x, y and z
          ....
          Is that it?
          No, to get perspective you then need to discard any bits with negative
          d, probably clipping against the boundaries of your viewing space, and
          divide (a,b,c) coordinates by d.


          - Tim

          Comment

          Working...