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 "Paul L. Bogen" <pl...@kbsi.com> on 2007/07/10 18:12:59 UTC

Rotation about center of a G

I am trying to implement a function that translates a G to the origin,
rotates it, translates it back to the original position, scales it, and
then translates it to a target position. However it doesn't seem to work
if I comment out the rotation bits translation and scaling work
perfectly. Any ideas what I am doing wrong?
 
<snip>
SVGOMGElement svgG = ((SVGOMGElement) n);
SVGTransformList svgTL = ((SVGTransformable)
svgG).getTransform().getBaseVal(); 
svgTL.consolidate();
 
SVGMatrix svgM;

if(svgTL.getNumberOfItems() == 0)
{
    SVGTransform svgT = new SVGOMTransform();
    svgM = new SVGOMMatrix(new AffineTransform(1,0,0,1,0,0));
    svgT.setMatrix(svgM);
    svgTL.appendItem(svgT);
}

SVGOMMatrix mat1 = new SVGOMMatrix(new
AffineTransform(1,0,0,1,-w/2,-h/2));
SVGOMMatrix mat2 = new SVGOMMatrix(new
AffineTransform(Math.cos(angle),Math.sin(angle),-Math.sin(angle),Math.co
s(angle),0,0));
SVGOMMatrix mat3 = new SVGOMMatrix(new
AffineTransform(1,0,0,1,w/2,h/2));
SVGOMMatrix mat4 = new SVGOMMatrix(new
AffineTransform(scaleX,0,0,scaleY,0,0));
SVGOMMatrix mat5 = new SVGOMMatrix(new AffineTransform(1,0,0,1,x,y));

svgM = mat1;
svgM = svgM.multiply(mat2);
svgM = svgM.multiply(mat3);
svgM = svgM.multiply(mat4);
svgM = svgM.multiply(mat5);
svgTL.getItem(0).setMatrix(svgM);

</snip>

thanks,
plb
PAUL LOGASA BOGEN II
Programmer

KNOWLEDGE BASED SYSTEMS, INC.
1408 University Drive East
College Station, Texas 77840
Phone: 979-260-5274
Fax: 979-691-2928
www.kbsi.com
<file:///C:/Documents%20and%20Settings/plbogen/Application%20Data/Micros
oft/Signatures/www.kbsi.com> 

 

RE: Rotation about center of a G

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

"Paul L. Bogen" <pl...@kbsi.com> wrote on 07/16/2007 01:20:13 PM:

> >    One thing is that I'm not entirely sure you have a clear 
> > idea of what you actually want when someone passes in a 
> > rotation of 45Deg with a scale of 2x and a translate of 200,100. 
> 
> I want the scaled object to be rotated 45 degrees respective to the post
> scaled center of the object and the object's upper left corner
> translated to 200,100.

   I believe this will do what you want:

        AffineTransform at = 
AffineTransform.getScaleInstance(scaleX,scaleY);
        at.rotate(angle*(Math.PI/180), scaleX*w/2.0, scaleY*h/2.0);
        at.translate(x, y);


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


RE: Rotation about center of a G

Posted by "Paul L. Bogen" <pl...@kbsi.com>.
>    One thing is that I'm not entirely sure you have a clear 
> idea of what you actually want when someone passes in a 
> rotation of 45Deg with a scale of 2x and a translate of 200,100. 

I want the scaled object to be rotated 45 degrees respective to the post
scaled center of the object and the object's upper left corner
translated to 200,100.
 
>    Since the translate interacts with both scale and rotation 
> you need to decide what single point in the source coordinate 
> system you want translated.  One example would be the center 
> point of the original.

>    The way you have constructed these you should only need 
> w/2, h/2 to rotate around the original origin.  You might 
> also try moving the translate before the scale.

Not if the object is already scaled, and translating before the scale
seems to produce even more bizarre results, namely I can't see the
object at all.

plb

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


RE: Rotation about center of a G

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

"Paul L. Bogen" <pl...@kbsi.com> wrote on 07/11/2007 04:40:00 PM:

> Here is applicable code I have now. It still isn't rotating right...

   One thing is that I'm not entirely sure you have a clear
idea of what you actually want when someone passes in a rotation
of 45Deg with a scale of 2x and a translate of 200,100. 

   Since the translate interacts with both scale and rotation
you need to decide what single point in the source coordinate
system you want translated.  One example would be the center point
of the original.

> <snip>
> SVGOMGElement svgG = ((SVGOMGElement) n);
> 
> SVGTransformList svgTL = 
((SVGTransformable)svgG).getTransform().getBaseVal(); 
> 
> AffineTransform at = AffineTransform.getScaleInstance(scaleX,scaleY);
> at.translate(x, y);
> at.rotate(angle*(Math.PI/180), x+(scaleX*w/2.0), y+(scaleY*h/2.0));

   The way you have constructed these you should only need
