Scaling Rotated Points
-
I'm developing a vector graphics app and I'm trying to find the most efficient way to scale a rotated shape. As an example, lets say the user adds a rectangular shape to the drawing surface. Once they rotate the shape to, say 45 degrees, how can I most effeciently perform scaling once they decide to resize the shape? My current solution is to get the amount of pixels the mouse has moved, then rotate the shape back to 0 degrees, then offset the points by the delta amount, then rotate the points back to the current rotation. I don't think this is the best method because if the user has created a complex polygon and rotates it, I may end performing thousands of calculations! Can anybody help me?
My code this week has no errors. But it's Monday morning and I haven't got out of bed.
-
I'm developing a vector graphics app and I'm trying to find the most efficient way to scale a rotated shape. As an example, lets say the user adds a rectangular shape to the drawing surface. Once they rotate the shape to, say 45 degrees, how can I most effeciently perform scaling once they decide to resize the shape? My current solution is to get the amount of pixels the mouse has moved, then rotate the shape back to 0 degrees, then offset the points by the delta amount, then rotate the points back to the current rotation. I don't think this is the best method because if the user has created a complex polygon and rotates it, I may end performing thousands of calculations! Can anybody help me?
My code this week has no errors. But it's Monday morning and I haven't got out of bed.
Hi, this is one approach: - create an abstract base class that represents a drawable item; give it a Transformation Matrix member that initially is set to the unity matrix. - derive all drawable items (lines, rectangles, circles, ...) from it; in the Paint handler, apply the transformation matrix to your Graphics object before drawing the object. - when one or more drawable items are selected and a transformation gets ordered (translation, rotation, scaling) adjust the matrix for each selected object, i.e. calculate the matrix that represents the new transformation and combine it with the individual matrices. The main problem that remains now is mapping mouse positions to the relevant drawable item; there is no inverse matrix so you can't directly go from mouse position to item; you have to enumerate the items, for each enumerate the clickable parts (points, edges, surfaces), apply the transformation to them and check for a mouse hit. Hope I made this sufficiently clear. :)
Luc Pattyn [Forum Guidelines] [My Articles]
I use ListBoxes for line-oriented text output (not TextBoxes), and PictureBoxes for pictures (not drawings).
-
Hi, this is one approach: - create an abstract base class that represents a drawable item; give it a Transformation Matrix member that initially is set to the unity matrix. - derive all drawable items (lines, rectangles, circles, ...) from it; in the Paint handler, apply the transformation matrix to your Graphics object before drawing the object. - when one or more drawable items are selected and a transformation gets ordered (translation, rotation, scaling) adjust the matrix for each selected object, i.e. calculate the matrix that represents the new transformation and combine it with the individual matrices. The main problem that remains now is mapping mouse positions to the relevant drawable item; there is no inverse matrix so you can't directly go from mouse position to item; you have to enumerate the items, for each enumerate the clickable parts (points, edges, surfaces), apply the transformation to them and check for a mouse hit. Hope I made this sufficiently clear. :)
Luc Pattyn [Forum Guidelines] [My Articles]
I use ListBoxes for line-oriented text output (not TextBoxes), and PictureBoxes for pictures (not drawings).
Thanks for the reply. I've toyed around with using the matrix class but I can't seem to justify transforming a whole collection of shapes every time I need the coordinates. The transforms would also have to be applied on every paint operation. This seems to be too much of a cpu hog. I wish I had a more firm grip on trigonomerty so the points could be scaled along the rotational axis.
My code this week has no errors. But it's Monday morning and I haven't got out of bed.
-
Thanks for the reply. I've toyed around with using the matrix class but I can't seem to justify transforming a whole collection of shapes every time I need the coordinates. The transforms would also have to be applied on every paint operation. This seems to be too much of a cpu hog. I wish I had a more firm grip on trigonomerty so the points could be scaled along the rotational axis.
My code this week has no errors. But it's Monday morning and I haven't got out of bed.
Hi, if you don't want to store and re-apply the transformation matrices on every paint or mouse action, you will have to store actual coordinates in the derived class, and modify those when you apply a new transformation. The logic required to transform a single point can still be implemented once in the base class, and used in the derived classes as often as is required. :)
Luc Pattyn [Forum Guidelines] [My Articles]
I use ListBoxes for line-oriented text output (not TextBoxes), and PictureBoxes for pictures (not drawings).
-
I'm developing a vector graphics app and I'm trying to find the most efficient way to scale a rotated shape. As an example, lets say the user adds a rectangular shape to the drawing surface. Once they rotate the shape to, say 45 degrees, how can I most effeciently perform scaling once they decide to resize the shape? My current solution is to get the amount of pixels the mouse has moved, then rotate the shape back to 0 degrees, then offset the points by the delta amount, then rotate the points back to the current rotation. I don't think this is the best method because if the user has created a complex polygon and rotates it, I may end performing thousands of calculations! Can anybody help me?
My code this week has no errors. But it's Monday morning and I haven't got out of bed.
-
Thanks for the reply. I've toyed around with using the matrix class but I can't seem to justify transforming a whole collection of shapes every time I need the coordinates. The transforms would also have to be applied on every paint operation. This seems to be too much of a cpu hog. I wish I had a more firm grip on trigonomerty so the points could be scaled along the rotational axis.
My code this week has no errors. But it's Monday morning and I haven't got out of bed.
If its a CPU hog, consider buffering or picking a framework like Piccolo or WPF which takes care of most of the details for you. An affine transform matrix can almost be seen as a cache of how the input vertex relates to the output vertex. I would expect that performing the actual trig operation on every vertex would be quite slow indeed. Take a look at the graphics primer that the Piccolo project provides, you'll probably find it fairly helpful.
Mark Churchill Director, Dunn & Churchill Pty Ltd Free Download: Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.
Entanglar: .Net game engine featuring automatic networking and powerful HLSL gfx binding.