# How-to: Rotate a CAD model along an axis

To rotate a whole model along an axis, it is needed to edit its root PO transformation (ie the corresponding A3DAsmProductOccurrenceData::m_pLocation) accordingly.
Below are some examples of code implementation:

``````enum Axis { X, Y, Z };  // 3D Axis

// Set-up a X rotation matrix
void SetXRotation(const A3DDouble radianAngle, A3DDouble *p4x4Matrix)
{
p4x4Matrix[0] = 1.0;	p4x4Matrix[4] = 0.0;			p4x4Matrix[8] = 0.0;			p4x4Matrix[12] = 0.0;
p4x4Matrix[1] = 0.0;	p4x4Matrix[5] = cos(radianAngle);	p4x4Matrix[9] = -sin(radianAngle);	p4x4Matrix[13] = 0.0;
p4x4Matrix[2] = 0.0;	p4x4Matrix[6] = sin(radianAngle);	p4x4Matrix[10] = cos(radianAngle);	p4x4Matrix[14] = 0.0;
p4x4Matrix[3] = 0.0;	p4x4Matrix[7] = 0.0;			p4x4Matrix[11] = 0.0;			p4x4Matrix[15] = 0.0;
}

// Set-up a Y rotation matrix
void SetYRotation(const A3DDouble radianAngle, A3DDouble *p4x4Matrix)
{
p4x4Matrix[0] = cos(radianAngle);	p4x4Matrix[4] = 0.0;	p4x4Matrix[8] = sin(radianAngle);	p4x4Matrix[12] = 0.0;
p4x4Matrix[1] = 0.0;			p4x4Matrix[5] = 1.0;	p4x4Matrix[9] = 0.0;			p4x4Matrix[13] = 0.0;
p4x4Matrix[2] = -sin(radianAngle);	p4x4Matrix[6] = 0.0;	p4x4Matrix[10] = cos(radianAngle);	p4x4Matrix[14] = 0.0;
p4x4Matrix[3] = 0.0;			p4x4Matrix[7] = 0.0;	p4x4Matrix[11] = 0.0;			p4x4Matrix[15] = 0.0;
}

// Set-up a Z rotation matrix
void SetZRotation(const A3DDouble radianAngle, A3DDouble *p4x4Matrix)
{
p4x4Matrix[0] = cos(radianAngle);	p4x4Matrix[4] = -sin(radianAngle);	p4x4Matrix[8] = 0.0;	p4x4Matrix[12] = 0.0;
p4x4Matrix[1] = sin(radianAngle);	p4x4Matrix[5] = cos(radianAngle);	p4x4Matrix[9] = 0.0;	p4x4Matrix[13] = 0.0;
p4x4Matrix[2] = 0.0;			p4x4Matrix[6] = 0.0;			p4x4Matrix[10] = 1.0;	p4x4Matrix[14] = 0.0;
p4x4Matrix[3] = 0.0;			p4x4Matrix[7] = 0.0;			p4x4Matrix[11] = 0.0;	p4x4Matrix[15] = 0.0;
}

// Function that apply a rotation to a modelFilea long an axis.
void applyRotationToModelFile(A3DAsmModelFile *pModelFile, A3DDouble rotationDegreeAngle, Axis rotationAxis)
{
A3DAsmModelFileData modelData;
A3D_INITIALIZE_DATA(A3DAsmModelFileData, modelData);
A3DAsmModelFileGet(pModelFile, &modelData);

A3DAsmProductOccurrenceData rootPoData;
A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, rootPoData);
A3DAsmProductOccurrenceGet(modelData.m_ppPOccurrences[0], &rootPoData);

A3DMiscGeneralTransformationData transfoData;
A3D_INITIALIZE_DATA(A3DMiscGeneralTransformationData, transfoData);

// We initialize an identity matrix

// We apply the rotation to the model
A3DDouble radianAngle = rotationDegreeAngle * M_PI / 180;

if (rotationAxis == X)

if (rotationAxis == Y)