w/2, h/2 to rotate around the original origin.  You might
also try moving the translate before the scale.

   One way to get a feel for transforms is to make a simple
coordinate system 'symbol' in SVG and play with the
transform attribute on the 'use' element.

> 
> SVGMatrix svgM = new SVGOMMatrix(at);
> 
> SVGTransform svgT = new SVGOMTransform();
> svgT.setMatrix(svgM);
> 
> svgTL.clear();
> svgTL.appendItem(svgT);
> </snip>
> 
> If I do getTranslateInstance first and the .scale, I get results that
> are even less correct.
> 
> plb
> 
> -----Original Message-----
> From: Bishop, Michael W. CONTR J9C880
> [mailto:Michael.Bishop@je.jfcom.mil] 
> Sent: Wednesday, July 11, 2007 12:13 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: RE: Rotation about center of a G
> 
> I use them in my utilities class.  I got it working well enough to
> rotate, translate, and scale in any order (to the user) without having
> things go crazy, but it sure took awhile.
> 
> Michael Bishop
> 
> -----Original Message-----
> From: Paul L. Bogen [mailto:plbogen@kbsi.com]
> Sent: Wednesday, July 11, 2007 12:53 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: RE: Rotation about center of a G
> 
> That is why my original code calculates the product of the affines and
> then applies that. I could never get the provided .rotate(), .scale(),
> .translate() methods to work at all
> 
> plb
> 
> -----Original Message-----
> From: Bishop, Michael W. CONTR J9C880
> [mailto:Michael.Bishop@je.jfcom.mil]
> Sent: Wednesday, July 11, 2007 11:51 AM
> To: batik-users@xmlgraphics.apache.org
> Subject: RE: Rotation about center of a G
> 
> The rotate function of transforms takes an x and a y coordinate where
> you can specify which point you want to rotate around.  I'm not sure why
> you want to do the rotation first.  It'd be easier to translate to your
> desired position, scale, then rotate.  You can operate on scale and
> rotate independently but rotating affects the same positions in the
> matrix as scaling and translating; once you rotate, your original values
> for scaling and translating are lost.
> 
> Michael Bishop
> 
> -----Original Message-----
> From: Paul L. Bogen [mailto:plbogen@kbsi.com]
> Sent: Wednesday, July 11, 2007 12:32 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: RE: Rotation about center of a G
> 
> But it will still rotate about the origin and not the center of the G,
> correct?
> 
> plb 
> 
> -----Original Message-----
> From: Bishop, Michael W. CONTR J9C880
> [mailto:Michael.Bishop@je.jfcom.mil]
> Sent: Wednesday, July 11, 2007 9:37 AM
> To: batik-users@xmlgraphics.apache.org
> Subject: RE: Rotation about center of a G
> 
> Transforms were a giant headache for me.  The best way I found to deal
> with it was to apply the operations in this order: Translate, Scale,
> Rotate.
> 
> If I wanted to "adjust" any of the values, I'd work backwards to that
> point.  In order to translate, for instance, I'd revert the rotation
> angle, revert the scale, translate by the new values, then reapply the
> scale and rotation.  It might not be the best way, but it was the only
> way I could find to allow the user to apply these operations
> arbitrarily.  I don't even account for stretch/skew.
> 
> I've got a utility class that helps with this stuff.
> 
> Michael Bishop 
> 
> -----Original Message-----
> From: Paul L. Bogen [mailto:plbogen@kbsi.com]
> Sent: Tuesday, July 10, 2007 12:13 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: Rotation about center of a G
> 
> I am trying to implement a function that translates a G to the origin,
> rotates it, translates it back to the original position, scales it, and
> then translates it to a target position. However it doesn't seem to work
> if I comment out the rotation bits translation and scaling work
> perfectly. Any ideas what I am doing wrong?
> 
> <snip>
> SVGOMGElement svgG = ((SVGOMGElement) n); SVGTransformList svgTL =
> ((SVGTransformable) svgG).getTransform().getBaseVal();
> svgTL.consolidate();
> 
> SVGMatrix svgM;
> 
> if(svgTL.getNumberOfItems() == 0)
> {
>     SVGTransform svgT = new SVGOMTransform();
>     svgM = new SVGOMMatrix(new AffineTransform(1,0,0,1,0,0));
>     svgT.setMatrix(svgM);
>     svgTL.appendItem(svgT);
> }
> 
> SVGOMMatrix mat1 = new SVGOMMatrix(new
> AffineTransform(1,0,0,1,-w/2,-h/2));
> SVGOMMatrix mat2 = new SVGOMMatrix(new
> AffineTransform(Math.cos(angle),Math.sin(angle),-Math.sin(angle),Math.co
> s(angle),0,0));
> SVGOMMatrix mat3 = new SVGOMMatrix(new
> AffineTransform(1,0,0,1,w/2,h/2));
> SVGOMMatrix mat4 = new SVGOMMatrix(new
> AffineTransform(scaleX,0,0,scaleY,0,0));
> SVGOMMatrix mat5 = new SVGOMMatrix(new AffineTransform(1,0,0,1,x,y));
> 
> svgM = mat1;
> svgM = svgM.multiply(mat2);
> svgM = svgM.multiply(mat3);
> svgM = svgM.multiply(mat4);
> svgM = svgM.multiply(mat5);
> svgTL.getItem(0).setMatrix(svgM);
> 
> </snip>
> 
> thanks,
> plb
> PAUL LOGASA BOGEN II
> Programmer
> 
> KNOWLEDGE BASED SYSTEMS, INC.
> 1408 University Drive East
> College Station, Texas 77840
> Phone: 979-260-5274
> Fax: 979-691-2928
> www.kbsi.com
> <file:///C:/Documents%20and%20Settings/plbogen/Application%20Data/Micros
> oft/Signatures/www.kbsi.com> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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: Rotation about center of a G

