You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> on 2006/06/01 15:12:27 UTC

RE: Extracting information from a transformation matrix

Wow, this is going to make me take another close look at the transformation matrix for SVG.  Let's start with an example:
 
transform="translate(x, y) scale(sx, sy) rotate(t, cx, cy)"
 
The above is the only kind of transform I maintain in my application.
 
If the user drags an element around the screen, it directly affects translate.
If the user scales the element, it affects scale which indirectly affects translate.
If the user rotates the element, I believe it affects scale which also affects translate.
 
What I want to do is be able to break apart the above to find out the values I wanted before.  The first thing I need to go is get a representation of the above into the matrix values (a, b, c, d, e, f).
 
I believe the first thing that needs extracting is the "rotate" value.  I need to find the rotation angle and "reverse" any effect on the scale and translate.
 
Next I need to extract the "scale" value and again "reverse" any effect that it has on translate.
 
Finally, the translate value left represents how much the user has dragged/dropped the element on the canvas.
 
Michael Bishop

________________________________

From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
Sent: Wed 5/31/2006 5:48 AM
To: batik-users@xmlgraphics.apache.org
Cc: batik-users@xmlgraphics.apache.org
Subject: RE: Extracting information from a transformation matrix



Hi Michael,

   There are many ways to view an AffineTransform.
In general the hard bit isn't extracting a rotation
angle or a scaling transform, the hard bit is that
in complex cases you may be left with a complex
matrix.

   For example with rotation it's easy to pick a
simple rotation matrix to 'extract'.  Simply
look at the rotation effect on say the X-axis
(note that for matrix with non-uniform scale or
shear you may get a different rotation value for
the Y-axis).

   Once you have a rotation you can 'assume'
that it was rotation about the center of your
object (which should stay constant in the
coordinate system established by the matrix).
By making this assumption you can construct your
rotation matrix around the center point.

   You can then invert it and multiply it with
the original matrix. The result is that you have
'extracted' a rotation around the center of the
object.

   Something very similar can be done for scaling.
If your source matrix is really just uniform scaling
and rotation then after all this is done you should
only have translation left.

    Of course if your matrix has other junk in it,
then all that junk will be left in the 'residual'
matrix.  There really isn't much 'sensible' that
can usually be done with this (especially if it
includes 'shear').

"Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on
05/30/2006 09:31:17 AM:

> If you scale/rotate around the center point of an element, this doesn't
> account for it, does it?  To find out how much of the translation is a
> scale operation:
>
> scaleTranslateX = -centerX * (scaleX - 1.0);
>
> Rotation is similar when you rotate around a center point.
>
> I've been storing a number of values:
> moveTranslateX/Y (How much the client has moved the element around the
> screen)
> scaleTranslateX/Y (How much translation has occurred as the result of a
> scale)
> centerX/Y (Center point)
> rotate (Rotation angle)
>
> I don't suppose there's a way to break out these values from the matrix?
> Storing extraneous information in an SVG file doesn't seem to be the way
> to do things.  I'd tried to tackle this before in the past, but never
> found an acceptable solution.
>
> Michael Bishop
>
> -----Original Message-----
> From: Andreas Neumann [mailto:neumann@karto.baug.ethz.ch]
> Sent: Saturday, May 27, 2006 10:40 AM
> To: batik-users@xmlgraphics.apache.org
> Subject: Re: Extracting information from a transformation matrix
>
> Hi Philip,
>
> Thomas Meinike recently wrote an article in a german developers magazine
>
> on reverse-engineering SVG matrices to their individual
> translate/rotate/skew/scale components.
>
> See javascript code at
> http://www.datenverdrahten.de/svglbc/?code=matrix_reverse&znr=on
>
> Thomas Meinike also published tons of other very useful SVG and
> ECMAScript examples. Explanations are usually in german, but you'll
> figure out the js code easily.
>
> Hope this helps,
> Andreas
>
> Bishop, Michael W. CONTR J9C880 wrote:
>
> >Well let us know if you figure it out.  Rotate affects scale, scale
> affects translate.  I haven't touched shear or skew.  I thnk it may be
> possible to reverse-engineer it all.  Figure out rotate's affect on
> scale.  Figure out scale's affect on translate.  I had it working when I
> was just scaling and translating.  I gave up when it came to rotating
> though.
> >
> >Michael Bishop
> >
> >  _____
> >
> >From: Philip Wilder [mailto:philip.wilder@gmail.com]
> >Sent: Thu 5/25/2006 11:35 AM
> >To: batik-users@xmlgraphics.apache.org
> >Subject: Re: Extracting information from a transformation matrix
> >
> >
> >
> >I've considered that, but I am manipulating 2DGraphics in Java,
> >exporting to SVG and back again. Ideally speaking I want to be able to
> >accomodate all SVG files whether they were created by my tool or not.
> >So like it or not I have to provide support for the matrix(a, b, c, d,
> >e, f) transformation function.
> >
> >Philip
> >
> >
> >On 5/25/06, Bishop, Michael W. CONTR J9C880
> <Mi...@je.jfcom.mil> wrote:
> >
> >
> >>I was unable to.  I track translate, scale, and rotate separately and
> combine them to form the transform attribute.
> >>
> >>Michael Bishop
> >>
> >>________________________________
> >>
> >>From: Philip Wilder [mailto:philip.wilder@gmail.com]
> >>Sent: Thu 5/25/2006 9:07 AM
> >>To: batik-users@xmlgraphics.apache.org
> >>Subject: Extracting information from a transformation matrix
> >>
> >>
> >>
> >>Hello all,
> >>
> >>While I apologize in that this is not necessarily a Batik specific
> >>question but I've run across it in my interactions with Batik and Java
> >>so I thought I would pose it here. Basically I would like to know if
> >>it is possible to extract information from a transformation matrix.
> >>Specifically I will like to be able to track things like shear,
> >>rotation and transformation independently. Other online sources would
> >>seem to indicate no, but it would be helpful if someone here could
> >>give me an authoritative (or at least confident) yay or nay.
> >>
> >>Thanks,
> >>
> >>Philip
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> >>For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> >>
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> >>For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> >>
> >>
> >>
> >>
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> >For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> >
> >
> >
> >
> >-----------------------------------------------------------------------
> -
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> >For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> >
>
>
> --
> ----------------------------------------------
> Andreas Neumann
> Institute of Cartography
> ETH Zurich
> Wolfgang-Paulistrasse 15
> CH-8093  Zurich, Switzerland
>
> Phone: ++41-44-633 3031, Fax: ++41-44-633 1153
> e-mail: neumann@karto.baug.ethz.ch
> www: http://www.carto.net/neumann/
> SVG.Open: http://www.svgopen.org/
> Carto.net: http://www.carto.net/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org



RE: Extracting information from a transformation matrix

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
I do have non-uniform scaling.  I allow the user to scale and "preserve the aspect ratio" or scale on just the X or Y axis.  I guess that explains why rotate looks strange after non-uniform scaling?  How do I account for that?
 
Michael Bishop

________________________________

From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
Sent: Tue 6/6/2006 8:38 PM
To: batik-users@xmlgraphics.apache.org
Cc: batik-users@xmlgraphics.apache.org
Subject: RE: Extracting information from a transformation matrix



Hi Michael,

"Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on
06/06/2006 08:28:55 PM:

> I'm confused...why do you call it "rotX"?
> Isn't there only a single rotation angle?

   Not in the presence of shear.  Take the simple example of shearY:

+------+         +------+
|      |   ->   /       /
+------+       +-------+

   Note that a vector aligned with the x-axis will experience no
rotation.  However a vector aligned with the y-axis will experience
rotation.  This is why I called the above value 'rotX' it is
the rotation of a vector aligned on the x-axis.

   If you don't have shear or non-uniform scaling (which can make
some of a normal rotation "look like" shear), this BTW is your
case, then rotX and the similar 'rotY' calculation will match.



