Rotating a Part in a Product Using Coordinate Transformations
When rotating a part within a product, the key is to apply a rotation transformation. Here’s a step-by-step approach to achieve this:
Steps to Rotate a Part:
-
Retrieve the Part’s Absolute Transform
First, obtain the part’s absolute transformation matrix in the product. This matrix defines the part’s position and orientation relative to the product’s coordinate system. -
Determine the Absolute Rotation Axis
Identify the mathematical axis (e.g., X, Y, or Z) around which you want to rotate the part. However, since the part may have a transformation relative to the product, you need to calculate its absolute axis in the product’s coordinate system.
How?
Multiply the part’s local axis vector by its absolute transformation matrix to convert it to the product’s coordinate system. -
Construct the Rotation Transformation
Create a rotation transformation matrix using the absolute axis and the desired rotation angle. -
Apply the Transformation
Combine the rotation matrix with the part’s existing transformation and update the part’s position in the product.
Key Issue: Calculating the Absolute Rotation Axis
A common mistake is assuming the rotation axis is defined purely in the part’s local coordinate system. However, if the part has a reflective transformation (e.g., mirrored), its local axis must be converted to the product’s absolute coordinate system.
Formula:
CATBool GetAbsPositionOfAxisInAsm(const CATIProduct_var ispProduct, const CATIGSMAxisLine_var ispAxis, CATMathLine &oMathLine)
{
std::cout << "AsmStruct::GetAbsPositionOfAxisInAsm" << "--->" << std::endl;
if (!ispProduct || !ispAxis)
{
std::cout << "AsmStruct::GetAbsPositionOfAxisInAsm" << "--->" << "Parameters are null" << std::endl;
return FALSE;
}
// Get the absolute coordinate matrix of the current part
CATIMovable_var spMovable = NULL_var;
spMovable = ispProduct;
if (!spMovable)
{
std::cout << "AsmStruct::GetAbsPositionOfAxisInAsm" << "--->" << "Part does not exist" << std::endl;
return FALSE;
}
CATMathTransformation Pos; // Absolute coordinate matrix of the part
spMovable->GetAbsPosition(Pos);
// Get the math line of the axis
CATLine_var spLine = NULL_var;
spLine = ispAxis;
if (!spLine)
{
std::cout << "AsmStruct::GetAbsPositionOfAxisInAsm" << "--->" << "Axis does not exist" << std::endl;
return FALSE;
}
CATMathPoint p;
spLine->GetOrigin(p);
CATMathDirection d;
spLine->GetDirection(d);
CATMathLine line(p, d);
oMathLine = Pos * line;
return TRUE;
}
// Get rotated transformation matrix based on rotation angle and axis
CATMathTransformation GetRotateMatrix(CATMathTransformation iMathTransformation, double angle, const CATMathLine &line)
{
std::cout << "AsmStruct::GetRotateMatrix" << "--->" << std::endl;
// Convert angle value to radians
double M_PI = 3.14159;
double dAngle = angle / 180 * M_PI;
CATAngle ang(dAngle);
CATMathTransformation trans(ang, line);
CATMathTransformation trans1;
trans1 = trans * iMathTransformation;
return trans1;
}

浙公网安备 33010602011771号