Sign in to follow this  

3 x 4 Matrix

This topic is 3632 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

would this function be correct when multipling a vector (Point p) by a 3 x 4 matrix.
   public Point convert(Point p, double[][] matrix) {
      Point result = new Point();
      result.x = matrix[0][0] * p.x +
                 matrix[0][1] * p.y +
                 matrix[0][2] * p.z +
                 matrix[0][3];

      result.y = matrix[1][0] * p.x +
                 matrix[1][1] * p.y +
                 matrix[1][2] * p.z +
                 matrix[1][3];

      result.z = matrix[2][0] * p.x +
                 matrix[2][1] * p.y +
                 matrix[2][2] * p.z +
                 matrix[2][3];

      return result;
   }


[Edited by - staticVoid2 on January 7, 2008 6:12:15 AM]

Share this post


Link to post
Share on other sites
Close:
   public Point convert(Point p, double[][] matrix) {
Point result = new Point();
result.x = matrix[0][0] * p.x +
matrix[0][1] * p.y +
matrix[0][2] * p.z +
matrix[0][3];

result.y = matrix[1][0] * p.x +
matrix[1][1] * p.y +
matrix[1][2] * p.z +
matrix[1][3];

result.z = matrix[2][0] * p.x +
matrix[2][1] * p.y +
matrix[2][2] * p.z +
matrix[2][3];

return result;
}
When writing these sorts of functions it can help to write out an example. e.g.:
[ 00 01 02 03 ][ x ]   [ x' ]
[ 10 11 12 13 ][ y ] = [ y' ]
[ 20 21 22 23 ][ z ] [ z' ]

Share this post


Link to post
Share on other sites
Correct me if I'm wrong, but iirc you cannot really multiply 3x4 matrix with a 3 element vector (at least not in the way you presented, you could right-multiply a 3 element row vector by a 3x4 matrix).

While in the current context (geometric transformation of a point) jyk's formula is correct, it's correct only because it assumes an extension of the 3-element vector [x,y,z] to the 4-element vector [x,y,z,1].

Share this post


Link to post
Share on other sites
Quote:
Original post by Morrandir
While in the current context (geometric transformation of a point) jyk's formula is correct, it's correct only because it assumes an extension of the 3-element vector [x,y,z] to the 4-element vector [x,y,z,1].
Extending a 3-element vector with an understood w of 1 or 0 (and, similarly, extending a 3x4 or 4x3 matrix with an understood row or column of identity) is a very common shortcut, so I didn't really feel it necessary to point out in my post that the operation in question was technically undefined.

Still, I suppose it was worth clarifying for the OP (although his use of a specialized 'point' class suggested to me that he understood what he was doing, geometrically speaking :).

Share this post


Link to post
Share on other sites
yeh, when you multiply the displacement vector in the matrix by 1 and then add it to the axis vectors you will get the translated point - but in this function it makes no difference - technically its not a matrix multiplication but it doesn't need to be.

Share this post


Link to post
Share on other sites

This topic is 3632 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this