Posted by "Paul L. Bogen" <pl...@kbsi.com>.
Here is applicable code I have now. It still isn't rotating right...

<snip>
SVGOMGElement svgG = ((SVGOMGElement) n);

SVGTransformList svgTL = ((SVGTransformable)
svgG).getTransform().getBaseVal();		

AffineTransform at = AffineTransform.getScaleInstance(scaleX,scaleY);
at.translate(x, y);
at.rotate(angle*(Math.PI/180), x+(scaleX*w/2.0), y+(scaleY*h/2.0));
			
SVGMatrix svgM = new SVGOMMatrix(at);

SVGTransform svgT = new SVGOMTransform();
svgT.setMatrix(svgM);
			
svgTL.clear();
svgTL.appendItem(svgT);
</snip>

If I do getTranslateInstance first and the .scale, I get results that
are even less correct.

plb

-----Original Message-----
From: Bishop, Michael W. CONTR J9C880
[mailto:Michael.Bishop@je.jfcom.mil] 
Sent: Wednesday, July 11, 2007 12:13 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Rotation about center of a G

I use them in my utilities class.  I got it working well enough to
rotate, translate, and scale in any order (to the user) without having
things go crazy, but it sure took awhile.

Michael Bishop

-----Original Message-----
From: Paul L. Bogen [mailto:plbogen@kbsi.com]
Sent: Wednesday, July 11, 2007 12:53 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Rotation about center of a G

That is why my original code calculates the product of the affines and
then applies that. I could never get the provided .rotate(), .scale(),
.translate() methods to work at all

plb

-----Original Message-----
From: Bishop, Michael W. CONTR J9C880
[mailto:Michael.Bishop@je.jfcom.mil]
Sent: Wednesday, July 11, 2007 11:51 AM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Rotation about center of a G

The rotate function of transforms takes an x and a y coordinate where
you can specify which point you want to rotate around.  I'm not sure why
you want to do the rotation first.  It'd be easier to translate to your
desired position, scale, then rotate.  You can operate on scale and
rotate independently but rotating affects the same positions in the
matrix as scaling and translating; once you rotate, your original values
for scaling and translating are lost.

Michael Bishop

-----Original Message-----
From: Paul L. Bogen [mailto:plbogen@kbsi.com]
Sent: Wednesday, July 11, 2007 12:32 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Rotation about center of a G

But it will still rotate about the origin and not the center of the G,
correct?

plb 

-----Original Message-----
From: Bishop, Michael W. CONTR J9C880
[mailto:Michael.Bishop@je.jfcom.mil]
Sent: Wednesday, July 11, 2007 9:37 AM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Rotation about center of a G

Transforms were a giant headache for me.  The best way I found to deal
with it was to apply the operations in this order: Translate, Scale,
Rotate.

If I wanted to "adjust" any of the values, I'd work backwards to that
point.  In order to translate, for instance, I'd revert the rotation
angle, revert the scale, translate by the new values, then reapply the
scale and rotation.  It might not be the best way, but it was the only
way I could find to allow the user to apply these operations
arbitrarily.  I don't even account for stretch/skew.

I've got a utility class that helps with this stuff.

Michael Bishop 

-----Original Message-----
From: Paul L. Bogen [mailto:plbogen@kbsi.com]
Sent: Tuesday, July 10, 2007 12:13 PM
To: batik-users@xmlgraphics.apache.org
Subject: Rotation about center of a G

