calculate width and height
I've a square image, 40x40. I want to shear it with 0.4, rotate it 45 degrees and scale y with 0.6. I want to calculate the height and width of it, to create an image where the sheared, rotated and scaled square can fit in. How can i calculate this?
TIA, Polyphemus.
BTW, i'm using java with the Graphics2D library.
Quote:Original post by Polyphemus
I've a square image, 40x40. I want to shear it with 0.4, rotate it 45 degrees and scale y with 0.6. I want to calculate the height and width of it, to create an image where the sheared, rotated and scaled square can fit in. How can i calculate this?
TIA, Polyphemus.
BTW, i'm using java with the Graphics2D library.
I'm guessing 0.4 and 0.6 are 40% and 60%? I've never used graphics2d, this is code i'd use to do it though:
tempwidth=oldwidth+0.4oldwidth; /* the total shear width is gonna equal the original swidth + the shear */tempheight=oldheight; /* shearing shouldn't affect the height... */newwidth=tempwidth*cos(theta)+tempheight*cos(90-theta);newheight=tempwidth*sin(theta)+tempheight*sin(90-theta);/* here, we project the width onto the x axisto get the width of the right portion of theimage. then, we project the side height ontothe x axis as well to get the rest of it. thenwe do the same ofr the y axis*/tempwidth=newwidth;tempheight=newheight*0.6;// since you said 'and scale y with 0.6' herei actually scale the height down by 0.6 insteadof adding the original height, like before
tempwidth and tempheight are your final width and height
[Edited by - Uthman on June 22, 2005 8:19:40 AM]
as for a general algo, I'd keep track of the the corners of the image after each transform, and calculate the bounding box around the corners.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement