Hi Paul, "Paul L. Bogen" <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED] > Sent: Wednesday, July 11, 2007 12:13 PM > To: [email protected] > 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:[EMAIL PROTECTED] > Sent: Wednesday, July 11, 2007 12:53 PM > To: [email protected] > 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:[EMAIL PROTECTED] > Sent: Wednesday, July 11, 2007 11:51 AM > To: [email protected] > 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:[EMAIL PROTECTED] > Sent: Wednesday, July 11, 2007 12:32 PM > To: [email protected] > 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:[EMAIL PROTECTED] > Sent: Wednesday, July 11, 2007 9:37 AM > To: [email protected] > 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:[EMAIL PROTECTED] > Sent: Tuesday, July 10, 2007 12:13 PM > To: [email protected] > 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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