I am trying to implement a function that translates a G to the origin,
rotates it, translates it back to the original position, scales it, and
then translates it to a target position. However it doesn't seem to work
if I comment out the rotation bits translation and scaling work
perfectly. Any ideas what I am doing wrong?
 
<snip>
SVGOMGElement svgG = ((SVGOMGElement) n); SVGTransformList svgTL =
((SVGTransformable) svgG).getTransform().getBaseVal();
svgTL.consolidate();
 
SVGMatrix svgM;

if(svgTL.getNumberOfItems() == 0)
{
    SVGTransform svgT = new SVGOMTransform();
    svgM = new SVGOMMatrix(new AffineTransform(1,0,0,1,0,0));
    svgT.setMatrix(svgM);
    svgTL.appendItem(svgT);
}

SVGOMMatrix mat1 = new SVGOMMatrix(new
AffineTransform(1,0,0,1,-w/2,-h/2));
SVGOMMatrix mat2 = new SVGOMMatrix(new
AffineTransform(Math.cos(angle),Math.sin(angle),-Math.sin(angle),Math.co
s(angle),0,0));
SVGOMMatrix mat3 = new SVGOMMatrix(new
AffineTransform(1,0,0,1,w/2,h/2));
SVGOMMatrix mat4 = new SVGOMMatrix(new
AffineTransform(scaleX,0,0,scaleY,0,0));
SVGOMMatrix mat5 = new SVGOMMatrix(new AffineTransform(1,0,0,1,x,y));

svgM = mat1;
svgM = svgM.multiply(mat2);
svgM = svgM.multiply(mat3);
svgM = svgM.multiply(mat4);
svgM = svgM.multiply(mat5);
svgTL.getItem(0).setMatrix(svgM);

</snip>

thanks,
plb
PAUL LOGASA BOGEN II
Programmer

KNOWLEDGE BASED SYSTEMS, INC.
1408 University Drive East
College Station, Texas 77840
Phone: 979-260-5274
Fax: 979-691-2928
www.kbsi.com
<file:///C:/Documents%20and%20Settings/plbogen/Application%20Data/Micros
oft/Signatures/www.kbsi.com> 

 

---------------------------------------------------------------------
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: Rotation about center of a G

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
I use them in my utilities class.  I got it working well enough to
rotate, translate, and scale in any order (to the user) without having
things go crazy, but it sure took awhile.

Michael Bishop

-----Original Message-----
From: Paul L. Bogen [mailto:plbogen@kbsi.com] 
Sent: Wednesday, July 11, 2007 12:53 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Rotation about center of a G

That is why my original code calculates the product of the affines and
then applies that. I could never get the provided .rotate(), .scale(),
.translate() methods to work at all

plb

-----Original Message-----
From: Bishop, Michael W. CONTR J9C880
[mailto:Michael.Bishop@je.jfcom.mil]
Sent: Wednesday, July 11, 2007 11:51 AM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Rotation about center of a G

The rotate function of transforms takes an x and a y coordinate where
you can specify which point you want to rotate around.  I'm not sure why
you want to do the rotation first.  It'd be easier to translate to your
desired position, scale, then rotate.  You can operate on scale and
rotate independently but rotating affects the same positions in the
matrix as scaling and translating; once you rotate, your original values
for scaling and translating are lost.

Michael Bishop

-----Original Message-----
From: Paul L. Bogen [mailto:plbogen@kbsi.com]
Sent: Wednesday, July 11, 2007 12:32 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Rotation about center of a G

But it will still rotate about the origin and not the center of the G,
correct?

plb 

-----Original Message-----
From: Bishop, Michael W. CONTR J9C880
[mailto:Michael.Bishop@je.jfcom.mil]
Sent: Wednesday, July 11, 2007 9:37 AM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Rotation about center of a G

Transforms were a giant headache for me.  The best way I found to deal
with it was to apply the operations in this order: Translate, Scale,
Rotate.

If I wanted to "adjust" any of the values, I'd work backwards to that
point.  In order to translate, for instance, I'd revert the rotation
angle, revert the scale, translate by the new values, then reapply the
scale and rotation.  It might not be the best way, but it was the only
way I could find to allow the user to apply these operations
arbitrarily.  I don't even account for stretch/skew.

I've got a utility class that helps with this stuff.

Michael Bishop 

-----Original Message-----
From: Paul L. Bogen [mailto:plbogen@kbsi.com]
Sent: Tuesday, July 10, 2007 12:13 PM
To: batik-users@xmlgraphics.apache.org
Subject: Rotation about center of a G

I am trying to implement a function that translates a G to the origin,
rotates it, translates it back to the original position, scales it, and
then translates it to a target position. However it doesn't seem to work
if I comment out the rotation bits translation and scaling work
perfectly. Any ideas what I am doing wrong?
 
