ScaleBy

MGraphic::ScaleBy changes the size of a graphic by multiplying the graphic's coordinates by a constant value. It scales the graphic about the centerOfScale
by factor.

    virtual void MGraphic::ScaleBy( const TGPoint& factor, const TGPoint& centerOfScale );
factor: Factor determines the amount of scaling in the x and y directions for uniform and non-uniform scaling. Uniform scaling is when the x and y values are the same. Non-uniform scaling is when the x and y values are different.

centerOfScale: The center of scale determines the point around which the graphic is scaled. A center of scale other than the center of the graphic can scale the graphic beyond the visible area of the view.

Figure 25 shows a shape scaled three times with a different center of scale each time. The shape after it has been rotated is shown filled.


The following code fragments scale the shape by 50 percent.

Center of graphic

      shape->ScaleBy( TGPoint( 0.5, 0.5 ), shape->GetGeometricBounds().GetCenter() );
      shape->Draw( thePort );

Origin of view

The origin of the view is
TGPoint( 0,0 ).

    shape->ScaleBy( TGPoint( 0.5, 0.5 ), TGPoint::kOrigin ); shape->Draw( thePort );

TGPoint( 0, 200 )

    shape->ScaleBy( TGPoint( 0.5, 0.5 ), TGPoint( 0, 200 ) ); shape->Draw( thePort );
You might want to refer to a book on matrix multiplication, particularly a section on scaling matrices, to see how the new points are calculated for this example.

Negative scale factor

The effect of negative scale factors is the same as mirroring. Scaling by 1.0 in the x direction is similar to mirroring about the y-axis. A negative scale factor in the y direction is similar to mirroring about the x-axis.

Figure 26 shows the shape scaled by the factor (1.0, 1.0) using the center of the graphic for centerOfScale. The shape after it has been scaled is shown filled.


      shape->ScaleBy( TGPoint( -1.0, -1.0), shape->GetGeometricBounds().GetCenter() );
      shape->Draw( thePort );

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker