# xmlgraphics-batik-users mailing list archives

##### Site index · List index
Message view
Top
From "Bishop, Michael W. CONTR J9C880" <Michael.Bis...@je.jfcom.mil>
Subject RE: Extracting information from a transformation matrix
Date Fri, 02 Jun 2006 13:20:53 GMT
```I don't care how it looks at all.  I don't need to present information
to the user.  I can store the 6 values and keep it that way.  So let me
think through this from a matrix standpoint.  First we translate by
(x,y):

1 0 0     x     (1 * x) + (0 * x) + (0 * 1)    x
0 1 0  *  y  =  (0 * y) + (1 * y) + (0 * y) =  y
0 0 1     1     (0 * 1) + (0 * 1) + (1 * 1)    1

I assume that makes my new matrix look like this:

1 0 x
0 1 y
0 0 1

So now to scale by (sx, sy):

1 0 x     sx 0  0     sx 0  x
0 1 y  *  0  sy 0  =  0  sy y
0 0 1     0  0  1     0  0  1

Finally, rotate by t

sx 0  x     cos(t) -sin(t) 0     (sx * cos(t)) + (0 * sin(t))  +  (x *
0)
0  sy y  *  sin(t) cos(t)  0  =  (0 * cos(t))  + (sy * sin(t)) +  (y *
0)
0  0  1     0      0       1     (0 * cos(t))  + (0 * sin(t))  +  (1 *
0)

...and so on and so forth...I'm not typing out all that!

But realistically, if I wanted to rotate around a center point, I'd
translate to the center point, perform the rotation, then "untranslate"
to the center point.  Does Batik assist with these calculations?  Or am
I going to be manually multiplying these values?  Am I even on the right
track here in that every operation I want to do is a new multiplication?
After I rotate, if I want to translate again, do I have to "undo"
anything or just multiply in a new (tx, ty)?

Michael Bishop

-----Original Message-----
From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
Sent: Friday, June 02, 2006 6:14 AM
To: batik-users@xmlgraphics.apache.org
Cc: batik-users@xmlgraphics.apache.org
Subject: RE: Extracting information from a transformation matrix

Hi Michael, Andrew,

Andrew Plotkin <erkyrath@eblong.com> wrote on 06/01/2006 11:47:12 PM:

> On Thu, 1 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:
>
> >
> > Assume that the transformation is always in order:
> >
> > translate(x,y) scale(sx, sy) rotate(t, cx, cy)
> >
> > As stated, we're given cx, and cy:
> >
> > transform="translate(20, 20) scale(3,3) rotate(60, 2, 2)"
> >
> > At this point I've dragged the element some unknown amount.
Although
> > translate says (20, 20), I know this is not correct because I've
also
> > scaled and rotated.
>
> Honestly, the easiest thing to do is store it as a matrix. Multiply

> translate(20,20) matrix on the right (or is it the left?) and you'll
get

> the correct answer. Don't convert it to "translate(x,y) scale(sx, sy)
> rotate(t, cx, cy)" until you need to.

Right, the best way to view the matrix is as a matrix.  If you want
to have it 'make sense' to the user you may choose to decompose it
but even that shouldn't really try and make sense of the matrix as a
whole.  The basic trick here is to try and do the following

M = original matrix;
R = Rotation about Center Point
R' = inverse of R

M = M*R'*R,   M1 = M*R',  M = M1*R

S = Scale (around Center point, if you want)
S' = inverse of S

M = M1*S'*S*R, M2 = M1*S', M = M2*S*R

At this point M2 should be of the form:
1 0 Tx
0 1 Ty

(actually my guess is that you won't have quite 1 0, 0 1
but it should be close enough).

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org