<snip>
SVGOMGElement svgG = ((SVGOMGElement) n); SVGTransformList svgTL =
((SVGTransformable) svgG).getTransform().getBaseVal();
svgTL.consolidate();
 
SVGMatrix svgM;

if(svgTL.getNumberOfItems() == 0)
{
    SVGTransform svgT = new SVGOMTransform();
    svgM = new SVGOMMatrix(new AffineTransform(1,0,0,1,0,0));
    svgT.setMatrix(svgM);
    svgTL.appendItem(svgT);
}

SVGOMMatrix mat1 = new SVGOMMatrix(new
AffineTransform(1,0,0,1,-w/2,-h/2));
SVGOMMatrix mat2 = new SVGOMMatrix(new
AffineTransform(Math.cos(angle),Math.sin(angle),-Math.sin(angle),Math.co
s(angle),0,0));
SVGOMMatrix mat3 = new SVGOMMatrix(new
AffineTransform(1,0,0,1,w/2,h/2));
SVGOMMatrix mat4 = new SVGOMMatrix(new
AffineTransform(scaleX,0,0,scaleY,0,0));
SVGOMMatrix mat5 = new SVGOMMatrix(new AffineTransform(1,0,0,1,x,y));

svgM = mat1;
svgM = svgM.multiply(mat2);
svgM = svgM.multiply(mat3);
svgM = svgM.multiply(mat4);
svgM = svgM.multiply(mat5);
svgTL.getItem(0).setMatrix(svgM);

</snip>

thanks,
plb
PAUL LOGASA BOGEN II
Programmer

KNOWLEDGE BASED SYSTEMS, INC.
1408 University Drive East
College Station, Texas 77840
Phone: 979-260-5274
Fax: 979-691-2928
www.kbsi.com
<file:///C:/Documents%20and%20Settings/plbogen/Application%20Data/Micros
oft/Signatures/www.kbsi.com> 

 

---------------------------------------------------------------------
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: Rotation about center of a G

Posted by "Paul L. Bogen" <pl...@kbsi.com>.
That is why my original code calculates the product of the affines and
then applies that. I could never get the provided .rotate(), .scale(),
.translate() methods to work at all

plb

-----Original Message-----
From: Bishop, Michael W. CONTR J9C880
[mailto:Michael.Bishop@je.jfcom.mil] 
Sent: Wednesday, July 11, 2007 11:51 AM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Rotation about center of a G

The rotate function of transforms takes an x and a y coordinate where
you can specify which point you want to rotate around.  I'm not sure why
you want to do the rotation first.  It'd be easier to translate to your
desired position, scale, then rotate.  You can operate on scale and
rotate independently but rotating affects the same positions in the
matrix as scaling and translating; once you rotate, your original values
for scaling and translating are lost.

Michael Bishop

-----Original Message-----
From: Paul L. Bogen [mailto:plbogen@kbsi.com]
Sent: Wednesday, July 11, 2007 12:32 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Rotation about center of a G

But it will still rotate about the origin and not the center of the G,
correct?

plb 

-----Original Message-----
From: Bishop, Michael W. CONTR J9C880
[mailto:Michael.Bishop@je.jfcom.mil]
Sent: Wednesday, July 11, 2007 9:37 AM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Rotation about center of a G

Transforms were a giant headache for me.  The best way I found to deal
with it was to apply the operations in this order: Translate, Scale,
Rotate.

If I wanted to "adjust" any of the values, I'd work backwards to that
point.  In order to translate, for instance, I'd revert the rotation
angle, revert the scale, translate by the new values, then reapply the
scale and rotation.  It might not be the best way, but it was the only
way I could find to allow the user to apply these operations
arbitrarily.  I don't even account for stretch/skew.

I've got a utility class that helps with this stuff.

Michael Bishop 

-----Original Message-----
From: Paul L. Bogen [mailto:plbogen@kbsi.com]
Sent: Tuesday, July 10, 2007 12:13 PM
To: batik-users@xmlgraphics.apache.org
Subject: Rotation about center of a G

I am trying to implement a function that translates a G to the origin,
rotates it, translates it back to the original position, scales it, and
then translates it to a target position. However it doesn't seem to work
if I comment out the rotation bits translation and scaling work
perfectly. Any ideas what I am doing wrong?
 
<snip>
SVGOMGElement svgG = ((SVGOMGElement) n); SVGTransformList svgTL =
((SVGTransformable) svgG).getTransform().getBaseVal();
svgTL.consolidate();
 
SVGMatrix svgM;

if(svgTL.getNumberOfItems() == 0)
{
    SVGTransform svgT = new SVGOMTransform();
    svgM = new SVGOMMatrix(new AffineTransform(1,0,0,1,0,0));
    svgT.setMatrix(svgM);
    svgTL.appendItem(svgT);
}

