locked
Scaling Transform Help RRS feed

  • Question

  • I'm having a bit of a problem getting my math right and know that there are folks here that know math better and matrix transforms better then myself, so help is requested...and greatly appreciated.

     

    I have a window that shows part of a large control area containing lots of information. I have a mini-Map that represents the full view with a "current view frame" within it.  The full mini-map is a 1/20th representation of the full view.  You can zoom in (scaleX in 0.1 increments 3 times) and you can zoom out (in 0.25 increments 4 times).  Everything is working great as I translate things from FullView to the Mini-Map (eg, my translations/conversions are working great that way).  However, when I try to translate values from the mini-Map to the currentView I'm not getting correct representations if I am scaled in or out.  (eg, If I scroll around or click/drag around the current view, zoomed in/out, the correct movement is mirrored in the miniMap, but if I zoom in/out and try to move my view using the mini-Map the mirror in the current view is way off).

     

    I'm hoping that I've given enough information to get some help.  I can post more information to help clarify my issue as needed.

     

    Thanks ahead of time.

     

    -Status



     

    Friday, June 13, 2008 2:05 PM

Answers

  • Hello, if you don't post any code, it's very difficult for us to get what you want. Anyway, here's the formula: To make things easy, you can use a ScaleTransform together with a TranslateTransform. You can set the ScaleTransform's CenterX/Y to 0,0 so the formula will be simplified. With CenterX/Y not equal to 0,0, the formula is:

    x' = ScaleX * (x - CenterX) + CenterX

    y' = ScaleY * (y - CenterY) + CenterY

    With CenterX/Y equal to 0,0, however, the formula is simply:

    x' = ScaleX * x

    y' = ScaleY * y

    Then you can add the TranslateTransform. The complete formula is:

    x' = ScaleX * x + TranslateX

    y' = ScaleY * y + TranslateY

    Monday, June 16, 2008 1:57 AM
  • Actually, that was what I thought I had in place.  On double checking, I had a copy paste error that was causing it.

     

    Thanks! 

    Monday, June 16, 2008 11:11 AM

All replies

  • Do you see any pattern in how the positioning is off?  For example, I had a scaling issue a few days ago, and so I did a bunch of tests placing objects on my canvas and seeing where the offset position actually was, and there was a clear pattern.  Once I identified the pattern, it became easier to fix.

    It would also help to see your calculation code.

    Friday, June 13, 2008 2:43 PM
  • Hello, if you don't post any code, it's very difficult for us to get what you want. Anyway, here's the formula: To make things easy, you can use a ScaleTransform together with a TranslateTransform. You can set the ScaleTransform's CenterX/Y to 0,0 so the formula will be simplified. With CenterX/Y not equal to 0,0, the formula is:

    x' = ScaleX * (x - CenterX) + CenterX

    y' = ScaleY * (y - CenterY) + CenterY

    With CenterX/Y equal to 0,0, however, the formula is simply:

    x' = ScaleX * x

    y' = ScaleY * y

    Then you can add the TranslateTransform. The complete formula is:

    x' = ScaleX * x + TranslateX

    y' = ScaleY * y + TranslateY

    Monday, June 16, 2008 1:57 AM
  • Actually, that was what I thought I had in place.  On double checking, I had a copy paste error that was causing it.

     

    Thanks! 

    Monday, June 16, 2008 11:11 AM