# calculate width and height

This topic is 4771 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
Quote:
 Original post by PolyphemusI'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]

Thank you :)

##### Share on other sites
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.

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631706
• Total Posts
3001833
×