Hi, I'm having transformation matrix woes. So I have 2 line segments and I'm trying construct with scale(), translate() and rotate() the matrix that maps one onto the other. I'm almost there but I'm having issues with the operator order. At the moment I have (partially pseudo):
- PMatrix2d mat = new PMatrix2d();
- //get the scale ratio of the line segs
- float scale = line2.getLength() / line1.getLength();
- //get angle between line segs
- float angle = PVector.sub( line2 .p2, line2 .p1).heading2D() - PVector.sub(line1.p2, line1.p1).heading2D() + Main.PI;
- mat.translate(line1.p1.x, line1 .p1.y);
- mat.scale(scale);
- mat.translate(- line1.p1.x, - line1.p1.y);
- mat.translate(( line2.p2.x - line1.p1.x)/scale, ( line2.p2.y - line1.p1.y)/scale);
- mat.rotate(angle);
- return mat;
1