This chapter provides information on how to transform bodies and profiles.
Facet Modeler allows you to perform five basic transformations on objects: scaling, translating, rotating, stretching and mirroring. All transformations are performed via matrices, so in order to transform, say a profile, first you need to create a corresponding matrix. For more information, see the examples below.
To transform a body, use the transform() method:
void transform(const OdGeMatrix3d& mMatrix);
OdGeMatrix3d has functions that help create matrices. Since all basic transformation matrices look very similar and have only two (or three in the 3D case) coefficients that vary, these functions ask only for the varying elements. You can also put several transformations into one matrix.
Function Name | Parameter | Description |
---|---|---|
setToTranslation(OdGeVector3d(dx, dy, dz))
|
OdGeVector3d
|
This function accepts a vector parameter that defines the direction in which the object is translated. The vector dimension depends on whether you are working with a body (3D) or a profile (2D).
When you work with a profile, create a two-dimensional vector OdGeVector2d(dx, dy) .
|
setToScaling(double coefficient)
|
double
|
This function accepts a scaling coefficient that defines how objects are scaled. If the coefficient is greater than 1, the object increases in size, otherwise it decreases. |
setToRotation(double angle, OdGeVector3d axis)
|
double, OdGeVector3d
|
This function accepts an angle that the object is rotated and an axis in the form of a vector, around which it is rotated. |
setToMirroring(OdGeLine3d line)
|
OdGeLine3d
|
This function accepts a line over which the object is mirrored. |
setToProduct(OdGeMatrix3d matrix1, OdGeMatrix3d matrix2)
|
OdGeMatrix3d, OdGeMatrix3d
|
This function accepts two matrices that are multiplied and returns a reference to the product. |
The following code snippet creates a cube with a side edgeLen
and scales it with a coefficient of 1/2 (halves its edge length):
Body scaledCube(const DeviationParams& devParams, double edgeLen) {
Body cube = Body::box(OdGePoint3d::kOrigin, OdGeVector3d(edgeLen, edgeLen, edgeLen));
OdGeMatrix3d matrix;
matrix.setToScaling(.5);
cube.transform(matrix);
return cube;
}
The following code snippet creates a cube with a side edgeLen
and translates, rotates and scales it:
Body transCube(const DeviationParams& devParams, double edgeLen) {
Body cube = Body::box(OdGePoint3d::kOrigin, OdGeVector3d(edgeLen, edgeLen, edgeLen));
OdGeMatrix3d matrix1, matrix2, matrix3, resMatrix;
matrix1.setToScaling(.5);
matrix2.setToRotation(OdaPI / 6, OdGeVector3d::kXAxis);
matrix3.setToTranslation(OdGeVector3d(50.0, 50.0, 50.0));
resMatrix = resMatrix.setToProduct(matrix1, matrix2);
resMatrix = resMatrix.setToProduct(resMatrix, matrix3);
cube.transform(resMatrix);
return cube;
}
The createCube()
function was implemented in the topic about creating basic objects.
To transform a profile, use the transformBy() method:
Result transformBy(const OdGeMatrix2d& mMatrix, const DeviationParams& devDeviation = FMGeGbl::gDefDev);
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|