0

How does concatenation of matrices makes sense when defining operators? Why are there even 3 dimensional matrices when we are dealing with 2 dimensions? I feel really stupid asking this but I lack any kind of information about this even though I'm quite familiar with vector analysis and algebra... Why aren't just the transformation or scaling matrices multiplied and then applied as an operator to the coordinates?

I'm trying to make a zoom-to-mouse feature to my already translatable-by-mouse grid and for 2 days I just can't. Is there a way to use setTranslate or setScale on the transformer without resetting the already existing operator? How does the composition of concatenation work?

EDIT Finally I got the zoom-to-and-from-a-point algorithm right... The trick is to apply translations that are dependent on the zoomLevel itself before you apply anything else, while saving the previous operator: (In case someone is interested in this..)

    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);
Ryan Marv
  • 109
  • 6
  • 3
    Your question is very broad. See [*Affine transformation: Augmented matrix*](http://en.wikipedia.org/wiki/Affine_transformation#Augmented_matrix) about the extra row and column. – trashgod Sep 09 '14 at 20:20
  • You might look at a few [examples](http://stackoverflow.com/search?tab=votes&q=%5bjava%5d%20AffineTransform), for [example](http://stackoverflow.com/a/3420651/230513). – trashgod Sep 09 '14 at 20:25
  • 1
    Very short answer to the first part of your question: (see trashgod's link for the rest) Applying one transformantion is accomplished by one matrix multiplication. Applying a sequence of transforms is a sequence of multiplications. The math lets you multiply the transform matrices first, and then apply the result of that to the point. Very useful when you have a long list of points that all must be transformed by the same sequence of operations. – Solomon Slow Sep 09 '14 at 21:10

1 Answers1

2

Wikipedia has a lot on affine transformations. By using a 3x3 matrix multiplication, you can perform rotation, reflection and translation at the same time.

I.e. instead of computing D*(C*(B*(x+a)+b)+c)+d all of these operations can be put into a single matrix operation M*x' (where x' is the vector x with an extra row). Now this matrix multiplication can be implemented in hardware (that's essentially what 3D graphics cards do - optimize 4D multiplications - but also your printer likely has optimized circuits for 3D multiplication!)

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194