SVGOMMatrix mat1 = new SVGOMMatrix(new
AffineTransform(1,0,0,1,-w/2,-h/2));
SVGOMMatrix mat2 = new SVGOMMatrix(new
AffineTransform(Math.cos(angle),Math.sin(angle),-Math.sin(angle),Math.co
s(angle),0,0));
SVGOMMatrix mat3 = new SVGOMMatrix(new
AffineTransform(1,0,0,1,w/2,h/2));
SVGOMMatrix mat4 = new SVGOMMatrix(new
AffineTransform(scaleX,0,0,scaleY,0,0));
SVGOMMatrix mat5 = new SVGOMMatrix(new AffineTransform(1,0,0,1,x,y));

svgM = mat1;
svgM = svgM.multiply(mat2);
svgM = svgM.multiply(mat3);
svgM = svgM.multiply(mat4);
svgM = svgM.multiply(mat5);
svgTL.getItem(0).setMatrix(svgM);

</snip>

thanks,
plb
PAUL LOGASA BOGEN II
Programmer

KNOWLEDGE BASED SYSTEMS, INC.
1408 University Drive East
College Station, Texas 77840
Phone: 979-260-5274
Fax: 979-691-2928
www.kbsi.com
<file:///C:/Documents%20and%20Settings/plbogen/Application%20Data/Micros
oft/Signatures/www.kbsi.com> 

 

---------------------------------------------------------------------
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: Rotation about center of a G

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
The rotate function of transforms takes an x and a y coordinate where
you can specify which point you want to rotate around.  I'm not sure why
you want to do the rotation first.  It'd be easier to translate to your
desired position, scale, then rotate.  You can operate on scale and
rotate independently but rotating affects the same positions in the
matrix as scaling and translating; once you rotate, your original values
for scaling and translating are lost.

Michael Bishop

-----Original Message-----
From: Paul L. Bogen [mailto:plbogen@kbsi.com] 
Sent: Wednesday, July 11, 2007 12:32 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Rotation about center of a G

But it will still rotate about the origin and not the center of the G,
correct?

plb 

-----Original Message-----
From: Bishop, Michael W. CONTR J9C880
[mailto:Michael.Bishop@je.jfcom.mil]
Sent: Wednesday, July 11, 2007 9:37 AM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Rotation about center of a G

Transforms were a giant headache for me.  The best way I found to deal
with it was to apply the operations in this order: Translate, Scale,
Rotate.

If I wanted to "adjust" any of the values, I'd work backwards to that
point.  In order to translate, for instance, I'd revert the rotation
angle, revert the scale, translate by the new values, then reapply the
scale and rotation.  It might not be the best way, but it was the only
way I could find to allow the user to apply these operations
arbitrarily.  I don't even account for stretch/skew.

I've got a utility class that helps with this stuff.

Michael Bishop 

-----Original Message-----
From: Paul L. Bogen [mailto:plbogen@kbsi.com]
Sent: Tuesday, July 10, 2007 12:13 PM
To: batik-users@xmlgraphics.apache.org
Subject: Rotation about center of a G

I am trying to implement a function that translates a G to the origin,
rotates it, translates it back to the original position, scales it, and
then translates it to a target position. However it doesn't seem to work
if I comment out the rotation bits translation and scaling work
perfectly. Any ideas what I am doing wrong?
 
<snip>
SVGOMGElement svgG = ((SVGOMGElement) n); SVGTransformList svgTL =
((SVGTransformable) svgG).getTransform().getBaseVal();
svgTL.consolidate();
 
SVGMatrix svgM;

if(svgTL.getNumberOfItems() == 0)
{
    SVGTransform svgT = new SVGOMTransform();
    svgM = new SVGOMMatrix(new AffineTransform(1,0,0,1,0,0));
    svgT.setMatrix(svgM);
    svgTL.appendItem(svgT);
}

SVGOMMatrix mat1 = new SVGOMMatrix(new
AffineTransform(1,0,0,1,-w/2,-h/2));
SVGOMMatrix mat2 = new SVGOMMatrix(new
AffineTransform(Math.cos(angle),Math.sin(angle),-Math.sin(angle),Math.co
s(angle),0,0));
SVGOMMatrix mat3 = new SVGOMMatrix(new
AffineTransform(1,0,0,1,w/2,h/2));
SVGOMMatrix mat4 = new SVGOMMatrix(new
AffineTransform(scaleX,0,0,scaleY,0,0));
SVGOMMatrix mat5 = new SVGOMMatrix(new AffineTransform(1,0,0,1,x,y));

svgM = mat1;
svgM = svgM.multiply(mat2);
svgM = svgM.multiply(mat3);
svgM = svgM.multiply(mat4);
svgM = svgM.multiply(mat5);
svgTL.getItem(0).setMatrix(svgM);

