# Rotate () like earth around sun

Hello every one…
Is it possible to rotate an object around imself and around a other point on the same time?
Thank’s a lot.

1 Like

The easiest way to do this would probably be to apply two `translate` and two `rotate` transformations to your object (or planet, in your case), like this:

``````translate(centerX, centerY); // move anchor point to the center
rotate(rotation1);           // rotate the planet around the center
translate(distanceToCenter); // move anchor point to planet position
rotate(rotation2);           // rotate planet around itself
``````

You would then increment the rotations every frame.
However this only works if you want the planet to follow a circle. Real planets move on elliptical paths. If you want to have this behavior, you’ll need to use `cos` and `sin`.

1 Like

Thank’s it’s working

Hello,

My “quick” initial approach to this…

``````float x, y;
float theta1;
int i;
float a, b;

void setup()
{
size(700, 500);
a = 200;
b = 150;
}

void draw()
{
background(0);
translate(width/2, height/2);
i++;
theta1 = i*TAU/500;
x = a*cos(theta1);
y = b*sin(theta1);
strokeWeight(10);
stroke(255, 255, 0);
point(x, y);

// Additional code; similar to above but new orbits were translated OR added to previous points.
}
``````

I started with the above code and kept adding additional orbits around the rotating point.

1 Like

You could maybe use a PVector with the distance as x, y as 0, and then rotate this Vector.

``````PVector rotation;

void setup() {
size(400, 400);
rotation = new PVector(50, 0);
}

void draw() {
translate(width/2, height/2);

noStroke();
fill(255, 220, 0);
ellipse(0, 0, 20, 20);

fill(0, 255, 50);
ellipse(rotation.x, rotation.y, 20, 20);