> ________________________________
>
> From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> Sent: Tue 6/6/2006 7:46 PM
> To: batik-users@xmlgraphics.apache.org
> Cc: batik-users@xmlgraphics.apache.org
> Subject: RE: Extracting information from a transformation matrix
>
>
>
> Hi Michael,
>
> "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on
> 06/06/2006 01:39:25 PM:
>
> > OK, I'm still struggling with this.  I'm trying to derive the rotation
> > angle using the MatrixReverse function here:
> >
> > http://www.datenverdrahten.de/svglbc/?code=matrix_reverse&znr=on
>
>    The code there doesn't look right to me.  In particular
> the calculation of konst1 is using tansky which is known to
> be zero.  I can't say this is 100% wrong (it may simply be
> to reduce 'unknowns').
>
>    I would simply use:
>
>         double rotX = Math.atan2(at.getShearX(), at.getScaleX());
>
>    I'm fairly sure I have scaleX/shearX in the right place.
>
> > Here's my test code:
> >
> > AffineTransform affineTransform = new AffineTransform(1, 0, 0, 1, 0,
0);
> >         affineTransform.translate(10, 10);
> >         affineTransform.scale(2, 2);
> >         System.out.println("Transform: " + affineTransform);
> >         System.out.println(
> >             "Angle: " +
> > AffineTransformUtil.getRotationAngle(affineTransform));
> >         affineTransform.rotate(60);
> >         System.out.println(
> >             "Angle: " +
> > AffineTransformUtil.getRotationAngle(affineTransform));
> >
> > The first time, the angle is reported as 0.0 which is correct.  The
> > second time, it's reported as 17.746...which is not.  I'm under the
> > impression it should be 60.  Anyone know how/why this (doesn't) work?
> >
> > Michael Bishop
> >
> > -----Original Message-----
> > From: Bishop, Michael W. CONTR J9C880
> > [mailto:Michael.Bishop@je.jfcom.mil]
> > Sent: Monday, June 05, 2006 1:49 PM
> > To: batik-users@xmlgraphics.apache.org
> > Subject: RE: Extracting information from a transformation matrix
> >
> > Well I'm trying to integrate this side-by-side with what's already
> > there.  So when I print out the attributes, I print out the
"transform"
> > attribute and I print out the dummy "matrix" attribute
> > (matrix="matrix(a, b, c, d, e, f)".
> >
> > The problem is that if I translate, things are fine.  If I scale,
things
> > are fine.  If I scale, then translate, the "matrix" numbers don't
match
> > the "transform".  In order to get them to match up, I've been
"undoing"
> > everything:
> >
> > (For translation)
> >
> > transform.scale(1.0d / sx, 1.0d / sy);
> > transform.translate(tx, ty);
> > transform.scale(sx, sy);
> >
> > In order to make the numbers "match", I have to do all my translations
> > "first" before scaling.  This kind of makes sense; when I use the
> > transform attribute, I always start from scratch: translate(tx, ty)
> > scale(sx, sy) rotate(t).
> >
> > I see the "preConcatenate" method here in the JDK, so let's go back to
> > my use case.  I want to be able to translate, rotate, and scale in any
> > order.  The user could draw an element, scale it by 150%, rotate it 60
> > degrees, drag it to the left, scale down to 50%, etc.
> >
> > I'm not sure how preconcatenating will help because I don't know when
to
> > do it and when not to.  I need to preconcatenate before any scaling
> > operations I think.  Rotate just makes it even tougher.
> >
> > Michael Bishop
> >
> > -----Original Message-----
> > From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> > Sent: Monday, June 05, 2006 1:38 PM
> > To: batik-users@xmlgraphics.apache.org
> > Cc: batik-users@xmlgraphics.apache.org
> > Subject: RE: Extracting information from a transformation matrix
> >
> > Hi Michael,
> >
> > "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote
on
> >
> > 06/05/2006 12:12:15 PM:
> >
> > > Am I correct in assuming that:
> > >
> > > transform(tx, ty) scale(sx, sy)
> > >
> > > and
> > >
> > > sx  0  tx
> > > 0   sy ty
> > >
> > > will hold identical values for sx, sy, tx, and ty for any values of
> > > those variables?  In other words, no matter how I scale/translate or
> > in
> > > what order, should it matter?  Note that no rotation has been
> > > introduced.
> >
> >    Order does matter. So scale then translate is different from
> > translate then scale.  However since you are manipulating the
> > transform on one element you can play some games by choosing to
> > pre or post multiply the various transforms.  So if you always
> > post multiply the translate transform (preconcatenate in JDK
> > terms) then the translate part will just be 'added' to the
> > existing matrix.  This is probably what you want for translate
> > (from what I recall of how you handle things).
> >
> >
> > >
> > > Michael Bishop
> > >
> > > -----Original Message-----
> > > From: Bishop, Michael W. CONTR J9C880
> > > [mailto:Michael.Bishop@je.jfcom.mil]
> > > Sent: Friday, June 02, 2006 12:32 PM
> > > To: batik-users@xmlgraphics.apache.org
> > > Subject: RE: Extracting information from a transformation matrix
> > >
> > > Good, good...OK, now I'm getting an understanding and figuring out
> > what
> > > needs to be done.  I assume the 6 values are represented as:
> > >
> > > a b c
> > > d e f
> > > 0 0 1 (implied, I know we don't really care about these values)
> > >
> > > According to my reference, to do a translation, I would have to
> > multiply
> > > in the following:
> > >
> > > 1 0 tx
> > > 0 1 ty
> > > 0 0 1 (again, implied)
> > >
> > > A scale:
> > >
> > > sx  0   0
> > > 0   sy  0
> > > 0   0   1 (implied for consistency's sake)
> > >
> > > A rotate:
> > >
> > > cos(t) -sin(t) 0
> > > sin(t)  cos(t) 0
> > > 0       0      1 (blah blah)
> > >
> > > To get this done in code:
> > >
> > > AffineTransform affineTransform = new AffineTransform(a, b, c, d, e,
> > f);
> > > SVGMatrix svgMatrix = new SVGOMMatrix(affineTransform);
> > >
> > > Besides the obvious way of calling getA(), getB(), etc., is there a
> > way
> > > to turn this into the proper attribute?
> > >
> > > transform="matrix(a, b, c, d, e, f)"
> > >
> > > Michael Bishop
> > > -----Original Message-----
> > > From: Andrew Plotkin [mailto:erkyrath@eblong.com]
> > > Sent: Friday, June 02, 2006 12:20 PM
> > > To: batik-users@xmlgraphics.apache.org
> > > Subject: RE: Extracting information from a transformation matrix
> > >
> > > On Fri, 2 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:
> > >
> > > > 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.
> > >
> > > Ok.
> > >
> > > > 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?
> > >
> > > The SVGMatrix interface has a multiply(SVGMatrix) method.
> > >
> > > > Am I even on the right
> > > > track here in that every operation I want to do is a new
> > > multiplication?
> > >
> > > Yes, that's right.
> > >
> > > > After I rotate, if I want to translate again, do I have to "undo"
> > > > anything or just multiply in a new (tx, ty)?
> > >
> > > Just multiply in a new one.
> > >
> > > --Z
> > >
> > > --
> > > "And Aholibamah bare Jeush, and Jaalam, and Korah: these were the
> > > borogoves..."
> > > *
> > > If the Bush administration hasn't subjected you to searches without
a
> > > warrant,
> > > it's for one reason: they don't feel like it. Not because you're
> > > innocent.
> > >
> > >
---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
batik-users-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail:
> > batik-users-help@xmlgraphics.apache.org
> > >
> > >
---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
batik-users-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail:
> > batik-users-help@xmlgraphics.apache.org
> > >
> > >
---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
batik-users-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail:
> > batik-users-help@xmlgraphics.apache.org
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail:
batik-users-help@xmlgraphics.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail:
batik-users-help@xmlgraphics.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail:
batik-users-help@xmlgraphics.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>
> [attachment "winmail.dat" deleted by Thomas E. DeWeese/449433/EKC]
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org



RE: Extracting information from a transformation matrix

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
Yeah, I was thinking rotate(degrees) was the same as
AffineTransform.rotate(degrees) and it's not.  It seems your latest
example works.  I didn't realize that manipulating an element was going
to be such a pain.  I suspect that's why InkScape "applies" each
transformation after you manipulate an object.  If you move it, it
changes the attributes that define the location.  If you scale it, it
changes the attributes that manipulate the width/height.  I thought that
would be a major pain (especially for polyline, polygon, and path
elements).  Now I'm not so sure.  Thanks for the help in figuring this
out.  A utility class that takes an element's AffineTransform and
correctly allows multiple move, scale, rotate, etc. is probably what I'm
going to write to keep all this simple.

Michael Bishop

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

Hi Michael,

"Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on

06/07/2006 03:31:12 PM:

> public static double[] getRotationAngle(AffineTransform inTransform) {
> double tx = Math.atan2(inTransform.getShearX(),
> inTransform.getScaleX());
> double ty = Math.atan2(inTransform.getShearY(),
> inTransform.getScaleY());

   I suspect these may need some tweaking. 
I don't have the time to sit down and sort the trig 
out exactly but I suspect I used ShearX when I should
have used ShearY, so something like:

double rx = Math.atan2(inTransform.getShearY(),
inTransform.getScaleX());
double ry =
Math.atan2(-inTransform.getShearX(),inTransform.getScaleY());

   but really you should pull out your old Trig Texts 
to sort this out.

> AffineTransform affineTransform = new AffineTransform(1, 0, 0, 1, 0
,0);
> affineTransform.translate(10, 10);
> affineTransform.scale(2, 2);
> affineTransform.rotate(60);

    Like most computer languages (and real math people) the
value to rotate is in radians (2*PI rad = 360 deg).  Since
this wraps every 2PI the above value is really ~3.451 which
is -2.83185... if you map it in the range -PI to PI.

> double[] rotation =
> AffineTransformUtil.getRotationAngle(affineTransform);
> System.out.println("Rotation X: " + rotation[0]);
> System.out.println("Rotation Y: " + rotation[1]);
> }
> 
> I get unexpected results:
> 
> Rotation X: 2.831853071795865
> Rotation Y: -2.831853071795865

   This is close to the expected results, perhaps
the above fix with sort the rest of it out...

> 
> I thought in this case with uniform scaling, I'd see 60.
> If I have non-uniform scaling, how do I represent two different
rotation
> angles (x and y) in the transform attribute?  I don't understand how
> rotate(t, cx, cy) breaks down into two values for rotate.
> 
> Michael Bishop
> 
> -----Original Message-----
> From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com] 
> Sent: Tuesday, June 06, 2006 8:39 PM
> To: batik-users@xmlgraphics.apache.org
> Cc: batik-users@xmlgraphics.apache.org
> Subject: RE: Extracting information from a transformation matrix
> 
> Hi Michael,
> 
> "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote
on
> 
> 06/06/2006 08:28:55 PM:
> 
> > I'm confused...why do you call it "rotX"? 
> > Isn't there only a single rotation angle?
> 
>    Not in the presence of shear.  Take the simple example of shearY:
> 
> +------+         +------+
> |      |   ->   /       /
> +------+       +-------+
> 
>    Note that a vector aligned with the x-axis will experience no
> rotation.  However a vector aligned with the y-axis will experience
> rotation.  This is why I called the above value 'rotX' it is
> the rotation of a vector aligned on the x-axis.
> 
>    If you don't have shear or non-uniform scaling (which can make
> some of a normal rotation "look like" shear), this BTW is your
> case, then rotX and the similar 'rotY' calculation will match.
> 
> 
> 
> > ________________________________
> > 
> > From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> > Sent: Tue 6/6/2006 7:46 PM
> > To: batik-users@xmlgraphics.apache.org
> > Cc: batik-users@xmlgraphics.apache.org
> > Subject: RE: Extracting information from a transformation matrix
> > 
> > 
> > 
> > Hi Michael,
> > 
> > "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>
wrote
> on
> > 06/06/2006 01:39:25 PM:
> > 
> > > OK, I'm still struggling with this.  I'm trying to derive the
> rotation
> > > angle using the MatrixReverse function here:
> > >
> > > http://www.datenverdrahten.de/svglbc/?code=matrix_reverse&znr=on
> > 
> >    The code there doesn't look right to me.  In particular
> > the calculation of konst1 is using tansky which is known to
> > be zero.  I can't say this is 100% wrong (it may simply be
> > to reduce 'unknowns').
> > 
> >    I would simply use:
> > 
> >         double rotX = Math.atan2(at.getShearX(), at.getScaleX());
> > 
> >    I'm fairly sure I have scaleX/shearX in the right place.
> > 
> > > Here's my test code:
> > >
> > > AffineTransform affineTransform = new AffineTransform(1, 0, 0, 1,
0,
> 
> 0);
> > >         affineTransform.translate(10, 10);
> > >         affineTransform.scale(2, 2);
> > >         System.out.println("Transform: " + affineTransform);
> > >         System.out.println(
> > >             "Angle: " +
> > > AffineTransformUtil.getRotationAngle(affineTransform));
> > >         affineTransform.rotate(60);
> > >         System.out.println(
> > >             "Angle: " +
> > > AffineTransformUtil.getRotationAngle(affineTransform));
> > >
> > > The first time, the angle is reported as 0.0 which is correct.
The
> > > second time, it's reported as 17.746...which is not.  I'm under
the
> > > impression it should be 60.  Anyone know how/why this (doesn't)
> work?
> > >
> > > Michael Bishop
> > >
> > > -----Original Message-----
> > > From: Bishop, Michael W. CONTR J9C880
> > > [mailto:Michael.Bishop@je.jfcom.mil]
> > > Sent: Monday, June 05, 2006 1:49 PM
> > > To: batik-users@xmlgraphics.apache.org
> > > Subject: RE: Extracting information from a transformation matrix
> > >
> > > Well I'm trying to integrate this side-by-side with what's already
> > > there.  So when I print out the attributes, I print out the 
> "transform"
> > > attribute and I print out the dummy "matrix" attribute
> > > (matrix="matrix(a, b, c, d, e, f)".
> > >
> > > The problem is that if I translate, things are fine.  If I scale, 
> things
> > > are fine.  If I scale, then translate, the "matrix" numbers don't 
> match
> > > the "transform".  In order to get them to match up, I've been 
> "undoing"
> > > everything:
> > >
> > > (For translation)
> > >
> > > transform.scale(1.0d / sx, 1.0d / sy);
> > > transform.translate(tx, ty);
> > > transform.scale(sx, sy);
> > >
> > > In order to make the numbers "match", I have to do all my
> translations
> > > "first" before scaling.  This kind of makes sense; when I use the
> > > transform attribute, I always start from scratch: translate(tx,
ty)
> > > scale(sx, sy) rotate(t).
> > >
> > > I see the "preConcatenate" method here in the JDK, so let's go
back
> to
> > > my use case.  I want to be able to translate, rotate, and scale in
> any
> > > order.  The user could draw an element, scale it by 150%, rotate
it
> 60
> > > degrees, drag it to the left, scale down to 50%, etc.
> > >
> > > I'm not sure how preconcatenating will help because I don't know
> when 
> to
> > > do it and when not to.  I need to preconcatenate before any
scaling
> > > operations I think.  Rotate just makes it even tougher.
> > >
> > > Michael Bishop
> > >
> > > -----Original Message-----
> > > From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> > > Sent: Monday, June 05, 2006 1:38 PM
> > > To: batik-users@xmlgraphics.apache.org
> > > Cc: batik-users@xmlgraphics.apache.org
> > > Subject: RE: Extracting information from a transformation matrix
> > >
> > > Hi Michael,
> > >
> > > "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>
> wrote 
> on
> > >
> > > 06/05/2006 12:12:15 PM:
> > >
> > > > Am I correct in assuming that:
> > > >
> > > > transform(tx, ty) scale(sx, sy)
> > > >
> > > > and
> > > >
> > > > sx  0  tx
> > > > 0   sy ty
> > > >
> > > > will hold identical values for sx, sy, tx, and ty for any values
> of
> > > > those variables?  In other words, no matter how I
scale/translate
> or
> > > in
> > > > what order, should it matter?  Note that no rotation has been
> > > > introduced.
> > >
> > >    Order does matter. So scale then translate is different from
> > > translate then scale.  However since you are manipulating the
> > > transform on one element you can play some games by choosing to
> > > pre or post multiply the various transforms.  So if you always
> > > post multiply the translate transform (preconcatenate in JDK
> > > terms) then the translate part will just be 'added' to the
> > > existing matrix.  This is probably what you want for translate
> > > (from what I recall of how you handle things).
> > >
> > >
> > > >
> > > > Michael Bishop
> > > >
> > > > -----Original Message-----
> > > > From: Bishop, Michael W. CONTR J9C880
> > > > [mailto:Michael.Bishop@je.jfcom.mil]
> > > > Sent: Friday, June 02, 2006 12:32 PM
> > > > To: batik-users@xmlgraphics.apache.org
> > > > Subject: RE: Extracting information from a transformation matrix
> > > >
> > > > Good, good...OK, now I'm getting an understanding and figuring
out
> > > what
> > > > needs to be done.  I assume the 6 values are represented as:
> > > >
> > > > a b c
> > > > d e f
> > > > 0 0 1 (implied, I know we don't really care about these values)
> > > >
> > > > According to my reference, to do a translation, I would have to
> > > multiply
> > > > in the following:
> > > >
> > > > 1 0 tx
> > > > 0 1 ty
> > > > 0 0 1 (again, implied)
> > > >
> > > > A scale:
> > > >
> > > > sx  0   0
> > > > 0   sy  0
> > > > 0   0   1 (implied for consistency's sake)
> > > >
> > > > A rotate:
> > > >
> > > > cos(t) -sin(t) 0
> > > > sin(t)  cos(t) 0
> > > > 0       0      1 (blah blah)
> > > >
> > > > To get this done in code:
> > > >
> > > > AffineTransform affineTransform = new AffineTransform(a, b, c,
d,
> e,
> > > f);
> > > > SVGMatrix svgMatrix = new SVGOMMatrix(affineTransform);
> > > >
> > > > Besides the obvious way of calling getA(), getB(), etc., is
there
> a
> > > way
> > > > to turn this into the proper attribute?
> > > >
> > > > transform="matrix(a, b, c, d, e, f)"
> > > >
> > > > Michael Bishop
> > > > -----Original Message-----
> > > > From: Andrew Plotkin [mailto:erkyrath@eblong.com]
> > > > Sent: Friday, June 02, 2006 12:20 PM
> > > > To: batik-users@xmlgraphics.apache.org
> > > > Subject: RE: Extracting information from a transformation matrix
> > > >
> > > > On Fri, 2 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:
> > > >
> > > > > 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.
> > > >
> > > > Ok.
> > > >
> > > > > 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?
> > > >
> > > > The SVGMatrix interface has a multiply(SVGMatrix) method.
> > > >
> > > > > Am I even on the right
> > > > > track here in that every operation I want to do is a new
> > > > multiplication?
> > > >
> > > > Yes, that's right.
> > > >
> > > > > After I rotate, if I want to translate again, do I have to
> "undo"
> > > > > anything or just multiply in a new (tx, ty)?
> > > >
> > > > Just multiply in a new one.
> > > >
> > > > --Z
> > > >
> > > > --
> > > > "And Aholibamah bare Jeush, and Jaalam, and Korah: these were
the
> > > > borogoves..."
> > > > *
> > > > If the Bush administration hasn't subjected you to searches
> without 
> a
> > > > warrant,
> > > > it's for one reason: they don't feel like it. Not because you're
> > > > innocent.
> > > >
> > > > 
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: 
> batik-users-unsubscribe@xmlgraphics.apache.org
> > > > For additional commands, e-mail:
> > > batik-users-help@xmlgraphics.apache.org
> > > >
> > > > 
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: 
> batik-users-unsubscribe@xmlgraphics.apache.org
> > > > For additional commands, e-mail:
> > > batik-users-help@xmlgraphics.apache.org
> > > >
> > > > 
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: 
> batik-users-unsubscribe@xmlgraphics.apache.org
> > > > For additional commands, e-mail:
> > > batik-users-help@xmlgraphics.apache.org
> > > >
> > >
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> batik-users-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail: 
> batik-users-help@xmlgraphics.apache.org
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> batik-users-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail: 
> batik-users-help@xmlgraphics.apache.org
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> batik-users-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail: 
> batik-users-help@xmlgraphics.apache.org
> > >
> > 
> > 
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> > 
> > 
> > [attachment "winmail.dat" deleted by Thomas E. DeWeese/449433/EKC] 
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail:
batik-users-help@xmlgraphics.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail:
batik-users-help@xmlgraphics.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Extracting information from a transformation matrix

Posted by th...@kodak.com.
Hi Michael,

"Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on 
06/07/2006 03:31:12 PM:

> public static double[] getRotationAngle(AffineTransform inTransform) {
> double tx = Math.atan2(inTransform.getShearX(),
> inTransform.getScaleX());
> double ty = Math.atan2(inTransform.getShearY(),
> inTransform.getScaleY());

   I suspect these may need some tweaking. 
I don't have the time to sit down and sort the trig 
out exactly but I suspect I used ShearX when I should
have used ShearY, so something like:

double rx = Math.atan2(inTransform.getShearY(), inTransform.getScaleX());
double ry = Math.atan2(-inTransform.getShearX(),inTransform.getScaleY());

   but really you should pull out your old Trig Texts 
to sort this out.

> AffineTransform affineTransform = new AffineTransform(1, 0, 0, 1, 0 ,0);
> affineTransform.translate(10, 10);
> affineTransform.scale(2, 2);
> affineTransform.rotate(60);

    Like most computer languages (and real math people) the
value to rotate is in radians (2*PI rad = 360 deg).  Since
this wraps every 2PI the above value is really ~3.451 which
is -2.83185... if you map it in the range -PI to PI.

> double[] rotation =
> AffineTransformUtil.getRotationAngle(affineTransform);
> System.out.println("Rotation X: " + rotation[0]);
> System.out.println("Rotation Y: " + rotation[1]);
> }
> 
> I get unexpected results:
> 
> Rotation X: 2.831853071795865
> Rotation Y: -2.831853071795865

   This is close to the expected results, perhaps
the above fix with sort the rest of it out...

> 
> I thought in this case with uniform scaling, I'd see 60.
> If I have non-uniform scaling, how do I represent two different rotation
> angles (x and y) in the transform attribute?  I don't understand how
> rotate(t, cx, cy) breaks down into two values for rotate.
> 
> Michael Bishop
> 
> -----Original Message-----
> From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com] 
> Sent: Tuesday, June 06, 2006 8:39 PM
> To: batik-users@xmlgraphics.apache.org
> Cc: batik-users@xmlgraphics.apache.org
> Subject: RE: Extracting information from a transformation matrix
> 
> Hi Michael,
> 
> "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on
> 
> 06/06/2006 08:28:55 PM:
> 
> > I'm confused...why do you call it "rotX"? 
> > Isn't there only a single rotation angle?
> 
>    Not in the presence of shear.  Take the simple example of shearY:
> 
> +------+         +------+
> |      |   ->   /       /
> +------+       +-------+
> 
>    Note that a vector aligned with the x-axis will experience no
> rotation.  However a vector aligned with the y-axis will experience
> rotation.  This is why I called the above value 'rotX' it is
> the rotation of a vector aligned on the x-axis.
> 
>    If you don't have shear or non-uniform scaling (which can make
> some of a normal rotation "look like" shear), this BTW is your
> case, then rotX and the similar 'rotY' calculation will match.
> 
> 
> 
> > ________________________________
> > 
> > From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> > Sent: Tue 6/6/2006 7:46 PM
> > To: batik-users@xmlgraphics.apache.org
> > Cc: batik-users@xmlgraphics.apache.org
> > Subject: RE: Extracting information from a transformation matrix
> > 
> > 
> > 
> > Hi Michael,
> > 
> > "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote
> on
> > 06/06/2006 01:39:25 PM:
> > 
> > > OK, I'm still struggling with this.  I'm trying to derive the
> rotation
> > > angle using the MatrixReverse function here:
> > >
> > > http://www.datenverdrahten.de/svglbc/?code=matrix_reverse&znr=on
> > 
> >    The code there doesn't look right to me.  In particular
> > the calculation of konst1 is using tansky which is known to
> > be zero.  I can't say this is 100% wrong (it may simply be
> > to reduce 'unknowns').
> > 
> >    I would simply use:
> > 
> >         double rotX = Math.atan2(at.getShearX(), at.getScaleX());
> > 
> >    I'm fairly sure I have scaleX/shearX in the right place.
> > 
> > > Here's my test code:
> > >
> > > AffineTransform affineTransform = new AffineTransform(1, 0, 0, 1, 0,
> 
> 0);
> > >         affineTransform.translate(10, 10);
> > >         affineTransform.scale(2, 2);
> > >         System.out.println("Transform: " + affineTransform);
> > >         System.out.println(
> > >             "Angle: " +
> > > AffineTransformUtil.getRotationAngle(affineTransform));
> > >         affineTransform.rotate(60);
> > >         System.out.println(
> > >             "Angle: " +
> > > AffineTransformUtil.getRotationAngle(affineTransform));
> > >
> > > The first time, the angle is reported as 0.0 which is correct.  The
> > > second time, it's reported as 17.746...which is not.  I'm under the
> > > impression it should be 60.  Anyone know how/why this (doesn't)
> work?
> > >
> > > Michael Bishop
> > >
> > > -----Original Message-----
> > > From: Bishop, Michael W. CONTR J9C880
> > > [mailto:Michael.Bishop@je.jfcom.mil]
> > > Sent: Monday, June 05, 2006 1:49 PM
> > > To: batik-users@xmlgraphics.apache.org
> > > Subject: RE: Extracting information from a transformation matrix
> > >
> > > Well I'm trying to integrate this side-by-side with what's already
> > > there.  So when I print out the attributes, I print out the 
> "transform"
> > > attribute and I print out the dummy "matrix" attribute
> > > (matrix="matrix(a, b, c, d, e, f)".
> > >
> > > The problem is that if I translate, things are fine.  If I scale, 
> things
> > > are fine.  If I scale, then translate, the "matrix" numbers don't 
> match
> > > the "transform".  In order to get them to match up, I've been 
> "undoing"
> > > everything:
> > >
> > > (For translation)
> > >
> > > transform.scale(1.0d / sx, 1.0d / sy);
> > > transform.translate(tx, ty);
> > > transform.scale(sx, sy);
> > >
> > > In order to make the numbers "match", I have to do all my
> translations
> > > "first" before scaling.  This kind of makes sense; when I use the
> > > transform attribute, I always start from scratch: translate(tx, ty)
> > > scale(sx, sy) rotate(t).
> > >
> > > I see the "preConcatenate" method here in the JDK, so let's go back
> to
> > > my use case.  I want to be able to translate, rotate, and scale in
> any
> > > order.  The user could draw an element, scale it by 150%, rotate it
> 60
> > > degrees, drag it to the left, scale down to 50%, etc.
> > >
> > > I'm not sure how preconcatenating will help because I don't know
> when 
> to
> > > do it and when not to.  I need to preconcatenate before any scaling
> > > operations I think.  Rotate just makes it even tougher.
> > >
> > > Michael Bishop
> > >
> > > -----Original Message-----
> > > From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> > > Sent: Monday, June 05, 2006 1:38 PM
> > > To: batik-users@xmlgraphics.apache.org
> > > Cc: batik-users@xmlgraphics.apache.org
> > > Subject: RE: Extracting information from a transformation matrix
> > >
> > > Hi Michael,
> > >
> > > "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>
> wrote 
> on
> > >
> > > 06/05/2006 12:12:15 PM:
> > >
> > > > Am I correct in assuming that:
> > > >
> > > > transform(tx, ty) scale(sx, sy)
> > > >
> > > > and
> > > >
> > > > sx  0  tx
> > > > 0   sy ty
> > > >
> > > > will hold identical values for sx, sy, tx, and ty for any values
> of
> > > > those variables?  In other words, no matter how I scale/translate
> or
> > > in
> > > > what order, should it matter?  Note that no rotation has been
> > > > introduced.
> > >
> > >    Order does matter. So scale then translate is different from
> > > translate then scale.  However since you are manipulating the
> > > transform on one element you can play some games by choosing to
> > > pre or post multiply the various transforms.  So if you always
> > > post multiply the translate transform (preconcatenate in JDK
> > > terms) then the translate part will just be 'added' to the
> > > existing matrix.  This is probably what you want for translate
> > > (from what I recall of how you handle things).
> > >
> > >
> > > >
> > > > Michael Bishop
> > > >
> > > > -----Original Message-----
> > > > From: Bishop, Michael W. CONTR J9C880
> > > > [mailto:Michael.Bishop@je.jfcom.mil]
> > > > Sent: Friday, June 02, 2006 12:32 PM
> > > > To: batik-users@xmlgraphics.apache.org
> > > > Subject: RE: Extracting information from a transformation matrix
> > > >
> > > > Good, good...OK, now I'm getting an understanding and figuring out
> > > what
> > > > needs to be done.  I assume the 6 values are represented as:
> > > >
> > > > a b c
> > > > d e f
> > > > 0 0 1 (implied, I know we don't really care about these values)
> > > >
> > > > According to my reference, to do a translation, I would have to
> > > multiply
> > > > in the following:
> > > >
> > > > 1 0 tx
> > > > 0 1 ty
> > > > 0 0 1 (again, implied)
> > > >
> > > > A scale:
> > > >
> > > > sx  0   0
> > > > 0   sy  0
> > > > 0   0   1 (implied for consistency's sake)
> > > >
> > > > A rotate:
> > > >
> > > > cos(t) -sin(t) 0
> > > > sin(t)  cos(t) 0
> > > > 0       0      1 (blah blah)
> > > >
> > > > To get this done in code:
> > > >
> > > > AffineTransform affineTransform = new AffineTransform(a, b, c, d,
> e,
> > > f);
> > > > SVGMatrix svgMatrix = new SVGOMMatrix(affineTransform);
> > > >
> > > > Besides the obvious way of calling getA(), getB(), etc., is there
> a
> > > way
> > > > to turn this into the proper attribute?
> > > >
> > > > transform="matrix(a, b, c, d, e, f)"
> > > >
> > > > Michael Bishop
> > > > -----Original Message-----
> > > > From: Andrew Plotkin [mailto:erkyrath@eblong.com]
> > > > Sent: Friday, June 02, 2006 12:20 PM
> > > > To: batik-users@xmlgraphics.apache.org
> > > > Subject: RE: Extracting information from a transformation matrix
> > > >
> > > > On Fri, 2 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:
> > > >
> > > > > 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.
> > > >
> > > > Ok.
> > > >
> > > > > 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?
> > > >
> > > > The SVGMatrix interface has a multiply(SVGMatrix) method.
> > > >
> > > > > Am I even on the right
> > > > > track here in that every operation I want to do is a new
> > > > multiplication?
> > > >
> > > > Yes, that's right.
> > > >
> > > > > After I rotate, if I want to translate again, do I have to
> "undo"
> > > > > anything or just multiply in a new (tx, ty)?
> > > >
> > > > Just multiply in a new one.
> > > >
> > > > --Z
> > > >
> > > > --
> > > > "And Aholibamah bare Jeush, and Jaalam, and Korah: these were the
> > > > borogoves..."
> > > > *
> > > > If the Bush administration hasn't subjected you to searches
> without 
> a
> > > > warrant,
> > > > it's for one reason: they don't feel like it. Not because you're
> > > > innocent.
> > > >
> > > > 
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: 
> batik-users-unsubscribe@xmlgraphics.apache.org
> > > > For additional commands, e-mail:
> > > batik-users-help@xmlgraphics.apache.org
> > > >
> > > > 
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: 
> batik-users-unsubscribe@xmlgraphics.apache.org
> > > > For additional commands, e-mail:
> > > batik-users-help@xmlgraphics.apache.org
> > > >
> > > > 
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: 
> batik-users-unsubscribe@xmlgraphics.apache.org
> > > > For additional commands, e-mail:
> > > batik-users-help@xmlgraphics.apache.org
> > > >
> > >
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> batik-users-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail: 
> batik-users-help@xmlgraphics.apache.org
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> batik-users-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail: 
> batik-users-help@xmlgraphics.apache.org
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> batik-users-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail: 
> batik-users-help@xmlgraphics.apache.org
> > >
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> > 
> > 
> > [attachment "winmail.dat" deleted by Thomas E. DeWeese/449433/EKC] 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Extracting information from a transformation matrix

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
OK, still working with this:
public static double[] getRotationAngle(AffineTransform inTransform) {
double tx = Math.atan2(inTransform.getShearX(),
inTransform.getScaleX());
double ty = Math.atan2(inTransform.getShearY(),
inTransform.getScaleY());
return new double[] { tx, ty };
}

public static void main(String[] args) {
AffineTransform affineTransform = new AffineTransform(1, 0, 0, 1, 0 ,0);
affineTransform.translate(10, 10);
affineTransform.scale(2, 2);
affineTransform.rotate(60);
double[] rotation =
AffineTransformUtil.getRotationAngle(affineTransform);
System.out.println("Rotation X: " + rotation[0]);
System.out.println("Rotation Y: " + rotation[1]);
}

I get unexpected results:

Rotation X: 2.831853071795865
Rotation Y: -2.831853071795865

I thought in this case with uniform scaling, I'd see 60.
If I have non-uniform scaling, how do I represent two different rotation
angles (x and y) in the transform attribute?  I don't understand how
rotate(t, cx, cy) breaks down into two values for rotate.

Michael Bishop

-----Original Message-----
From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com] 
Sent: Tuesday, June 06, 2006 8:39 PM
To: batik-users@xmlgraphics.apache.org
Cc: batik-users@xmlgraphics.apache.org
Subject: RE: Extracting information from a transformation matrix

Hi Michael,

"Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on

06/06/2006 08:28:55 PM:

> I'm confused...why do you call it "rotX"? 
> Isn't there only a single rotation angle?

   Not in the presence of shear.  Take the simple example of shearY:

+------+         +------+
|      |   ->   /       /
+------+       +-------+

   Note that a vector aligned with the x-axis will experience no
rotation.  However a vector aligned with the y-axis will experience
rotation.  This is why I called the above value 'rotX' it is
the rotation of a vector aligned on the x-axis.

   If you don't have shear or non-uniform scaling (which can make
some of a normal rotation "look like" shear), this BTW is your
case, then rotX and the similar 'rotY' calculation will match.



> ________________________________
> 
> From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> Sent: Tue 6/6/2006 7:46 PM
> To: batik-users@xmlgraphics.apache.org
> Cc: batik-users@xmlgraphics.apache.org
> Subject: RE: Extracting information from a transformation matrix
> 
> 
> 
> Hi Michael,
> 
> "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote
on
> 06/06/2006 01:39:25 PM:
> 
> > OK, I'm still struggling with this.  I'm trying to derive the
rotation
> > angle using the MatrixReverse function here:
> >
> > http://www.datenverdrahten.de/svglbc/?code=matrix_reverse&znr=on
> 
>    The code there doesn't look right to me.  In particular
> the calculation of konst1 is using tansky which is known to
> be zero.  I can't say this is 100% wrong (it may simply be
> to reduce 'unknowns').
> 
>    I would simply use:
> 
>         double rotX = Math.atan2(at.getShearX(), at.getScaleX());
> 
>    I'm fairly sure I have scaleX/shearX in the right place.
> 
> > Here's my test code:
> >
> > AffineTransform affineTransform = new AffineTransform(1, 0, 0, 1, 0,

0);
> >         affineTransform.translate(10, 10);
> >         affineTransform.scale(2, 2);
> >         System.out.println("Transform: " + affineTransform);
> >         System.out.println(
> >             "Angle: " +
> > AffineTransformUtil.getRotationAngle(affineTransform));
> >         affineTransform.rotate(60);
> >         System.out.println(
> >             "Angle: " +
> > AffineTransformUtil.getRotationAngle(affineTransform));
> >
> > The first time, the angle is reported as 0.0 which is correct.  The
> > second time, it's reported as 17.746...which is not.  I'm under the
> > impression it should be 60.  Anyone know how/why this (doesn't)
work?
> >
> > Michael Bishop
> >
> > -----Original Message-----
> > From: Bishop, Michael W. CONTR J9C880
> > [mailto:Michael.Bishop@je.jfcom.mil]
> > Sent: Monday, June 05, 2006 1:49 PM
> > To: batik-users@xmlgraphics.apache.org
> > Subject: RE: Extracting information from a transformation matrix
> >
> > Well I'm trying to integrate this side-by-side with what's already
> > there.  So when I print out the attributes, I print out the 
"transform"
> > attribute and I print out the dummy "matrix" attribute
> > (matrix="matrix(a, b, c, d, e, f)".
> >
> > The problem is that if I translate, things are fine.  If I scale, 
things
> > are fine.  If I scale, then translate, the "matrix" numbers don't 
match
> > the "transform".  In order to get them to match up, I've been 
"undoing"
> > everything:
> >
> > (For translation)
> >
> > transform.scale(1.0d / sx, 1.0d / sy);
> > transform.translate(tx, ty);
> > transform.scale(sx, sy);
> >
> > In order to make the numbers "match", I have to do all my
translations
> > "first" before scaling.  This kind of makes sense; when I use the
> > transform attribute, I always start from scratch: translate(tx, ty)
> > scale(sx, sy) rotate(t).
> >
> > I see the "preConcatenate" method here in the JDK, so let's go back
to
> > my use case.  I want to be able to translate, rotate, and scale in
any
> > order.  The user could draw an element, scale it by 150%, rotate it
60
> > degrees, drag it to the left, scale down to 50%, etc.
> >
> > I'm not sure how preconcatenating will help because I don't know
when 
to
> > do it and when not to.  I need to preconcatenate before any scaling
> > operations I think.  Rotate just makes it even tougher.
> >
> > Michael Bishop
> >
> > -----Original Message-----
> > From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> > Sent: Monday, June 05, 2006 1:38 PM
> > To: batik-users@xmlgraphics.apache.org
> > Cc: batik-users@xmlgraphics.apache.org
> > Subject: RE: Extracting information from a transformation matrix
> >
> > Hi Michael,
> >
> > "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>
wrote 
on
> >
> > 06/05/2006 12:12:15 PM:
> >
> > > Am I correct in assuming that:
> > >
> > > transform(tx, ty) scale(sx, sy)
> > >
> > > and
> > >
> > > sx  0  tx
> > > 0   sy ty
> > >
> > > will hold identical values for sx, sy, tx, and ty for any values
of
> > > those variables?  In other words, no matter how I scale/translate
or
> > in
> > > what order, should it matter?  Note that no rotation has been
> > > introduced.
> >
> >    Order does matter. So scale then translate is different from
> > translate then scale.  However since you are manipulating the
> > transform on one element you can play some games by choosing to
> > pre or post multiply the various transforms.  So if you always
> > post multiply the translate transform (preconcatenate in JDK
> > terms) then the translate part will just be 'added' to the
> > existing matrix.  This is probably what you want for translate
> > (from what I recall of how you handle things).
> >
> >
> > >
> > > Michael Bishop
> > >
> > > -----Original Message-----
> > > From: Bishop, Michael W. CONTR J9C880
> > > [mailto:Michael.Bishop@je.jfcom.mil]
> > > Sent: Friday, June 02, 2006 12:32 PM
> > > To: batik-users@xmlgraphics.apache.org
> > > Subject: RE: Extracting information from a transformation matrix
> > >
> > > Good, good...OK, now I'm getting an understanding and figuring out
> > what
> > > needs to be done.  I assume the 6 values are represented as:
> > >
> > > a b c
> > > d e f
> > > 0 0 1 (implied, I know we don't really care about these values)
> > >
> > > According to my reference, to do a translation, I would have to
> > multiply
> > > in the following:
> > >
> > > 1 0 tx
> > > 0 1 ty
> > > 0 0 1 (again, implied)
> > >
> > > A scale:
> > >
> > > sx  0   0
> > > 0   sy  0
> > > 0   0   1 (implied for consistency's sake)
> > >
> > > A rotate:
> > >
> > > cos(t) -sin(t) 0
> > > sin(t)  cos(t) 0
> > > 0       0      1 (blah blah)
> > >
> > > To get this done in code:
> > >
> > > AffineTransform affineTransform = new AffineTransform(a, b, c, d,
e,
> > f);
> > > SVGMatrix svgMatrix = new SVGOMMatrix(affineTransform);
> > >
> > > Besides the obvious way of calling getA(), getB(), etc., is there
a
> > way
> > > to turn this into the proper attribute?
> > >
> > > transform="matrix(a, b, c, d, e, f)"
> > >
> > > Michael Bishop
> > > -----Original Message-----
> > > From: Andrew Plotkin [mailto:erkyrath@eblong.com]
> > > Sent: Friday, June 02, 2006 12:20 PM
> > > To: batik-users@xmlgraphics.apache.org
> > > Subject: RE: Extracting information from a transformation matrix
> > >
> > > On Fri, 2 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:
> > >
> > > > 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.
> > >
> > > Ok.
> > >
> > > > 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?
> > >
> > > The SVGMatrix interface has a multiply(SVGMatrix) method.
> > >
> > > > Am I even on the right
> > > > track here in that every operation I want to do is a new
> > > multiplication?
> > >
> > > Yes, that's right.
> > >
> > > > After I rotate, if I want to translate again, do I have to
"undo"
> > > > anything or just multiply in a new (tx, ty)?
> > >
> > > Just multiply in a new one.
> > >
> > > --Z
> > >
> > > --
> > > "And Aholibamah bare Jeush, and Jaalam, and Korah: these were the
> > > borogoves..."
> > > *
> > > If the Bush administration hasn't subjected you to searches
without 
a
> > > warrant,
> > > it's for one reason: they don't feel like it. Not because you're
> > > innocent.
> > >
> > > 
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: 
batik-users-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail:
> > batik-users-help@xmlgraphics.apache.org
> > >
> > > 
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: 
batik-users-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail:
> > batik-users-help@xmlgraphics.apache.org
> > >
> > > 
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: 
batik-users-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail:
> > batik-users-help@xmlgraphics.apache.org
> > >
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: 
batik-users-help@xmlgraphics.apache.org
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: 
batik-users-help@xmlgraphics.apache.org
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: 
batik-users-help@xmlgraphics.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail:
batik-users-help@xmlgraphics.apache.org
> 
> 
> [attachment "winmail.dat" deleted by Thomas E. DeWeese/449433/EKC] 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail:
batik-users-help@xmlgraphics.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Extracting information from a transformation matrix

Posted by th...@kodak.com.
Hi Michael,

"Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on 
06/06/2006 08:28:55 PM:

> I'm confused...why do you call it "rotX"? 
> Isn't there only a single rotation angle?

   Not in the presence of shear.  Take the simple example of shearY:

+------+         +------+
|      |   ->   /       /
+------+       +-------+

   Note that a vector aligned with the x-axis will experience no
rotation.  However a vector aligned with the y-axis will experience
rotation.  This is why I called the above value 'rotX' it is
the rotation of a vector aligned on the x-axis.

   If you don't have shear or non-uniform scaling (which can make
some of a normal rotation "look like" shear), this BTW is your
case, then rotX and the similar 'rotY' calculation will match.



> ________________________________
> 
> From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> Sent: Tue 6/6/2006 7:46 PM
> To: batik-users@xmlgraphics.apache.org
> Cc: batik-users@xmlgraphics.apache.org
> Subject: RE: Extracting information from a transformation matrix
> 
> 
> 
> Hi Michael,
> 
> "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on
> 06/06/2006 01:39:25 PM:
> 
> > OK, I'm still struggling with this.  I'm trying to derive the rotation
> > angle using the MatrixReverse function here:
> >
> > http://www.datenverdrahten.de/svglbc/?code=matrix_reverse&znr=on
> 
>    The code there doesn't look right to me.  In particular
> the calculation of konst1 is using tansky which is known to
> be zero.  I can't say this is 100% wrong (it may simply be
> to reduce 'unknowns').
> 
>    I would simply use:
> 
>         double rotX = Math.atan2(at.getShearX(), at.getScaleX());
> 
>    I'm fairly sure I have scaleX/shearX in the right place.
> 
> > Here's my test code:
> >
> > AffineTransform affineTransform = new AffineTransform(1, 0, 0, 1, 0, 
0);
> >         affineTransform.translate(10, 10);
> >         affineTransform.scale(2, 2);
> >         System.out.println("Transform: " + affineTransform);
> >         System.out.println(
> >             "Angle: " +
> > AffineTransformUtil.getRotationAngle(affineTransform));
> >         affineTransform.rotate(60);
> >         System.out.println(
> >             "Angle: " +
> > AffineTransformUtil.getRotationAngle(affineTransform));
> >
> > The first time, the angle is reported as 0.0 which is correct.  The
> > second time, it's reported as 17.746...which is not.  I'm under the
> > impression it should be 60.  Anyone know how/why this (doesn't) work?
> >
> > Michael Bishop
> >
> > -----Original Message-----
> > From: Bishop, Michael W. CONTR J9C880
> > [mailto:Michael.Bishop@je.jfcom.mil]
> > Sent: Monday, June 05, 2006 1:49 PM
> > To: batik-users@xmlgraphics.apache.org
> > Subject: RE: Extracting information from a transformation matrix
> >
> > Well I'm trying to integrate this side-by-side with what's already
> > there.  So when I print out the attributes, I print out the 
"transform"
> > attribute and I print out the dummy "matrix" attribute
> > (matrix="matrix(a, b, c, d, e, f)".
> >
> > The problem is that if I translate, things are fine.  If I scale, 
things
> > are fine.  If I scale, then translate, the "matrix" numbers don't 
match
> > the "transform".  In order to get them to match up, I've been 
"undoing"
> > everything:
> >
> > (For translation)
> >
> > transform.scale(1.0d / sx, 1.0d / sy);
> > transform.translate(tx, ty);
> > transform.scale(sx, sy);
> >
> > In order to make the numbers "match", I have to do all my translations
> > "first" before scaling.  This kind of makes sense; when I use the
> > transform attribute, I always start from scratch: translate(tx, ty)
> > scale(sx, sy) rotate(t).
> >
> > I see the "preConcatenate" method here in the JDK, so let's go back to
> > my use case.  I want to be able to translate, rotate, and scale in any
> > order.  The user could draw an element, scale it by 150%, rotate it 60
> > degrees, drag it to the left, scale down to 50%, etc.
> >
> > I'm not sure how preconcatenating will help because I don't know when 
to
> > do it and when not to.  I need to preconcatenate before any scaling
> > operations I think.  Rotate just makes it even tougher.
> >
> > Michael Bishop
> >
> > -----Original Message-----
> > From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> > Sent: Monday, June 05, 2006 1:38 PM
> > To: batik-users@xmlgraphics.apache.org
> > Cc: batik-users@xmlgraphics.apache.org
> > Subject: RE: Extracting information from a transformation matrix
> >
> > Hi Michael,
> >
> > "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote 
on
> >
> > 06/05/2006 12:12:15 PM:
> >
> > > Am I correct in assuming that:
> > >
> > > transform(tx, ty) scale(sx, sy)
> > >
> > > and
> > >
> > > sx  0  tx
> > > 0   sy ty
> > >
> > > will hold identical values for sx, sy, tx, and ty for any values of
> > > those variables?  In other words, no matter how I scale/translate or
> > in
> > > what order, should it matter?  Note that no rotation has been
> > > introduced.
> >
> >    Order does matter. So scale then translate is different from
> > translate then scale.  However since you are manipulating the
> > transform on one element you can play some games by choosing to
> > pre or post multiply the various transforms.  So if you always
> > post multiply the translate transform (preconcatenate in JDK
> > terms) then the translate part will just be 'added' to the
> > existing matrix.  This is probably what you want for translate
> > (from what I recall of how you handle things).
> >
> >
> > >
> > > Michael Bishop
> > >
> > > -----Original Message-----
> > > From: Bishop, Michael W. CONTR J9C880
> > > [mailto:Michael.Bishop@je.jfcom.mil]
> > > Sent: Friday, June 02, 2006 12:32 PM
> > > To: batik-users@xmlgraphics.apache.org
> > > Subject: RE: Extracting information from a transformation matrix
> > >
> > > Good, good...OK, now I'm getting an understanding and figuring out
> > what
> > > needs to be done.  I assume the 6 values are represented as:
> > >
> > > a b c
> > > d e f
> > > 0 0 1 (implied, I know we don't really care about these values)
> > >
> > > According to my reference, to do a translation, I would have to
> > multiply
> > > in the following:
> > >
> > > 1 0 tx
> > > 0 1 ty
> > > 0 0 1 (again, implied)
> > >
> > > A scale:
> > >
> > > sx  0   0
> > > 0   sy  0
> > > 0   0   1 (implied for consistency's sake)
> > >
> > > A rotate:
> > >
> > > cos(t) -sin(t) 0
> > > sin(t)  cos(t) 0
> > > 0       0      1 (blah blah)
> > >
> > > To get this done in code:
> > >
> > > AffineTransform affineTransform = new AffineTransform(a, b, c, d, e,
> > f);
> > > SVGMatrix svgMatrix = new SVGOMMatrix(affineTransform);
> > >
> > > Besides the obvious way of calling getA(), getB(), etc., is there a
> > way
> > > to turn this into the proper attribute?
> > >
> > > transform="matrix(a, b, c, d, e, f)"
> > >
> > > Michael Bishop
> > > -----Original Message-----
> > > From: Andrew Plotkin [mailto:erkyrath@eblong.com]
> > > Sent: Friday, June 02, 2006 12:20 PM
> > > To: batik-users@xmlgraphics.apache.org
> > > Subject: RE: Extracting information from a transformation matrix
> > >
> > > On Fri, 2 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:
> > >
> > > > 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.
> > >
> > > Ok.
> > >
> > > > 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?
> > >
> > > The SVGMatrix interface has a multiply(SVGMatrix) method.
> > >
> > > > Am I even on the right
> > > > track here in that every operation I want to do is a new
> > > multiplication?
> > >
> > > Yes, that's right.
> > >
> > > > After I rotate, if I want to translate again, do I have to "undo"
> > > > anything or just multiply in a new (tx, ty)?
> > >
> > > Just multiply in a new one.
> > >
> > > --Z
> > >
> > > --
> > > "And Aholibamah bare Jeush, and Jaalam, and Korah: these were the
> > > borogoves..."
> > > *
> > > If the Bush administration hasn't subjected you to searches without 
a
> > > warrant,
> > > it's for one reason: they don't feel like it. Not because you're
> > > innocent.
> > >
> > > 
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: 
batik-users-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail:
> > batik-users-help@xmlgraphics.apache.org
> > >
> > > 
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: 
batik-users-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail:
> > batik-users-help@xmlgraphics.apache.org
> > >
> > > 
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: 
batik-users-unsubscribe@xmlgraphics.apache.org
> > > For additional commands, e-mail:
> > batik-users-help@xmlgraphics.apache.org
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: 
batik-users-help@xmlgraphics.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: 
batik-users-help@xmlgraphics.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: 
batik-users-help@xmlgraphics.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> 
> [attachment "winmail.dat" deleted by Thomas E. DeWeese/449433/EKC] 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Extracting information from a transformation matrix

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
I'm confused...why do you call it "rotX"?  Isn't there only a single rotation angle?
 
Michael Bishop

________________________________

From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
Sent: Tue 6/6/2006 7:46 PM
To: batik-users@xmlgraphics.apache.org
Cc: batik-users@xmlgraphics.apache.org
Subject: RE: Extracting information from a transformation matrix



Hi Michael,

"Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on
06/06/2006 01:39:25 PM:

> OK, I'm still struggling with this.  I'm trying to derive the rotation
> angle using the MatrixReverse function here:
>
> http://www.datenverdrahten.de/svglbc/?code=matrix_reverse&znr=on

   The code there doesn't look right to me.  In particular
the calculation of konst1 is using tansky which is known to
be zero.  I can't say this is 100% wrong (it may simply be
to reduce 'unknowns').

   I would simply use:

        double rotX = Math.atan2(at.getShearX(), at.getScaleX());

   I'm fairly sure I have scaleX/shearX in the right place.

> Here's my test code:
>
> AffineTransform affineTransform = new AffineTransform(1, 0, 0, 1, 0, 0);
>         affineTransform.translate(10, 10);
>         affineTransform.scale(2, 2);
>         System.out.println("Transform: " + affineTransform);
>         System.out.println(
>             "Angle: " +
> AffineTransformUtil.getRotationAngle(affineTransform));
>         affineTransform.rotate(60);
>         System.out.println(
>             "Angle: " +
> AffineTransformUtil.getRotationAngle(affineTransform));
>
> The first time, the angle is reported as 0.0 which is correct.  The
> second time, it's reported as 17.746...which is not.  I'm under the
> impression it should be 60.  Anyone know how/why this (doesn't) work?
>
> Michael Bishop
>
> -----Original Message-----
> From: Bishop, Michael W. CONTR J9C880
> [mailto:Michael.Bishop@je.jfcom.mil]
> Sent: Monday, June 05, 2006 1:49 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: RE: Extracting information from a transformation matrix
>
> Well I'm trying to integrate this side-by-side with what's already
> there.  So when I print out the attributes, I print out the "transform"
> attribute and I print out the dummy "matrix" attribute
> (matrix="matrix(a, b, c, d, e, f)".
>
> The problem is that if I translate, things are fine.  If I scale, things
> are fine.  If I scale, then translate, the "matrix" numbers don't match
> the "transform".  In order to get them to match up, I've been "undoing"
> everything:
>
> (For translation)
>
> transform.scale(1.0d / sx, 1.0d / sy);
> transform.translate(tx, ty);
> transform.scale(sx, sy);
>
> In order to make the numbers "match", I have to do all my translations
> "first" before scaling.  This kind of makes sense; when I use the
> transform attribute, I always start from scratch: translate(tx, ty)
> scale(sx, sy) rotate(t).
>
> I see the "preConcatenate" method here in the JDK, so let's go back to
> my use case.  I want to be able to translate, rotate, and scale in any
> order.  The user could draw an element, scale it by 150%, rotate it 60
> degrees, drag it to the left, scale down to 50%, etc.
>
> I'm not sure how preconcatenating will help because I don't know when to
> do it and when not to.  I need to preconcatenate before any scaling
> operations I think.  Rotate just makes it even tougher.
>
> Michael Bishop
>
> -----Original Message-----
> From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> Sent: Monday, June 05, 2006 1:38 PM
> To: batik-users@xmlgraphics.apache.org
> Cc: batik-users@xmlgraphics.apache.org
> Subject: RE: Extracting information from a transformation matrix
>
> Hi Michael,
>
> "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on
>
> 06/05/2006 12:12:15 PM:
>
> > Am I correct in assuming that:
> >
> > transform(tx, ty) scale(sx, sy)
> >
> > and
> >
> > sx  0  tx
> > 0   sy ty
> >
> > will hold identical values for sx, sy, tx, and ty for any values of
> > those variables?  In other words, no matter how I scale/translate or
> in
> > what order, should it matter?  Note that no rotation has been
> > introduced.
>
>    Order does matter. So scale then translate is different from
> translate then scale.  However since you are manipulating the
> transform on one element you can play some games by choosing to
> pre or post multiply the various transforms.  So if you always
> post multiply the translate transform (preconcatenate in JDK
> terms) then the translate part will just be 'added' to the
> existing matrix.  This is probably what you want for translate
> (from what I recall of how you handle things).
>
>
> >
> > Michael Bishop
> >
> > -----Original Message-----
> > From: Bishop, Michael W. CONTR J9C880
> > [mailto:Michael.Bishop@je.jfcom.mil]
> > Sent: Friday, June 02, 2006 12:32 PM
> > To: batik-users@xmlgraphics.apache.org
> > Subject: RE: Extracting information from a transformation matrix
> >
> > Good, good...OK, now I'm getting an understanding and figuring out
> what
> > needs to be done.  I assume the 6 values are represented as:
> >
> > a b c
> > d e f
> > 0 0 1 (implied, I know we don't really care about these values)
> >
> > According to my reference, to do a translation, I would have to
> multiply
> > in the following:
> >
> > 1 0 tx
> > 0 1 ty
> > 0 0 1 (again, implied)
> >
> > A scale:
> >
> > sx  0   0
> > 0   sy  0
> > 0   0   1 (implied for consistency's sake)
> >
> > A rotate:
> >
> > cos(t) -sin(t) 0
> > sin(t)  cos(t) 0
> > 0       0      1 (blah blah)
> >
> > To get this done in code:
> >
> > AffineTransform affineTransform = new AffineTransform(a, b, c, d, e,
> f);
> > SVGMatrix svgMatrix = new SVGOMMatrix(affineTransform);
> >
> > Besides the obvious way of calling getA(), getB(), etc., is there a
> way
> > to turn this into the proper attribute?
> >
> > transform="matrix(a, b, c, d, e, f)"
> >
> > Michael Bishop
> > -----Original Message-----
> > From: Andrew Plotkin [mailto:erkyrath@eblong.com]
> > Sent: Friday, June 02, 2006 12:20 PM
> > To: batik-users@xmlgraphics.apache.org
> > Subject: RE: Extracting information from a transformation matrix
> >
> > On Fri, 2 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:
> >
> > > 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.
> >
> > Ok.
> >
> > > 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?
> >
> > The SVGMatrix interface has a multiply(SVGMatrix) method.
> >
> > > Am I even on the right
> > > track here in that every operation I want to do is a new
> > multiplication?
> >
> > Yes, that's right.
> >
> > > After I rotate, if I want to translate again, do I have to "undo"
> > > anything or just multiply in a new (tx, ty)?
> >
> > Just multiply in a new one.
> >
> > --Z
> >
> > --
> > "And Aholibamah bare Jeush, and Jaalam, and Korah: these were the
> > borogoves..."
> > *
> > If the Bush administration hasn't subjected you to searches without a
> > warrant,
> > it's for one reason: they don't feel like it. Not because you're
> > innocent.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org



RE: Extracting information from a transformation matrix

Posted by th...@kodak.com.
Hi Michael,

"Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on 
06/06/2006 01:39:25 PM:

> OK, I'm still struggling with this.  I'm trying to derive the rotation
> angle using the MatrixReverse function here:
> 
> http://www.datenverdrahten.de/svglbc/?code=matrix_reverse&znr=on

   The code there doesn't look right to me.  In particular
the calculation of konst1 is using tansky which is known to
be zero.  I can't say this is 100% wrong (it may simply be
to reduce 'unknowns').

   I would simply use:

        double rotX = Math.atan2(at.getShearX(), at.getScaleX());

   I'm fairly sure I have scaleX/shearX in the right place.

> Here's my test code:
> 
> AffineTransform affineTransform = new AffineTransform(1, 0, 0, 1, 0, 0);
>         affineTransform.translate(10, 10);
>         affineTransform.scale(2, 2);
>         System.out.println("Transform: " + affineTransform);
>         System.out.println(
>             "Angle: " +
> AffineTransformUtil.getRotationAngle(affineTransform));
>         affineTransform.rotate(60);
>         System.out.println(
>             "Angle: " +
> AffineTransformUtil.getRotationAngle(affineTransform));
> 
> The first time, the angle is reported as 0.0 which is correct.  The
> second time, it's reported as 17.746...which is not.  I'm under the
> impression it should be 60.  Anyone know how/why this (doesn't) work?
> 
> Michael Bishop
> 
> -----Original Message-----
> From: Bishop, Michael W. CONTR J9C880
> [mailto:Michael.Bishop@je.jfcom.mil] 
> Sent: Monday, June 05, 2006 1:49 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: RE: Extracting information from a transformation matrix
> 
> Well I'm trying to integrate this side-by-side with what's already
> there.  So when I print out the attributes, I print out the "transform"
> attribute and I print out the dummy "matrix" attribute
> (matrix="matrix(a, b, c, d, e, f)".
> 
> The problem is that if I translate, things are fine.  If I scale, things
> are fine.  If I scale, then translate, the "matrix" numbers don't match
> the "transform".  In order to get them to match up, I've been "undoing"
> everything:
> 
> (For translation)
> 
> transform.scale(1.0d / sx, 1.0d / sy);
> transform.translate(tx, ty);
> transform.scale(sx, sy);
> 
> In order to make the numbers "match", I have to do all my translations
> "first" before scaling.  This kind of makes sense; when I use the
> transform attribute, I always start from scratch: translate(tx, ty)
> scale(sx, sy) rotate(t).
> 
> I see the "preConcatenate" method here in the JDK, so let's go back to
> my use case.  I want to be able to translate, rotate, and scale in any
> order.  The user could draw an element, scale it by 150%, rotate it 60
> degrees, drag it to the left, scale down to 50%, etc.
> 
> I'm not sure how preconcatenating will help because I don't know when to
> do it and when not to.  I need to preconcatenate before any scaling
> operations I think.  Rotate just makes it even tougher.
> 
> Michael Bishop
> 
> -----Original Message-----
> From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com] 
> Sent: Monday, June 05, 2006 1:38 PM
> To: batik-users@xmlgraphics.apache.org
> Cc: batik-users@xmlgraphics.apache.org
> Subject: RE: Extracting information from a transformation matrix
> 
> Hi Michael,
> 
> "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on
> 
> 06/05/2006 12:12:15 PM:
> 
> > Am I correct in assuming that:
> > 
> > transform(tx, ty) scale(sx, sy)
> > 
> > and
> > 
> > sx  0  tx
> > 0   sy ty
> > 
> > will hold identical values for sx, sy, tx, and ty for any values of
> > those variables?  In other words, no matter how I scale/translate or
> in
> > what order, should it matter?  Note that no rotation has been
> > introduced.
> 
>    Order does matter. So scale then translate is different from
> translate then scale.  However since you are manipulating the
> transform on one element you can play some games by choosing to
> pre or post multiply the various transforms.  So if you always
> post multiply the translate transform (preconcatenate in JDK
> terms) then the translate part will just be 'added' to the 
> existing matrix.  This is probably what you want for translate
> (from what I recall of how you handle things). 
> 
> 
> > 
> > Michael Bishop
> > 
> > -----Original Message-----
> > From: Bishop, Michael W. CONTR J9C880
> > [mailto:Michael.Bishop@je.jfcom.mil] 
> > Sent: Friday, June 02, 2006 12:32 PM
> > To: batik-users@xmlgraphics.apache.org
> > Subject: RE: Extracting information from a transformation matrix
> > 
> > Good, good...OK, now I'm getting an understanding and figuring out
> what
> > needs to be done.  I assume the 6 values are represented as:
> > 
> > a b c
> > d e f
> > 0 0 1 (implied, I know we don't really care about these values)
> > 
> > According to my reference, to do a translation, I would have to
> multiply
> > in the following:
> > 
> > 1 0 tx
> > 0 1 ty
> > 0 0 1 (again, implied)
> > 
> > A scale:
> > 
> > sx  0   0
> > 0   sy  0
> > 0   0   1 (implied for consistency's sake)
> > 
> > A rotate:
> > 
> > cos(t) -sin(t) 0
> > sin(t)  cos(t) 0
> > 0       0      1 (blah blah)
> > 
> > To get this done in code:
> > 
> > AffineTransform affineTransform = new AffineTransform(a, b, c, d, e,
> f);
> > SVGMatrix svgMatrix = new SVGOMMatrix(affineTransform);
> > 
> > Besides the obvious way of calling getA(), getB(), etc., is there a
> way
> > to turn this into the proper attribute?
> > 
> > transform="matrix(a, b, c, d, e, f)" 
> > 
> > Michael Bishop
> > -----Original Message-----
> > From: Andrew Plotkin [mailto:erkyrath@eblong.com] 
> > Sent: Friday, June 02, 2006 12:20 PM
> > To: batik-users@xmlgraphics.apache.org
> > Subject: RE: Extracting information from a transformation matrix
> > 
> > On Fri, 2 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:
> > 
> > > 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.
> > 
> > Ok.
> > 
> > > 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?
> > 
> > The SVGMatrix interface has a multiply(SVGMatrix) method.
> > 
> > > Am I even on the right
> > > track here in that every operation I want to do is a new
> > multiplication?
> > 
> > Yes, that's right.
> > 
> > > After I rotate, if I want to translate again, do I have to "undo"
> > > anything or just multiply in a new (tx, ty)?
> > 
> > Just multiply in a new one.
> > 
> > --Z
> > 
> > -- 
> > "And Aholibamah bare Jeush, and Jaalam, and Korah: these were the
> > borogoves..."
> > *
> > If the Bush administration hasn't subjected you to searches without a
> > warrant,
> > it's for one reason: they don't feel like it. Not because you're
> > innocent.
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Extracting information from a transformation matrix

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
OK, I'm still struggling with this.  I'm trying to derive the rotation
angle using the MatrixReverse function here:

http://www.datenverdrahten.de/svglbc/?code=matrix_reverse&znr=on

Here's my test code:

AffineTransform affineTransform = new AffineTransform(1, 0, 0, 1, 0, 0);
        affineTransform.translate(10, 10);
        affineTransform.scale(2, 2);
        System.out.println("Transform: " + affineTransform);
        System.out.println(
            "Angle: " +
AffineTransformUtil.getRotationAngle(affineTransform));
        affineTransform.rotate(60);
        System.out.println(
            "Angle: " +
AffineTransformUtil.getRotationAngle(affineTransform));

The first time, the angle is reported as 0.0 which is correct.  The
second time, it's reported as 17.746...which is not.  I'm under the
impression it should be 60.  Anyone know how/why this (doesn't) work?

Michael Bishop

-----Original Message-----
From: Bishop, Michael W. CONTR J9C880
[mailto:Michael.Bishop@je.jfcom.mil] 
Sent: Monday, June 05, 2006 1:49 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Extracting information from a transformation matrix

Well I'm trying to integrate this side-by-side with what's already
there.  So when I print out the attributes, I print out the "transform"
attribute and I print out the dummy "matrix" attribute
(matrix="matrix(a, b, c, d, e, f)".

The problem is that if I translate, things are fine.  If I scale, things
are fine.  If I scale, then translate, the "matrix" numbers don't match
the "transform".  In order to get them to match up, I've been "undoing"
everything:

(For translation)

transform.scale(1.0d / sx, 1.0d / sy);
transform.translate(tx, ty);
transform.scale(sx, sy);

In order to make the numbers "match", I have to do all my translations
"first" before scaling.  This kind of makes sense; when I use the
transform attribute, I always start from scratch: translate(tx, ty)
scale(sx, sy) rotate(t).

I see the "preConcatenate" method here in the JDK, so let's go back to
my use case.  I want to be able to translate, rotate, and scale in any
order.  The user could draw an element, scale it by 150%, rotate it 60
degrees, drag it to the left, scale down to 50%, etc.

I'm not sure how preconcatenating will help because I don't know when to
do it and when not to.  I need to preconcatenate before any scaling
operations I think.  Rotate just makes it even tougher.

Michael Bishop

-----Original Message-----
From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com] 
Sent: Monday, June 05, 2006 1:38 PM
To: batik-users@xmlgraphics.apache.org
Cc: batik-users@xmlgraphics.apache.org
Subject: RE: Extracting information from a transformation matrix

Hi Michael,

"Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on

06/05/2006 12:12:15 PM:

> Am I correct in assuming that:
> 
> transform(tx, ty) scale(sx, sy)
> 
> and
> 
> sx  0  tx
> 0   sy ty
> 
> will hold identical values for sx, sy, tx, and ty for any values of
> those variables?  In other words, no matter how I scale/translate or
in
> what order, should it matter?  Note that no rotation has been
> introduced.

   Order does matter. So scale then translate is different from
translate then scale.  However since you are manipulating the
transform on one element you can play some games by choosing to
pre or post multiply the various transforms.  So if you always
post multiply the translate transform (preconcatenate in JDK
terms) then the translate part will just be 'added' to the 
existing matrix.  This is probably what you want for translate
(from what I recall of how you handle things). 


> 
> Michael Bishop
> 
> -----Original Message-----
> From: Bishop, Michael W. CONTR J9C880
> [mailto:Michael.Bishop@je.jfcom.mil] 
> Sent: Friday, June 02, 2006 12:32 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: RE: Extracting information from a transformation matrix
> 
> Good, good...OK, now I'm getting an understanding and figuring out
what
> needs to be done.  I assume the 6 values are represented as:
> 
> a b c
> d e f
> 0 0 1 (implied, I know we don't really care about these values)
> 
> According to my reference, to do a translation, I would have to
multiply
> in the following:
> 
> 1 0 tx
> 0 1 ty
> 0 0 1 (again, implied)
> 
> A scale:
> 
> sx  0   0
> 0   sy  0
> 0   0   1 (implied for consistency's sake)
> 
> A rotate:
> 
> cos(t) -sin(t) 0
> sin(t)  cos(t) 0
> 0       0      1 (blah blah)
> 
> To get this done in code:
> 
> AffineTransform affineTransform = new AffineTransform(a, b, c, d, e,
f);
> SVGMatrix svgMatrix = new SVGOMMatrix(affineTransform);
> 
> Besides the obvious way of calling getA(), getB(), etc., is there a
way
> to turn this into the proper attribute?
> 
> transform="matrix(a, b, c, d, e, f)" 
> 
> Michael Bishop
> -----Original Message-----
> From: Andrew Plotkin [mailto:erkyrath@eblong.com] 
> Sent: Friday, June 02, 2006 12:20 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: RE: Extracting information from a transformation matrix
> 
> On Fri, 2 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:
> 
> > 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.
> 
> Ok.
> 
> > 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?
> 
> The SVGMatrix interface has a multiply(SVGMatrix) method.
> 
> > Am I even on the right
> > track here in that every operation I want to do is a new
> multiplication?
> 
> Yes, that's right.
> 
> > After I rotate, if I want to translate again, do I have to "undo"
> > anything or just multiply in a new (tx, ty)?
> 
> Just multiply in a new one.
> 
> --Z
> 
> -- 
> "And Aholibamah bare Jeush, and Jaalam, and Korah: these were the
> borogoves..."
> *
> If the Bush administration hasn't subjected you to searches without a
> warrant,
> it's for one reason: they don't feel like it. Not because you're
> innocent.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail:
batik-users-help@xmlgraphics.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail:
batik-users-help@xmlgraphics.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail:
batik-users-help@xmlgraphics.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Extracting information from a transformation matrix

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
Well I'm trying to integrate this side-by-side with what's already
there.  So when I print out the attributes, I print out the "transform"
attribute and I print out the dummy "matrix" attribute
(matrix="matrix(a, b, c, d, e, f)".

The problem is that if I translate, things are fine.  If I scale, things
are fine.  If I scale, then translate, the "matrix" numbers don't match
the "transform".  In order to get them to match up, I've been "undoing"
everything:

(For translation)

transform.scale(1.0d / sx, 1.0d / sy);
transform.translate(tx, ty);
transform.scale(sx, sy);

In order to make the numbers "match", I have to do all my translations
"first" before scaling.  This kind of makes sense; when I use the
transform attribute, I always start from scratch: translate(tx, ty)
scale(sx, sy) rotate(t).

I see the "preConcatenate" method here in the JDK, so let's go back to
my use case.  I want to be able to translate, rotate, and scale in any
order.  The user could draw an element, scale it by 150%, rotate it 60
degrees, drag it to the left, scale down to 50%, etc.

I'm not sure how preconcatenating will help because I don't know when to
do it and when not to.  I need to preconcatenate before any scaling
operations I think.  Rotate just makes it even tougher.

Michael Bishop

-----Original Message-----
From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com] 
Sent: Monday, June 05, 2006 1:38 PM
To: batik-users@xmlgraphics.apache.org
Cc: batik-users@xmlgraphics.apache.org
Subject: RE: Extracting information from a transformation matrix

Hi Michael,

"Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on

06/05/2006 12:12:15 PM:

> Am I correct in assuming that:
> 
> transform(tx, ty) scale(sx, sy)
> 
> and
> 
> sx  0  tx
> 0   sy ty
> 
> will hold identical values for sx, sy, tx, and ty for any values of
> those variables?  In other words, no matter how I scale/translate or
in
> what order, should it matter?  Note that no rotation has been
> introduced.

   Order does matter. So scale then translate is different from
translate then scale.  However since you are manipulating the
transform on one element you can play some games by choosing to
pre or post multiply the various transforms.  So if you always
post multiply the translate transform (preconcatenate in JDK
terms) then the translate part will just be 'added' to the 
existing matrix.  This is probably what you want for translate
(from what I recall of how you handle things). 


> 
> Michael Bishop
> 
> -----Original Message-----
> From: Bishop, Michael W. CONTR J9C880
> [mailto:Michael.Bishop@je.jfcom.mil] 
> Sent: Friday, June 02, 2006 12:32 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: RE: Extracting information from a transformation matrix
> 
> Good, good...OK, now I'm getting an understanding and figuring out
what
> needs to be done.  I assume the 6 values are represented as:
> 
> a b c
> d e f
> 0 0 1 (implied, I know we don't really care about these values)
> 
> According to my reference, to do a translation, I would have to
multiply
> in the following:
> 
> 1 0 tx
> 0 1 ty
> 0 0 1 (again, implied)
> 
> A scale:
> 
> sx  0   0
> 0   sy  0
> 0   0   1 (implied for consistency's sake)
> 
> A rotate:
> 
> cos(t) -sin(t) 0
> sin(t)  cos(t) 0
> 0       0      1 (blah blah)
> 
> To get this done in code:
> 
> AffineTransform affineTransform = new AffineTransform(a, b, c, d, e,
f);
> SVGMatrix svgMatrix = new SVGOMMatrix(affineTransform);
> 
> Besides the obvious way of calling getA(), getB(), etc., is there a
way
> to turn this into the proper attribute?
> 
> transform="matrix(a, b, c, d, e, f)" 
> 
> Michael Bishop
> -----Original Message-----
> From: Andrew Plotkin [mailto:erkyrath@eblong.com] 
> Sent: Friday, June 02, 2006 12:20 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: RE: Extracting information from a transformation matrix
> 
> On Fri, 2 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:
> 
> > 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.
> 
> Ok.
> 
> > 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?
> 
> The SVGMatrix interface has a multiply(SVGMatrix) method.
> 
> > Am I even on the right
> > track here in that every operation I want to do is a new
> multiplication?
> 
> Yes, that's right.
> 
> > After I rotate, if I want to translate again, do I have to "undo"
> > anything or just multiply in a new (tx, ty)?
> 
> Just multiply in a new one.
> 
> --Z
> 
> -- 
> "And Aholibamah bare Jeush, and Jaalam, and Korah: these were the
> borogoves..."
> *
> If the Bush administration hasn't subjected you to searches without a
> warrant,
> it's for one reason: they don't feel like it. Not because you're
> innocent.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail:
batik-users-help@xmlgraphics.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail:
batik-users-help@xmlgraphics.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail:
batik-users-help@xmlgraphics.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Extracting information from a transformation matrix

Posted by th...@kodak.com.
Hi Michael,

"Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on 
06/05/2006 12:12:15 PM:

> Am I correct in assuming that:
> 
> transform(tx, ty) scale(sx, sy)
> 
> and
> 
> sx  0  tx
> 0   sy ty
> 
> will hold identical values for sx, sy, tx, and ty for any values of
> those variables?  In other words, no matter how I scale/translate or in
> what order, should it matter?  Note that no rotation has been
> introduced.

   Order does matter. So scale then translate is different from
translate then scale.  However since you are manipulating the
transform on one element you can play some games by choosing to
pre or post multiply the various transforms.  So if you always
post multiply the translate transform (preconcatenate in JDK
terms) then the translate part will just be 'added' to the 
existing matrix.  This is probably what you want for translate
(from what I recall of how you handle things). 


> 
> Michael Bishop
> 
> -----Original Message-----
> From: Bishop, Michael W. CONTR J9C880
> [mailto:Michael.Bishop@je.jfcom.mil] 
> Sent: Friday, June 02, 2006 12:32 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: RE: Extracting information from a transformation matrix
> 
> Good, good...OK, now I'm getting an understanding and figuring out what
> needs to be done.  I assume the 6 values are represented as:
> 
> a b c
> d e f
> 0 0 1 (implied, I know we don't really care about these values)
> 
> According to my reference, to do a translation, I would have to multiply
> in the following:
> 
> 1 0 tx
> 0 1 ty
> 0 0 1 (again, implied)
> 
> A scale:
> 
> sx  0   0
> 0   sy  0
> 0   0   1 (implied for consistency's sake)
> 
> A rotate:
> 
> cos(t) -sin(t) 0
> sin(t)  cos(t) 0
> 0       0      1 (blah blah)
> 
> To get this done in code:
> 
> AffineTransform affineTransform = new AffineTransform(a, b, c, d, e, f);
> SVGMatrix svgMatrix = new SVGOMMatrix(affineTransform);
> 
> Besides the obvious way of calling getA(), getB(), etc., is there a way
> to turn this into the proper attribute?
> 
> transform="matrix(a, b, c, d, e, f)" 
> 
> Michael Bishop
> -----Original Message-----
> From: Andrew Plotkin [mailto:erkyrath@eblong.com] 
> Sent: Friday, June 02, 2006 12:20 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: RE: Extracting information from a transformation matrix
> 
> On Fri, 2 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:
> 
> > 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.
> 
> Ok.
> 
> > 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?
> 
> The SVGMatrix interface has a multiply(SVGMatrix) method.
> 
> > Am I even on the right
> > track here in that every operation I want to do is a new
> multiplication?
> 
> Yes, that's right.
> 
> > After I rotate, if I want to translate again, do I have to "undo"
> > anything or just multiply in a new (tx, ty)?
> 
> Just multiply in a new one.
> 
> --Z
> 
> -- 
> "And Aholibamah bare Jeush, and Jaalam, and Korah: these were the
> borogoves..."
> *
> If the Bush administration hasn't subjected you to searches without a
> warrant,
> it's for one reason: they don't feel like it. Not because you're
> innocent.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Extracting information from a transformation matrix

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
Am I correct in assuming that:

transform(tx, ty) scale(sx, sy)

and

sx  0  tx
0   sy ty

will hold identical values for sx, sy, tx, and ty for any values of
those variables?  In other words, no matter how I scale/translate or in
what order, should it matter?  Note that no rotation has been
introduced.

Michael Bishop

-----Original Message-----
From: Bishop, Michael W. CONTR J9C880
[mailto:Michael.Bishop@je.jfcom.mil] 
Sent: Friday, June 02, 2006 12:32 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Extracting information from a transformation matrix

Good, good...OK, now I'm getting an understanding and figuring out what
needs to be done.  I assume the 6 values are represented as:

a b c
d e f
0 0 1 (implied, I know we don't really care about these values)

According to my reference, to do a translation, I would have to multiply
in the following:

1 0 tx
0 1 ty
0 0 1 (again, implied)

A scale:

sx  0   0
0   sy  0
0   0   1 (implied for consistency's sake)

A rotate:

cos(t) -sin(t) 0
sin(t)  cos(t) 0
0       0      1 (blah blah)

To get this done in code:

AffineTransform affineTransform = new AffineTransform(a, b, c, d, e, f);
SVGMatrix svgMatrix = new SVGOMMatrix(affineTransform);

Besides the obvious way of calling getA(), getB(), etc., is there a way
to turn this into the proper attribute?

transform="matrix(a, b, c, d, e, f)" 

Michael Bishop
-----Original Message-----
From: Andrew Plotkin [mailto:erkyrath@eblong.com] 
Sent: Friday, June 02, 2006 12:20 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Extracting information from a transformation matrix

On Fri, 2 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:

> 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.

Ok.

> 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?

The SVGMatrix interface has a multiply(SVGMatrix) method.

> Am I even on the right
> track here in that every operation I want to do is a new
multiplication?

Yes, that's right.

> After I rotate, if I want to translate again, do I have to "undo"
> anything or just multiply in a new (tx, ty)?

Just multiply in a new one.

--Z

-- 
"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the
borogoves..."
*
If the Bush administration hasn't subjected you to searches without a
warrant,
it's for one reason: they don't feel like it. Not because you're
innocent.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Extracting information from a transformation matrix

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
Good, good...OK, now I'm getting an understanding and figuring out what
needs to be done.  I assume the 6 values are represented as:

a b c
d e f
0 0 1 (implied, I know we don't really care about these values)

According to my reference, to do a translation, I would have to multiply
in the following:

1 0 tx
0 1 ty
0 0 1 (again, implied)

A scale:

sx  0   0
0   sy  0
0   0   1 (implied for consistency's sake)

A rotate:

cos(t) -sin(t) 0
sin(t)  cos(t) 0
0       0      1 (blah blah)

To get this done in code:

AffineTransform affineTransform = new AffineTransform(a, b, c, d, e, f);
SVGMatrix svgMatrix = new SVGOMMatrix(affineTransform);

Besides the obvious way of calling getA(), getB(), etc., is there a way
to turn this into the proper attribute?

transform="matrix(a, b, c, d, e, f)" 

Michael Bishop
-----Original Message-----
From: Andrew Plotkin [mailto:erkyrath@eblong.com] 
Sent: Friday, June 02, 2006 12:20 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Extracting information from a transformation matrix

On Fri, 2 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:

> 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.

Ok.

> 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?

The SVGMatrix interface has a multiply(SVGMatrix) method.

> Am I even on the right
> track here in that every operation I want to do is a new
multiplication?

Yes, that's right.

> After I rotate, if I want to translate again, do I have to "undo"
> anything or just multiply in a new (tx, ty)?

Just multiply in a new one.

--Z

-- 
"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the
borogoves..."
*
If the Bush administration hasn't subjected you to searches without a
warrant,
it's for one reason: they don't feel like it. Not because you're
innocent.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Extracting information from a transformation matrix

Posted by Andrew Plotkin <er...@eblong.com>.
On Fri, 2 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:

> 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.

Ok.

> 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?

The SVGMatrix interface has a multiply(SVGMatrix) method.

> Am I even on the right
> track here in that every operation I want to do is a new multiplication?

Yes, that's right.

> After I rotate, if I want to translate again, do I have to "undo"
> anything or just multiply in a new (tx, ty)?

Just multiply in a new one.

--Z

-- 
"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
*
If the Bush administration hasn't subjected you to searches without a warrant,
it's for one reason: they don't feel like it. Not because you're innocent.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Extracting information from a transformation matrix

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
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 <er...@eblong.com> wrote on 06/01/2006 11:47:12 PM:

> On Thu, 1 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:
> 
> > Ouch.  Major headache.
> >
> > 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
your 

> 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
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Extracting information from a transformation matrix

Posted by th...@kodak.com.
Hi Michael, Andrew,

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

> On Thu, 1 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:
> 
> > Ouch.  Major headache.
> >
> > 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 your 

> 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
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Extracting information from a transformation matrix

Posted by Andrew Plotkin <er...@eblong.com>.
On Thu, 1 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:

> Ouch.  Major headache.
>
> 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 your 
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.

--Z

-- 
"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
*
If the Bush administration hasn't subjected you to searches without a warrant,
it's for one reason: they don't feel like it. Not because you're innocent.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Extracting information from a transformation matrix

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
Ouch.  Major headache.
 
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.
 
Say the user drags and drops the element again.  I can't just manipulate the translation because I've rotated and scaled around a center point.
 
At this point, I need to "reverse" the rotation first, extracting it from the transform.  Then I need to "reverse" the scale as well, extracting it.  What I'm left with is the amount I've translated (dragged and dropped) by, correct?
 
Another question, in Java how can I change a transform attribute into the 6 matrix values?  In your example, do you compensate for the fact the element is rotated around the center point?  What about scaling around a center point?  The amount that scaling effects is -centerX * (scaleX - 1.0);  I'd have to subtract that from the original translation as well to find out exactly how much I dragged and dropped...right?
 
Michael Bishop

________________________________

From: Andrew Plotkin [mailto:erkyrath@eblong.com]
Sent: Thu 6/1/2006 2:10 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Extracting information from a transformation matrix



On Thu, 1 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:

> All right, this is great information.  I need to sit down and work
> through it with my SVG Matrix algebra examples in front of me.  I do
> have a couple of questions:
>
> - Assuming I already have the center poitns, I could derive all the
> values I wanted right?  The rotate(t, x, y) command is a shortcut for
> translation if I remember right.  It's short for translate(x,y)
> rotate(t) translate(-x,-y) isn't it?

Yes.

If you already know the cx and cy, you can work everything out, yes. Let
me take a look at my example...

<ellipse id="sall" transform="translate(4,4) scale(3) rotate(60,1,2)"
    rx="1" ry="2" />

    cx,cy = (1,2)   (we know this in advance)
    translate=(10.69615268,4.401909828)
    scale=3
    rotate=60

The scale and rotate values are correct. We just need to fix the
translation.

(This is where we start applying some Experimental Mathematics. Which is
to say, I'm going to rearrange the equations until the right answers come
out. :)

Scale and rotate the cx,cy vector by the values we've worked out. (We're
converting degrees to radians now.

   newcx = scale * (cx*cos(rotate*pi/180) + cy*sin(rotate*pi/180))
         = 3 * (1*cos(60*pi/180) + 2*sin(60*pi/180))
         = 6.69615241552696
   newcy = scale * (cy*cos(rotate*pi/180) - cx*sin(rotate*pi/180))
         = 3 * (2*cos(60*pi/180) - 1*sin(60*pi/180))
         = 0.401923908261826

Then to work out the original translation values, take the values above
and subtract (newcx, newcy)

   (10.69615268,4.40190982) - (6.69615241,0.40192390) = (4,4)

> - Does the order matter?  In the app, you can scale, rotate, and
> translate in any order.

Yes, the order matters. If you translate after you scale, you'll have to
unscale the translation values (divide them by the scale). If you
translate after you rotate, you'll have to unrotate them (apply some more
trig). Go through some examples and it should be obvious.

The order of scale and rotate doesn't matter. (As you can see: rotating a
shape and then scaling it produces the same result as scaling it and then
rotating it.)

--Z

--
"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
*
If the Bush administration hasn't thrown you in military prison
without trial, it's for one reason: they don't feel like it. Not
because of the Fifth Amendment.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org



RE: Extracting information from a transformation matrix

Posted by Andrew Plotkin <er...@eblong.com>.
On Thu, 1 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:

> All right, this is great information.  I need to sit down and work 
> through it with my SVG Matrix algebra examples in front of me.  I do 
> have a couple of questions:
>
> - Assuming I already have the center poitns, I could derive all the 
> values I wanted right?  The rotate(t, x, y) command is a shortcut for 
> translation if I remember right.  It's short for translate(x,y) 
> rotate(t) translate(-x,-y) isn't it?

Yes.

If you already know the cx and cy, you can work everything out, yes. Let 
me take a look at my example...

<ellipse id="sall" transform="translate(4,4) scale(3) rotate(60,1,2)"
    rx="1" ry="2" />

    cx,cy = (1,2)   (we know this in advance)
    translate=(10.69615268,4.401909828)
    scale=3
    rotate=60

The scale and rotate values are correct. We just need to fix the 
translation.

(This is where we start applying some Experimental Mathematics. Which is 
to say, I'm going to rearrange the equations until the right answers come 
out. :)

Scale and rotate the cx,cy vector by the values we've worked out. (We're
converting degrees to radians now.

   newcx = scale * (cx*cos(rotate*pi/180) + cy*sin(rotate*pi/180))
         = 3 * (1*cos(60*pi/180) + 2*sin(60*pi/180))
         = 6.69615241552696
   newcy = scale * (cy*cos(rotate*pi/180) - cx*sin(rotate*pi/180))
         = 3 * (2*cos(60*pi/180) - 1*sin(60*pi/180))
         = 0.401923908261826

Then to work out the original translation values, take the values above 
and subtract (newcx, newcy)

   (10.69615268,4.40190982) - (6.69615241,0.40192390) = (4,4)

> - Does the order matter?  In the app, you can scale, rotate, and 
> translate in any order.

Yes, the order matters. If you translate after you scale, you'll have to 
unscale the translation values (divide them by the scale). If you 
translate after you rotate, you'll have to unrotate them (apply some more 
trig). Go through some examples and it should be obvious.

The order of scale and rotate doesn't matter. (As you can see: rotating a 
shape and then scaling it produces the same result as scaling it and then 
rotating it.)

--Z

-- 
"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
*
If the Bush administration hasn't thrown you in military prison
without trial, it's for one reason: they don't feel like it. Not
because of the Fifth Amendment.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Extracting information from a transformation matrix

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
All right, this is great information.  I need to sit down and work through it with my SVG Matrix algebra examples in front of me.  I do have a couple of questions:
 
- Assuming I already have the center poitns, I could derive all the values I wanted right?  The rotate(t, x, y) command is a shortcut for translation if I remember right.  It's short for translate(x,y) rotate(t) translate(-x,-y) isn't it?  Would I have to take that into account?
 
- Does the order matter?  In the app, you can scale, rotate, and translate in any order.
 
Michael Bishop

________________________________

From: Andrew Plotkin [mailto:erkyrath@eblong.com]
Sent: Thu 6/1/2006 12:27 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Extracting information from a transformation matrix



On Thu, 1 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:

> Wow, this is going to make me take another close look at the transformation matrix for SVG.  Let's start with an example:
>
> transform="translate(x, y) scale(sx, sy) rotate(t, cx, cy)"
>
> The above is the only kind of transform I maintain in my application.
>
> If the user drags an element around the screen, it directly affects
> translate.
> If the user scales the element, it affects scale which indirectly
> affects translate.
> If the user rotates the element, I believe it affects scale which also
> affects translate.
>
> What I want to do is be able to break apart the above to find out the
> values I wanted before.  The first thing I need to go is get a
> representation of the above into the matrix values (a, b, c, d, e, f).

Ok, let's work through it.

Here is a simple routine that gets the transform of an object relative to
its parent:

function dump(id) {
   var el = document.getElementById(id);
   var parent = el.parentNode;
   var matrix = el.getTransformToElement(parent);
   alert(matrix.a + " " + matrix.c + " " + matrix.e
     + "\n" + matrix.b + " " + matrix.d + " " + matrix.f);
}

Some samples, in the standard format:
   a c e
   b d f


<ellipse id="none" rx="1" ry="2" />
   1 0 0
   0 1 0

<ellipse id="trans" transform="translate(4,4)" rx="1" ry="2" />
   1 0 4
   0 1 4

<ellipse id="scale" transform="scale(3)" rx="1" ry="2" />
   3 0 0
   0 3 0

<ellipse id="rot" transform="rotate(60)" rx="1" ry="2" />
   0.5 -0.8660253882408142 0
   0.8660253882408142 0.5 0

(Note that 0.8660253882408142 is sqrt(3)/2, or sin(60). 0.5 is cos(60).
Now you know where those numbers come from.)

So an object with a translate+scale+rotate:

<ellipse id="all" transform="translate(4,4) scale(3) rotate(60)" rx="1"
   ry="2" />
   1.5 -2.598076105117798 4
   2.598076105117798 1.5 4

Now this is easy to undo. We're going to pull the transforms off in
forwards order (the *same* order they're listed in the transform
attribute.)

Translate is the (e,f) values directly:
   translate = (4,4).

Now remove this by setting e and f to zero:

   1.5 -2.598076105117798 0
   2.598076105117798 1.5 0

The scale is the magnitude of (a,b). Or (c,d) or (a,c) -- all the same.
Pythagorean theorem:

   scale = sqrt(1.5*1.5 + -2.598076105117798*-2.598076105117798) = 3

Now remove this by dividing each element of the matrix by 3:

   0.5 -0.8660253882408142 0
   0.8660253882408142 0.5 0

What's left is the pure rotation -- you can see it's the same as the "rot"
matrix above. To get the angle out, you'll want to use an atan2 function;
in Javascript this is Math.atan2. The result of that is radians, so we
also have to convert to degrees:

   rotate = atan2(b,a) * 180 / 3.1415926 = 60


Now, the rotation in this example is a rotation around the origin. You
asked about the more complex rotation "rotate(t, cx, cy)". Unfortunately,
there's no way to get that information! If we consider the object

<ellipse id="sall" transform="translate(4,4) scale(3) rotate(60,1,2)"
   rx="1" ry="2" />

and apply the above procedure, you'll get the result:
   translate=(10.69615268,4.401909828)
   scale=3
   rotate=60

Or, if you like,

<ellipse id="sall2" transform="translate(10.69615268,4.401909828) scale(3)
   rotate(60)" rx="1" ry="2" />

The problem is, this is the right answer! These two transforms produce the
*same* matrix -- the same a,b,c,d,e,f values. And there are an infinite
other number of "translate(x, y) scale(sx, sy) rotate(t, cx, cy)"
transforms that produce that matrix. To get a single solution, you *have*
to assume that cx and cy are zero. Otherwise you're trying to get
seven unknowns out of six variables, which is impossible.

(If you assume cx and cy are zero, you get five unknowns out of six
variable. The sixth unknown is skew, or stretching on an axis; the
procedure above assumes there's none of that either.)

--Z

--
"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
*
If the Bush administration hasn't shipped you to Syria for interrogation,
it's for one reason: they don't feel like it. Not because you're patriotic.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org



RE: Extracting information from a transformation matrix

Posted by Andrew Plotkin <er...@eblong.com>.
On Thu, 1 Jun 2006, Bishop, Michael W. CONTR J9C880 wrote:

> Wow, this is going to make me take another close look at the transformation matrix for SVG.  Let's start with an example:
>
> transform="translate(x, y) scale(sx, sy) rotate(t, cx, cy)"
>
> The above is the only kind of transform I maintain in my application.
>
> If the user drags an element around the screen, it directly affects 
> translate. 
> If the user scales the element, it affects scale which indirectly 
> affects translate. 
> If the user rotates the element, I believe it affects scale which also 
> affects translate. 
>
> What I want to do is be able to break apart the above to find out the 
> values I wanted before.  The first thing I need to go is get a 
> representation of the above into the matrix values (a, b, c, d, e, f).

Ok, let's work through it.

Here is a simple routine that gets the transform of an object relative to 
its parent:

function dump(id) {
   var el = document.getElementById(id);
   var parent = el.parentNode;
   var matrix = el.getTransformToElement(parent);
   alert(matrix.a + " " + matrix.c + " " + matrix.e
     + "\n" + matrix.b + " " + matrix.d + " " + matrix.f);
}

Some samples, in the standard format:
   a c e
   b d f


<ellipse id="none" rx="1" ry="2" />
   1 0 0
   0 1 0

<ellipse id="trans" transform="translate(4,4)" rx="1" ry="2" />
   1 0 4
   0 1 4

<ellipse id="scale" transform="scale(3)" rx="1" ry="2" />
   3 0 0
   0 3 0

<ellipse id="rot" transform="rotate(60)" rx="1" ry="2" />
   0.5 -0.8660253882408142 0
   0.8660253882408142 0.5 0

(Note that 0.8660253882408142 is sqrt(3)/2, or sin(60). 0.5 is cos(60). 
Now you know where those numbers come from.)

So an object with a translate+scale+rotate:

<ellipse id="all" transform="translate(4,4) scale(3) rotate(60)" rx="1"
   ry="2" />
   1.5 -2.598076105117798 4
   2.598076105117798 1.5 4

Now this is easy to undo. We're going to pull the transforms off in 
forwards order (the *same* order they're listed in the transform 
attribute.)

Translate is the (e,f) values directly:
   translate = (4,4).

Now remove this by setting e and f to zero:

   1.5 -2.598076105117798 0
   2.598076105117798 1.5 0

The scale is the magnitude of (a,b). Or (c,d) or (a,c) -- all the same. 
Pythagorean theorem:

   scale = sqrt(1.5*1.5 + -2.598076105117798*-2.598076105117798) = 3

Now remove this by dividing each element of the matrix by 3:

   0.5 -0.8660253882408142 0
   0.8660253882408142 0.5 0

What's left is the pure rotation -- you can see it's the same as the "rot" 
matrix above. To get the angle out, you'll want to use an atan2 function; 
in Javascript this is Math.atan2. The result of that is radians, so we 
also have to convert to degrees:

   rotate = atan2(b,a) * 180 / 3.1415926 = 60


Now, the rotation in this example is a rotation around the origin. You 
asked about the more complex rotation "rotate(t, cx, cy)". Unfortunately, 
there's no way to get that information! If we consider the object

<ellipse id="sall" transform="translate(4,4) scale(3) rotate(60,1,2)"
   rx="1" ry="2" />

and apply the above procedure, you'll get the result:
   translate=(10.69615268,4.401909828)
   scale=3
   rotate=60

Or, if you like,

<ellipse id="sall2" transform="translate(10.69615268,4.401909828) scale(3)
   rotate(60)" rx="1" ry="2" />

The problem is, this is the right answer! These two transforms produce the 
*same* matrix -- the same a,b,c,d,e,f values. And there are an infinite 
other number of "translate(x, y) scale(sx, sy) rotate(t, cx, cy)" 
transforms that produce that matrix. To get a single solution, you *have* 
to assume that cx and cy are zero. Otherwise you're trying to get 
seven unknowns out of six variables, which is impossible.

(If you assume cx and cy are zero, you get five unknowns out of six 
variable. The sixth unknown is skew, or stretching on an axis; the 
procedure above assumes there's none of that either.)

--Z

-- 
"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
*
If the Bush administration hasn't shipped you to Syria for interrogation,
it's for one reason: they don't feel like it. Not because you're patriotic.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org