Sign in to follow this  
Polyphemus

calculate width and height

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 this post


Link to post
Share on other sites
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 axis
to get the width of the right portion of the
image. then, we project the side height onto
the x axis as well to get the rest of it. then
we do the same ofr the y axis*/

tempwidth=newwidth;
tempheight=newheight*0.6;

// since you said 'and scale y with 0.6' here
i actually scale the height down by 0.6 instead
of 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]

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this