xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bishop, Michael W. CONTR J9C880" <Michael.Bis...@je.jfcom.mil>
Subject RE: Extracting information from a transformation matrix
Date Thu, 01 Jun 2006 13:12:27 GMT
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" <Michael.Bishop@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
> <Michael.Bishop@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



Mime
View raw message