It is currently Sun Feb 25, 2018 8:43 pm

 Page 1 of 1 [ 2 posts ] 
Author Message
 Post subject: 2-D Drawing - Resizing a rotated shape
PostPosted: Tue Jun 16, 2009 5:05 pm 

Joined: Tue Jun 16, 2009 4:41 pm
Posts: 1
I am developing an application in which the user is allowed to draw primitives on the screen (ellipses, rectangles, lines, polylines etc).

The application allows a user to move, rotate, and resize a shape. Everything works correctly, except when I attempt to resize a rotated shape.

My rectangle and ellipse is expressed as a point array of size two.


The first point represents the top left point of my shape and the second point the bottom right point of my shape. I can draw an ellipse or rectangle just by knowing these two points.

The problem I am having is that rotation is expressed by:

x' = cx + (x * cos(Theta)) - (y * sin(Theta));
y' = cy + (x * sin(Theta)) + (y * cos(Theta));

As I am resizing the value of cx, cy is changing since the centre of my shape is changing thus causing the shape to appear to "float" across the screen instead of it being anchored (as in MS Word).

I tried removing the centre x, y coordinates from the equation and just use (0,0) as the origin when the user is resizing a rotated shape:

x' = (x * cos(Theta)) - (y * sin(Theta));
y' = (x * sin(Theta)) + (y * cos(Theta));

This seems to work correctly (shape remains anchored), but unfortunately the entire shape moves to another location along the perimeter of my imaginary circle with centre at (0,0).

Has anyone ever dealt with this problem before? Is there a way to compensate for the shape being moved to another location? Or is there another solution to this problem? I am not using matricies.



 Post subject:
PostPosted: Tue Jun 16, 2009 6:59 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1106
Location: Ontario Canada
When compounding transforms for translations, centre, rotation and scaling, you'll see that I forumlate my matrix by doing the following:

M = (T C R S C^)

T = translation
C = offset by the centre
R = Rotation
S = scaling
C^ = inverse of the centre (move in the -C direction)

This is explained in detail in GameEngine VMK21D Node Transform

Display posts from previous:  Sort by  
 Page 1 of 1 [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to: