# Rotate () like earth around sun

**URL:** <https://discourse.processing.org/t/rotate-like-earth-around-sun/16713>\
**Category:** Coding Questions\
**Created:** [December 29, 2019, 6:34pm UTC](https://discourse.processing.org/t/rotate-like-earth-around-sun/16713 "2019-12-29T18:34:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bouls631](https://avatars.discourse-cdn.com/v4/letter/b/6a8cbe/32.png) [@Bouls631](https://discourse.processing.org/u/Bouls631)\
**Post date:** [December 29, 2019, 6:34pm UTC](https://discourse.processing.org/t/rotate-like-earth-around-sun/16713/1 "2019-12-29T18:34:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DongKingKong0](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dongkingkong0/32/960_2.png) [@DongKingKong0](https://discourse.processing.org/u/DongKingKong0)\
**Post date:** [December 29, 2019, 6:47pm UTC](https://discourse.processing.org/t/rotate-like-earth-around-sun/16713/2 "2019-12-29T18:47:49Z")

</div>

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:

```auto
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`.

---

<div class="post-metadata">

**Author:** ![Bouls631](https://avatars.discourse-cdn.com/v4/letter/b/6a8cbe/32.png) [@Bouls631](https://discourse.processing.org/u/Bouls631)\
**Post date:** [December 29, 2019, 7:29pm UTC](https://discourse.processing.org/t/rotate-like-earth-around-sun/16713/3 "2019-12-29T19:29:44Z")

</div>

Thank’s it’s working

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 29, 2019, 7:41pm UTC](https://discourse.processing.org/t/rotate-like-earth-around-sun/16713/4 "2019-12-29T19:41:14Z")

</div>

Hello,

My “quick” initial approach to this…

```auto
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.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/86b010a8ed83dcd1e3fe4d8f527d3cfe67e6e560.png)

🙂

---

<div class="post-metadata">

**Author:** ![anon68884268](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon68884268](https://discourse.processing.org/u/anon68884268)\
**Post date:** [December 31, 2019, 2:43pm UTC](https://discourse.processing.org/t/rotate-like-earth-around-sun/16713/5 "2019-12-31T14:43:45Z")

</div>

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

```auto
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);

  rotation.rotate(radians(1));
}

```

---

<div class="post-metadata">

**Author:** ![Bouls631](https://avatars.discourse-cdn.com/v4/letter/b/6a8cbe/32.png) [@Bouls631](https://discourse.processing.org/u/Bouls631)\
**Post date:** [May 24, 2020, 7:40am UTC](https://discourse.processing.org/t/rotate-like-earth-around-sun/16713/6 "2020-05-24T07:40:57Z")

</div>

Thank a lot it’s work like this
