# Sequence of rotation

**URL:** <https://discourse.processing.org/t/sequence-of-rotation/3184>\
**Category:** Coding Questions\
**Created:** [September 2, 2018, 2:41am UTC](https://discourse.processing.org/t/sequence-of-rotation/3184 "2018-09-02T02:41:46Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 3, 2018, 7:04pm UTC](https://discourse.processing.org/t/sequence-of-rotation/3184/6 "2018-09-03T19:04:36Z")

</div>

> [@kll](#):
>
> does the sequence in what i use rotation matter?

~~It does _if_ you are **not** using translations between the rotations. If not, no. You can try this out with a physical object in your hand to confirm – rotate a stick of butter 90 x, then 90 y, or 90 y then 90 x, and it ends up in the same orientation. If you translate, however,~~

**(See expanded examples below) IN GENERAL** everything is order-dependent.

> [@kll](#):
>
> but all this is already inside a push - pop matrix loop  
> could this be ?stacked?

You may want to make sure that you have completely worked out the 2D case, then add another dimension of rotation to tilt the axes.

For example, here is a very very simple toy model which uses pushes and pops, implemented in the 2D case.

```auto
float spin;

void setup() {
  size(400, 400);
  rectMode(CENTER);
  ellipseMode(CENTER);
}
void draw() {
  background(0);
  spin = (spin + 0.012);

  translate(width/2, height/2);

  // planet
  translate(0, 0);
  rotate(spin);
  rect(0, 0, 50, 50);

  // moon A
  pushMatrix();
    rotate(spin + PI/3);
    translate(100, 0);
    rect(0, 0, 25, 25);

    // moon A sattelite 1
    pushMatrix();
      rotate(spin/2 + PI);
      translate(40, 0);
      rect(0, 0, 12, 12);
    popMatrix();

    // moon A sattelite 2
    pushMatrix();
      rotate(spin + PI/3);
      translate(50, 0);
      rect(0, 0, 10, 10);
    popMatrix();
  
  popMatrix();

  // moon B
  pushMatrix();
    rotate(spin/2 + PI/5);
    translate(140, 0);
    rect(0, 0, 20, 20);
  popMatrix();

}

```

![08%20PM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/2cfc42ee38ec48c5723c96cc9332060052ccb6fe.jpeg)

Notice how each starting angle for a child is relative, rather than absolute.

If you want to get into more detail about debugging your code, you may want to share example code here and describe how specifically you can tell it “looks wrong”, and what part of the code you think is doing that.

---

_[View the full topic](https://discourse.processing.org/t/sequence-of-rotation/3184)._
