Hi Paul,
"Paul L. Bogen" <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]