.. role:: blue :class: blue Constructing a Transformed Body =============================== .. _Constructing_a_Transformed_Body_: .. kernel version: 118058 The function .. code-block:: cpp MbResultType TransformedSolid( MbSolid & solid, MbeCopyMode sameShell, const TransformValues & p, const MbSNameMaker & names, MbSolid *& result ) performs a transformation of a source body by a given matrix calculated from the bounding cube. The input parameters of the function are: - **solid** is the source body. - **sameShell** is a mode of copying the source body. - **p** is the transformation parameters. - **names** is a name maker of the operation. The output parameter of the function is the modified body **result**. If succeessful, the function returns :blue:`rt_Success`; otherwise, it returns an error code from the :ref:`MbResultType ` enumeration (see *mb_operation_result.h*). The function is declared in the *action_direct.h* file. When creating the **p** object with the transformation parameters, one of the following constructors is used (see *op_shell_parameter.h*): Default constructor: .. code-block:: cpp TransformValues() : matrix() , fixedPoint() , useFixed( false ) , isotropy( false ) {} Constructor by a matrix: .. code-block:: cpp TransformValues( const MbMatrix3D & m ) : matrix( m ) , fixedPoint() , useFixed( false ) , isotropy( false ) {} Constructor by a matrix and a fixed transformation point: .. code-block:: cpp TransformValues( const MbMatrix3D & m, const MbCartPoint3D & f, bool fix = false, bool iso = false ) : matrix( m ) , fixedPoint( f ) , useFixed( fix ) , isotropy( iso ) {} Constructor by a fixed transformation point and scale factors along axes: .. code-block:: cpp TransformValues( double sX, double sY, double sZ, const MbCartPoint3D & fP ); Copy constructor: .. code-block:: cpp TransformValues( const TransformValues & other ) : matrix ( other.matrix ) , fixedPoint( other.fixedPoint ) , useFixed ( other.useFixed ) , isotropy ( other.isotropy ) {} The function scales the body by a matrix with equal or different scale factors along the axes of the global coordinate system. The **solid** parameter contains the source body to be processed. The **sameShell** parameter controls data copying from the source body **solid** to the resulting body **result** (see :ref:`Copying_a_Set_of_Faces `). The **p** parameter contains a transformation matrix **p**.\ *matrix* and values **p**.\ *fixedPoint*, **p**.\ *useFixed*, **p**.\ *isotropy*, which are used for calculating the transformation matrix. The :blue:`TransformValues` transformation parameter is declared in the *op_shell_parameter.h* file. The **names** parameter is used for naming body elements. The transformation matrix is calculated from the bounding cube of the source body **solid** and from a displacement of one of the points of the bounding cube by the method: .. code-block:: cpp bool MbCube::CalculateMatrix( size_t pIndex, const MbCartPoint3D & point, const MbCartPoint3D & fixedPoint, bool useFixed, bool isotropy, MbMatrix3D & matrix ) const; where - **pIndex** is the index of a point of the bounding cube to be displaced; - **point** is a space point to which the point of the bounding cube with index **pIndex** shall be connected; - **fixedPoint** is a fixed transformation point (used if **useFixed** = *true*); - **useFixed** is a flag for using a fixed point; - **isotropy** is a flag for equal transformation scale factors; - **matrix** is the calculated transformation matrix. Figure 1 shows the numbering of the points of the bounding cube of the **solid** body. The vertices of the bounding cube have indices 0–7, the midpoints of the edges of the bounding cube have indices 8–19, and the centers of the faces of the bounding cube have indices 20–25. .. figure:: /MODELER/DIRECT_MODELING_METHODS/pictures/M.6.1.1.png :width: 12cm :align: center Fig. 1 The transformation matrix **matrix** is calculated from a deformed cube obtained by moving the point of the bounding cube with index **pIndex** to the space point **point**. If **useFixed** = *true*, the fixed transformation point is the **fixedPoint** point. If **useFixed** = *false*, the fixed transformation point is the point of the bounding cube opposite to the point with index **pIndex**. The following pairs of points of the bounding cube are considered opposite: 0–6, 1–7, 2–4, 3–5, 8–14, 9–15, 10–12, 11–13, 16–18, 17–19, 20–21, 22–23, 24–25. If **isotropy** = *true*, the transformation scale factors along all axes are equal and proportional to the displacement vector of the point of the bounding cube with index **pIndex**. If **isotropy** = *false*, the transformation scale factors are proportional to the projections of the displacement vector of the point of the bounding cube with index **pIndex** onto the edges of the bounding cube. The values **p**.\ *fixedPoint*, **p**.\ *useFixed*, **p**.\ *isotropy* and **p**.\ *matrix* are used as the **fixedPoint**, **useFixed**, **isotropy** and **matrix** parameters of the :blue:`CalculateMatrix`\() method. Figure 2 shows the source body **solid**, the points of the bounding cube, and the space point **point** to which the specified point of the bounding cube shall be moved, and Figure 3 shows the transformed body **result** constructed by the function under consideration with the parameters **useFixed** = *false* and **isotropy** = *false*. .. figure:: /MODELER/DIRECT_MODELING_METHODS/pictures/M.6.1.2.png :width: 12cm :align: center Fig. 2 .. figure:: /MODELER/DIRECT_MODELING_METHODS/pictures/M.6.1.3.png :width: 12cm :align: center Fig. 3 A body can also be transformed by a given matrix by the :blue:`Transform`\() method, which is overloaded in all geometric objects including :blue:`MbSolid`, but in this case the body will not contain any information about the performed operations. The :blue:`TransformedSolid`\() function adds the :blue:`MbTransformedSolid` builder to the history of the resulting body. The :blue:`MbTransformedSolid` builder is declared in the *cr_transformed_solid.h* file. The test application *test.exe* constructs a transformed body by the menu command “Create → Body → By direct editing → Transformation of bounding box”.