# How to scale or mirror a shape

With older occ versions i mirrored (maybe rather clumpsy) shapes by setting a `TopLoc_Location` with a scale of -1.0, f.e. such a transformation matrix:

``````1  0 0
0 -1 0
0  0 1
``````

or simply uniformly scaled shapes (mostly with values > 0).

Newer versions don't don't allow this because of this fix (0027457: Modeling - Raise exception if scaled transformation is used for shape location)

The fact is that use of transformations with non-unit scale factor in shape locations (e.g. method TopoDS_Shape::Moved()) is not well supported in OCCT: in most cases (especially if underlying geometry is elementary) this will lead to invalid shape, and most algorithms will fail due to being not able to handle effect of scaling on parameterization. It is quite regular that users get confused by this possibility (see e.g. https://github.com/tpaviot/oce/issues/615).

To prevent confusion, we can raise exception when scaled transformation is used for shape (e.g. in TopLoc_Location).

with this new source code which throws a domain error exception for such cases:

``````  void Location (const TopLoc_Location& theLoc, const Standard_Boolean theRaiseExc = Standard_True)
{
const gp_Trsf& aTrsf = theLoc.Transformation();
if ((Abs(Abs(aTrsf.ScaleFactor()) - 1.) > TopLoc_Location::ScalePrec() || aTrsf.IsNegative()) && theRaiseExc)
{
//Exception
throw Standard_DomainError("Location with scaling transformation is forbidden");
}
else
{
myLocation = theLoc;
}
}
``````

Is there another way to scale shapes (maybe also along X, Y, Z or even arbitrary axes) or, which might be a simpler case, "mirror" along X, Y, or Z?

Hello,

To make any tranformation on shape you can use "BRepBuilderAPI_Transform" which get gp_Trsf or "BRepBuilderAPI_GTransform" which get "gp_GTrsf".

Best regards, Dmitrii.

Use BRepBuilderAPI_Transform and BRepBuilderAPI_GTransform algorithms to perform such transformations.