Jump to content
  • Advertisement
Sign in to follow this  
Polyphemus

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.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!