0

I have a shape and a vector of shape's points, and I want to zoom in/out (resize whatever) the shape by dragging the mouse from a point of the shape to other random point (like in windows point for example)

What I search e read is that to scale a shape you have to recalculate all coordinates to:

xScaled = firstX * scaleX

yScaled = firstY * sclaleY

My problem is how to find that scale factor, what is the formula? Remebering that I have acess to the firstHitPoint, the actual point and all the points of the shape, and I have to do this by dragging the mouse.

Here is a peaceof my code:

@Override
public void transformPoints() {
    findTransformationFactors();

    int size = points.size();
    for(int i = 0; i < size; i++) 
        points.set(i, new Point(points.get(i).x * scaleX, points.get(i).y * scaleY));

}

@Override
public void findTransformationFactors() {
    int oldx = firstHitPoint.x;
    int oldY = firstHitPoint.y;

    int actualX = actualPoint.x;
    int actualY = actualPoint.y;

    scaleX = ??
    scaleY = ??

}
Silva_PT_SCP
  • 557
  • 2
  • 8
  • 20
  • 1
    For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example). In this case it would provide a template to allow people to play with ideas. – Andrew Thompson Oct 26 '14 at 01:52
  • Use `createTransformedShape()` as suggested [here](http://stackoverflow.com/q/23644698/230513) – trashgod Oct 26 '14 at 05:37

1 Answers1

0

The X factor taking the center as a constant point:

xVar = (initial.getX()-mouse.getX())/(center.getX()-initial.getX());
scaleX=xVar+1.0;

Then you must control that the scale applied is not negative --> avoid mirror transform

Kim Sant
  • 386
  • 4
  • 7