</snip>

thanks,
plb
PAUL LOGASA BOGEN II
Programmer

KNOWLEDGE BASED SYSTEMS, INC.
1408 University Drive East
College Station, Texas 77840
Phone: 979-260-5274
Fax: 979-691-2928
www.kbsi.com
<file:///C:/Documents%20and%20Settings/plbogen/Application%20Data/Micros
oft/Signatures/www.kbsi.com> 

 

---------------------------------------------------------------------
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: Rotation about center of a G

Posted by "Paul L. Bogen" <pl...@kbsi.com>.
But it will still rotate about the origin and not the center of the G,
correct?

plb 

-----Original Message-----
From: Bishop, Michael W. CONTR J9C880
[mailto:Michael.Bishop@je.jfcom.mil] 
Sent: Wednesday, July 11, 2007 9:37 AM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Rotation about center of a G

Transforms were a giant headache for me.  The best way I found to deal
with it was to apply the operations in this order: Translate, Scale,
Rotate.

If I wanted to "adjust" any of the values, I'd work backwards to that
point.  In order to translate, for instance, I'd revert the rotation
angle, revert the scale, translate by the new values, then reapply the
scale and rotation.  It might not be the best way, but it was the only
way I could find to allow the user to apply these operations
arbitrarily.  I don't even account for stretch/skew.

I've got a utility class that helps with this stuff.

Michael Bishop 

-----Original Message-----
From: Paul L. Bogen [mailto:plbogen@kbsi.com]
Sent: Tuesday, July 10, 2007 12:13 PM
To: batik-users@xmlgraphics.apache.org
Subject: Rotation about center of a G

I am trying to implement a function that translates a G to the origin,
rotates it, translates it back to the original position, scales it, and
then translates it to a target position. However it doesn't seem to work
if I comment out the rotation bits translation and scaling work
perfectly. Any ideas what I am doing wrong?
 
<snip>
SVGOMGElement svgG = ((SVGOMGElement) n); SVGTransformList svgTL =
((SVGTransformable) svgG).getTransform().getBaseVal();
svgTL.consolidate();
 
SVGMatrix svgM;

if(svgTL.getNumberOfItems() == 0)
{
    SVGTransform svgT = new SVGOMTransform();
    svgM = new SVGOMMatrix(new AffineTransform(1,0,0,1,0,0));
    svgT.setMatrix(svgM);
    svgTL.appendItem(svgT);
}

SVGOMMatrix mat1 = new SVGOMMatrix(new
AffineTransform(1,0,0,1,-w/2,-h/2));
SVGOMMatrix mat2 = new SVGOMMatrix(new
AffineTransform(Math.cos(angle),Math.sin(angle),-Math.sin(angle),Math.co
s(angle),0,0));
SVGOMMatrix mat3 = new SVGOMMatrix(new
AffineTransform(1,0,0,1,w/2,h/2));
SVGOMMatrix mat4 = new SVGOMMatrix(new
AffineTransform(scaleX,0,0,scaleY,0,0));
SVGOMMatrix mat5 = new SVGOMMatrix(new AffineTransform(1,0,0,1,x,y));

svgM = mat1;
svgM = svgM.multiply(mat2);
svgM = svgM.multiply(mat3);
svgM = svgM.multiply(mat4);
svgM = svgM.multiply(mat5);
svgTL.getItem(0).setMatrix(svgM);

</snip>

thanks,
plb
PAUL LOGASA BOGEN II
Programmer

KNOWLEDGE BASED SYSTEMS, INC.
1408 University Drive East
College Station, Texas 77840
Phone: 979-260-5274
Fax: 979-691-2928
www.kbsi.com
<file:///C:/Documents%20and%20Settings/plbogen/Application%20Data/Micros
oft/Signatures/www.kbsi.com> 

 

---------------------------------------------------------------------
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: Rotation about center of a G

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

"Paul L. Bogen" <pl...@kbsi.com> wrote on 07/10/2007 12:12:59 PM:

> I am trying to implement a function that translates a G to the 
> origin, rotates it, translates it back to the original position, 
> scales it, and then translates it to a target position. However it 
> doesn't seem to work if I comment out the rotation bits translation 
> and scaling work perfectly. Any ideas what I am doing wrong?

   After/Before the rotation the translations need to be rotated as
well.  The easiest way to rotate around a point is:
        AffineTransform.getRotateInstance( angleRad, cx, cy)

   Note that after you rotate your center point will change, so
the scale offsets will also need to change (it may be easier to
scale then rotate).

