realbasic-games
[Top] [All Lists]

Re: Drawing Rotated Image

To: REALbasic Games <realbasic-games at lists dot realsoftware dot com>
Subject: Re: Drawing Rotated Image
From: "Joseph J. Strout" <joe at realsoftware dot com>
Date: Fri, 23 Sep 2005 08:17:27 -0600
Delivered-to: realbasic-games at lists dot realsoftware dot com
References: <496bf51a05092019337180466a at mail dot gmail dot com> <a06200704bf567b8c2eb0 at 10 dot 0 dot 1 dot 4> <496bf51a0509211826355b31bb at mail dot gmail dot com> <a06200702bf57caa5de4d at 10 dot 0 dot 1 dot 4> <496bf51a050922191027900e59 at mail dot gmail dot com>
At 9:10 PM -0500 9/22/05, Andrew Krebs wrote:

Is there a way to find out at what x,y to draw the rotated image, so
that it is drawn as close to 0,0 as possible.

Ah, yes, that just requires a bit of trigonometry. If you know which quadrant you're going to rotate it into, you can do this simply: for example, just calculate the Y position of the top-left corner, and the X position of the bottom-left corner, and shift your drawing by that much.

If you don't know how much it'll be rotated, then you'll have to calculate the position of all four corners, and find the minimum X and Y of the set. Then shift by that much.

Let's see, I haven't had my coffee yet so I'm not sure this is the simplest way to do it, but one way to find the rotated position of a corner is to first convert it into polar coordinates (r = sqrt(dx^2+dy^2), ang = ATan2(dx,dy)), then add the rotation amount to the angle (ang), and convert back to cartesian coordinates (dx2 = r*cos(ang), dy2 = r*sin(ang)).

Nothing that can't be solved with a little math!   :)

HTH,
- Joe

--
Joe Strout                          REAL Software, Inc.

Vote for REALbasic (twice!) in the LinuxWorld Reader's Choice Awards:
http://linux.sys-con.com/general/readerschoice.htm
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>