TITLE: Finding the Transform matrix from 4 projected points (with Javascript)
QUESTION [87 upvotes]: I'm working on a project using Chrome - JS and Webkit 3D CSS3 transform matrix.
The final goal is to create a tool for artistic projects using projectors and animation - somewhat far away from using maths...
I'm using a projector to project several squares over several shapes - as seen in the picture.
What I would like to do is for the user to draw 4 points on the screen (2D x and y) and from there extract a matrix object that I could apply to a regular DIV element of a dimension of 100px by 100px.
By finding scaleX, scaleY, rotation, rotationX, rotationZ and probably some perspective that I could apply to the div to relatively match the surface.
I'm not really familiar with geometry beyond sin and cos, and 3D in general and don't even know if that is something doable. If anyone could help me get started or point me in the right direction, I would greatly appreciate.
Here is an animated gif (click to enlarge), hoping it makes it more clear to understand.

REPLY [7 votes]: This isn't my solution, just a link to what, for me, was the perfect solution:
http://franklinta.com/2014/09/08/computing-css-matrix3d-transforms/
The way it's made, you can paste the JS into the page you're working on and line up the points exactly how you want, then copy the CSS from the inspector.
As far as I can tell (which is only superficially), this does the same thing as MvG's JS Fiddle, but it's packaged in a way that was more useful to me. HTH!