定义运算符时矩阵串联有何意义?当我们处理 2 维矩阵时,为什么还有 3 维矩阵?我觉得问这个问题真的很愚蠢,但我缺乏任何有关此问题的信息,即使我非常熟悉 vector 分析和代数......为什么不只是将变换或缩放矩阵相乘,然后作为运算符应用于坐标?
我正在尝试为我已经可以通过鼠标翻译的网格添加缩放到鼠标的功能,但两天来我却做不到。有没有办法在变压器上使用 setTranslate 或 setScale 而不重置已经存在的运算符?串联的组合是如何工作的?
编辑最后我得到了正确的缩放到点和从点开始的算法...技巧是在应用其他任何内容之前应用依赖于缩放级别本身的翻译,同时保存前一个运算符:(如果有人对此感兴趣..)
AffineTransform savedTransform = new AffineTransform(transformer);
AffineTransform tempTransform = new AffineTransform();
tempTransform.translate(-0.25*(mouseX-transOfGridXD-game.curWS*sF*sqSize/2), -0.25*(mouseY-transOfGridYD-game.curWS*sF*sqSize/2)); //sF is the zoom level, game.curWS*sqSize is the grid size in pixels, transOfGrid is the translation of the transform
tempTransform.concatenate(savedTransform);
transformer.setTransform(tempTransform );
transformer.translate(-(game.curWS)*sqSize*0.125, -(game.curWS)*sqSize*0.125);
transformer.scale(1.25, 1.25);
最佳答案
Wikipedia has a lot on affine transformations 。通过使用 3x3 矩阵乘法,您可以同时执行旋转、反射和平移。 p>
即所有这些运算都可以放入单个矩阵运算 M*x'(其中 x ' 是带有额外行的 vector x)。现在,这种矩阵乘法可以在硬件中实现(这本质上就是 3D 显卡所做的 - 优化 4D 乘法 - 而且您的打印机也可能具有针对 3D 乘法的优化电路!)
关于java - 仿射变换如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25752930/