Register to reply 
2D Perspective xform using CSS 3D matrix? 
Share this thread: 
#1
Nov2211, 11:52 PM

P: 5

Hi,
I have used Mathematica to determine a 3x3 perspective transformation from one 2D image to another. Let's say that Mathematica gave me the following 3x3 matrix: a b c d e f g h 1 Now, moving outside of Mathematica, I'm trying to use that perspective xform it gave me in CSS on a webpage. There are two general matrix xform choices in CSS3: 2D "matrix" and 3D "matrix3d". The former, "matrix", is 3x3 but doesn't allow specification of the third row  it's fixed to "0 0 1": p q r s t u 0 0 1 If I'm not mistaken, this is the form of an affine xform, but I'm trying to do a perspective transform which isn't affine. So, I thought I could use the more general "matrix3D", which allows all 16 elements to be specified: k l m n o p q r s t u v w x y z I am hoping that I can provide values that would accomplish the original transformation but leave z ordinates unaffected. Off the top of my head, as a wild guess, I thought it might be: a b 0 c d e 0 f 0 0 1 0 g h 0 1 where a,b,c,d,e,f,g,h are the values from the original 3x3 xform Mathematica gave me. I'm neither a physicist nor a mathematician, but thought this might be a good place to ask. Even though I'm ultimately trying to do a perspective xform on a web page using CSS, it seems like a generic sort of linear algebra question... Any help or pointers will be greatly appreciated. 


#2
Nov2311, 10:36 AM

Sci Advisor
P: 3,252

I gather your definition of "affine transformation" does not include all the "perspective transformations" as a subset. Is that correct? Also, what is "CSS"? 


#3
Nov2311, 01:56 PM

P: 5

I've attached "before" and "after" images to illustrate the image transformation.
I am currently using Mathematica's FindGeometricTransform function to get the 3x3 matrix and then I'm using Mathematica's ImagePerspectiveTransformation to transform "before" into "after". The transformation compensates for the fact that the camera is placed out of the line of fire, from which perspective the target is no longer circular. After the transformation, the target is once again circular. CSS is a styling language for the web. The most recent version introduces 2D and 3D transformation of items on pages. I want to place the "before" image on a web page then set the image's transform attribute to either a CSS matrix(...) or matrix3d(...) construct. I want to use the 3x3 matrix Mathematica gave me, but matrix(...) only allows one to specify the first two rows, which is why I'm looking at matrix3d(...). If you're interested in the CSS details, this page is probably as good at explaining it as any other. But my question is really about how to extend this sort of 2D 3x3 transformation matrix into a 3D 4x4 transformation matrix that leaves z unchanged. I.e. if a b c d e f g h 1 transforms (x,y) to (X,Y), what's the 4x4 matrix that would transform (x,y,z) to (X,Y,z)? 


#4
Nov2311, 10:09 PM

P: 4,572

2D Perspective xform using CSS 3D matrix?
Hey SporkInTucson and welcome to the forums.
Are you trying to transform a plane from one orientation to another? Do you want to use the same projection for both objects. It seems to me that from the images you are taking a quadrilateral (which can be defined using two triangles since every triangle defined a unique plane) and then you are translating the two triangles using a transform. If that is all you are doing (transforming the two triangles by using translations, rotations, and scaling matrices), then you need to basically concatenate a few matrix transforms together to get your final position and then apply a standard projection. I'm not completely sure about what you want to do though, so I based this response on your images that you have attached. In terms of deriving the transformation matrices in the above context, you need to understand arbitrary rotations and translations. For translations, this won't be much of an issue (as will scaling), but for rotations, especially ones that are not axis aligned, this will be a slight issue. The rotation matrix you should use should be based on rotation about a specified axis. Here is something for you to read: http://en.wikipedia.org/wiki/Rotatio...axis_and_angle Once you have these down, the next part is choosing the right concatenation of the matrices. The order is important because rotating and then translating is completely different to translating and then rotating. 


#5
Nov2411, 12:55 PM

P: 5

Seems like the CSS details have prevented me from posting my question clearly. I've figured it all out, as of this morning, but wanted to post a follow up to close out the thread.
CSS constrains the type of 3x3 xform matrices that can be applied in 2D. Specifically, it allows 3x3 xform matrices with only six specifiable elements (a,b,c,d,e,f):
The answer to my question was that a 2D 3x3 xform can be expressed as a 3D 4x4 transform.



Register to reply 
Related Discussions  
Real matrix  eigenvector matrix R  diagonal eigenvalue matrix L  Programming & Computer Science  0  
Step Function (heaviside) laplace xform  Differential Equations  2  
Hint on Inverse Fourier XForm  Calculus & Beyond Homework  0  
Why you should like my perspective!  General Physics  106 