3

I'm trying to figure out the algorithm for scaling multiple selected objects on a canvas (similar to Visio's behavior). Say for instance I have the following selected objects in my application:

I then drag the lower-right handle of the bounding box to increase the size of the selected objects and thus produce the following results:

enter image description here

My questions are as follows:

  1. How do I get the amount of scaling to be applied to each object?
  2. How do I get the amount of translation to be applied to each object?

I hope this question makes sense. And I hope you could help.

ASanch
  • 10,233
  • 46
  • 32

1 Answers1

0

Hi I dont think there is any Translation , There is only Scaleing . One easy way to do that is preserve the Width and Height of your object like (TextBoxes above) and then when you want to get Scaleing values of that object

ScaleTransform scale = new ScaleTransform();
        //_text is the scaled object
        scale.ScaleX = text.ActualWidth - _width; //_width is width of the textbox at beginning.
        scale.ScaleY = text.ActualHeight - _height; //_height is the height of textbox at the beginning.

This will give you the amount by which object is scaled corressponding to the Width and Height of TextBox at the beginning (i.e When window initialized) . I hyope this will give you an idea.

yo chauhan
  • 12,079
  • 4
  • 39
  • 58
  • Actually, I believe there is. Consider this: http://imgur.com/FVIwL. Here, the object rotated at 90 degrees will have to be translated so that it stays in the corner of the bounding rectangle. This picture also shows that using the formula you have above will not really be enough in computing the ScaleX and ScaleY of the objects. In the picture, only the width of the bounding box was adjusted. But it was the 90 degree object's height that was scaled instead of its width. So really, the rotation angle of the objects relative to the bounding box will have to be considered as well. – ASanch Jul 27 '12 at 16:08
  • Yes in that image there is translation but no Scaling in that image. Translation does not reform the image it only reposition the object by increasing or decreasing each and every pixel of that object by same amount (i.e Height and Width will remain same as that in beginning) – yo chauhan Jul 27 '12 at 16:20
  • Well, I believe there's also scaling in that image. It's just not too obvious. Consider a slightly modified example: http://i.imgur.com/6dCQW.png. Here, we resized the bounding rectangle to be 2x the original size. The 90 degree object in this picture was scaled (i.e. it's height was 2x the original) and translated as well. – ASanch Jul 27 '12 at 16:41
  • Yes now in this image there is both Scaleing and Transformation. – yo chauhan Jul 27 '12 at 17:01