> <snip>
> SVGOMGElement svgG = ((SVGOMGElement) n);
> SVGTransformList svgTL = ((SVGTransformable) svgG).getTransform().
> getBaseVal(); 
> svgTL.consolidate();
> 
> SVGMatrix svgM;
> if(svgTL.getNumberOfItems() == 0)
> {
>     SVGTransform svgT = new SVGOMTransform();
>     svgM = new SVGOMMatrix(new AffineTransform(1,0,0,1,0,0));
>     svgT.setMatrix(svgM);
>     svgTL.appendItem(svgT);
> }
> SVGOMMatrix mat1 = new SVGOMMatrix(new 
AffineTransform(1,0,0,1,-w/2,-h/2));
> SVGOMMatrix mat2 = new SVGOMMatrix(new 
AffineTransform(Math.cos(angle),Math.
> sin(angle),-Math.sin(angle),Math.cos(angle),0,0));
> SVGOMMatrix mat3 = new SVGOMMatrix(new 
AffineTransform(1,0,0,1,w/2,h/2));
> SVGOMMatrix mat4 = new SVGOMMatrix(new AffineTransform(scaleX,0,0,
> scaleY,0,0));
> SVGOMMatrix mat5 = new SVGOMMatrix(new AffineTransform(1,0,0,1,x,y));
> svgM = mat1;
> svgM = svgM.multiply(mat2);
> svgM = svgM.multiply(mat3);
> svgM = svgM.multiply(mat4);
> svgM = svgM.multiply(mat5);
> svgTL.getItem(0).setMatrix(svgM);
> </snip>
> thanks,
> plb
> PAUL LOGASA BOGEN II
> Programmer
> KNOWLEDGE BASED SYSTEMS, INC.
> 1408 University Drive East
> College Station, Texas 77840
> Phone: 979-260-5274
> Fax: 979-691-2928
> www.kbsi.com
> 

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


RE: Rotation about center of a G

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
Transforms were a giant headache for me.  The best way I found to deal
with it was to apply the operations in this order: Translate, Scale,
Rotate.

If I wanted to "adjust" any of the values, I'd work backwards to that
point.  In order to translate, for instance, I'd revert the rotation
angle, revert the scale, translate by the new values, then reapply the
scale and rotation.  It might not be the best way, but it was the only
way I could find to allow the user to apply these operations
arbitrarily.  I don't even account for stretch/skew.

I've got a utility class that helps with this stuff.

Michael Bishop 

-----Original Message-----
From: Paul L. Bogen [mailto:plbogen@kbsi.com] 
Sent: Tuesday, July 10, 2007 12:13 PM
To: batik-users@xmlgraphics.apache.org
Subject: Rotation about center of a G

I am trying to implement a function that translates a G to the origin,
rotates it, translates it back to the original position, scales it, and
then translates it to a target position. However it doesn't seem to work
if I comment out the rotation bits translation and scaling work
perfectly. Any ideas what I am doing wrong?
 
<snip>
SVGOMGElement svgG = ((SVGOMGElement) n); SVGTransformList svgTL =
((SVGTransformable) svgG).getTransform().getBaseVal();
svgTL.consolidate();
 
SVGMatrix svgM;

if(svgTL.getNumberOfItems() == 0)
{
    SVGTransform svgT = new SVGOMTransform();
    svgM = new SVGOMMatrix(new AffineTransform(1,0,0,1,0,0));
    svgT.setMatrix(svgM);
    svgTL.appendItem(svgT);
}

SVGOMMatrix mat1 = new SVGOMMatrix(new
AffineTransform(1,0,0,1,-w/2,-h/2));
SVGOMMatrix mat2 = new SVGOMMatrix(new
AffineTransform(Math.cos(angle),Math.sin(angle),-Math.sin(angle),Math.co
s(angle),0,0));
SVGOMMatrix mat3 = new SVGOMMatrix(new
AffineTransform(1,0,0,1,w/2,h/2));
SVGOMMatrix mat4 = new SVGOMMatrix(new
AffineTransform(scaleX,0,0,scaleY,0,0));
SVGOMMatrix mat5 = new SVGOMMatrix(new AffineTransform(1,0,0,1,x,y));

svgM = mat1;
svgM = svgM.multiply(mat2);
svgM = svgM.multiply(mat3);
svgM = svgM.multiply(mat4);
svgM = svgM.multiply(mat5);
svgTL.getItem(0).setMatrix(svgM);

</snip>

thanks,
plb
PAUL LOGASA BOGEN II
Programmer

KNOWLEDGE BASED SYSTEMS, INC.
1408 University Drive East
College Station, Texas 77840
Phone: 979-260-5274
Fax: 979-691-2928
www.kbsi.com
<file:///C:/Documents%20and%20Settings/plbogen/Application%20Data/Micros
oft/Signatures/www.kbsi.com> 

 

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