# How do I rotate an object around another object with an angle and an offset?

I made a small game engine with a hierarchy, but have a with problem with applying transform down the hierarchy. I have an object with a parent, and I want the child to rotate around the parent with an offset (the childs localPosition, relative to the parent, and a parent rotation).

For example, I have a parent "Earth", and a child "Moon". The "Earth" rotates, and the "Moon" rotates with a 100, 50 offset.

How do I rotate an object around another object with an angle and an offset?

Each object has:

• x / y localPosition
• private x / y globalPosition
• localRotation
• private globalRotation

This is what I have, so far:

float atr = Deg2Rad(parent->GetGlobalRotation());
globalPosition.x = parent->GetGlobalPosition().x + cos(atr) * localPosition.x;
globalPosition.y = parent->GetGlobalPosition().y + sin(atr) * localPosition.y;


but it only only on the x-axis if localPositon is 50, 0

globalPosition.x = parent.GetGlobalPosition().x