Question

Java's transformations done with Graphics2D and AffineTransforms have a last-specified, first-applied order. For example, to rotate a component and then translate it, you first call translate() and later rotate(). Why is that? Is there some application or implementation that favors it? To me it just seems counter-intuitive.

I understand that AffineTransforms are represented with a matrix, and (while I don't know the details) multiple transforms can be concatenated by multiplying the matrices onto each other. What I don't understand is why this seems to be a right-multiply instead of a left-multiply.

Était-ce utile?

La solution

Think of it this way: the transformation that is specified later is closer to the drawing primitive that follows and therefore applied first.

This sequence makes it simpler to apply a transformation to a complex drawing. Suppose you have a method that draws some complex figure and uses itself also transformations. You want the figure to appear twice in different sizes. You can first set the scaling transformation and then call your method. For the second appearance you set another scaling and then call your method again.

This would not be possible, if the transformations are specified in the other order.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top