Hero made of parts 2d rotation

I have a problem with rotation of my hero in 2D space. The hero is made of body parts such as: head, arms etc. Every part is a separate sprite. When I want to rotate the hero, I have to rotate all of its parts.

I know the hero position, and I save the parts positions as:

In other words I know the positions of all parts while the hero was not rotated. After rotation I know only the hero position and the rotation angle(Grades).

How can I calculate the new position for each part? This problem is called Forward Kinematics. To solve this problem in general, I recommend creating what is called a Kinematic Chain, or Kinematic Tree. To do this, you will need knowledge of a 2D rotation matrix, or transformation matrix.

A 2D 3x3 transformation matrix is defined as:

H = [xx, xy, tx;
yx, yy, ty;
0,  0,  1];

In this case, [xx, yx] represents the x axis of the transformation, [xy, yy] represents the y axis, and [tx, ty] represents the translation of the transformation. For instance, the transformation:

H = [1, 0, 1;
0, 1, 0.5;
0, 0, 1];

translates a part 1 unit in the x direction, and 0.5 units in the y direction. To transform any vector, just pre-mulltiply it by the transformation matrix H. A special case of the transformation matrix is the rotation matrix. In 2D, a pure rotation can be represented as:

H = [cos(theta), -sin(theta), 0;
sin(theta),  cos(theta), 0;
0,           0, 1];

where theta is the rotation value in Radians.

Now, to implement a Kinematic tree, you just need to do this:

// Represents a rigid link in a kinematic chain
{
public:
// The "root" of the tree has no parent (NULL)
// All links can have as many children as needed

// Represents the transform from the parent link to
Matrix3x3 localTransform;
// Reprsents the transform from the world to this link.
Matrix3x3 globalTransform;

// Computes the global transform of this link with respect
// to the world. Then computes the global transforms of all
// children.
void ComputeTransformsRecursive()
{
// If we're the root link, the global transform is the local transform.
if(!parent) globalTransform = localTransform;
else
{
// Otherwise, the global transform is the parent's global transform
// times our transform (matrix multiplication)
globalTransform = parent->globalTransform * localTransform;

// Now recursively compute the global transform for each of the children
{
}
}
}

}

To build the kinematic tree for your character, you just do this:

// The body is the base link, and starts at (0, 0) with 0 rotation.

// The left arm, relative to the body, is 50 pixels to the right and 10 up,
// with no local rotation.
leftArm->localTransform = Matrix3x3::CreateTranslation(50, 10);

// The right arm is 50 right and 10 down.
rightArm->localTransform = Matrix3x3::CreateTranslation(50, -10);

// The head is 10 right and 0 down

You can rotate/translate the entire character just by moving around the body link:

Then, to update, you just need to do this: