# How to rotate object around edge?

**URL:** <https://discourse.processing.org/t/how-to-rotate-object-around-edge/19757>\
**Category:** Coding Questions\
**Created:** [April 13, 2020, 10:58pm UTC](https://discourse.processing.org/t/how-to-rotate-object-around-edge/19757 "2020-04-13T22:58:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cybernet](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@Cybernet](https://discourse.processing.org/u/Cybernet)\
**Post date:** [April 13, 2020, 10:58pm UTC](https://discourse.processing.org/t/how-to-rotate-object-around-edge/19757/1 "2020-04-13T22:58:11Z")

</div>

I have this code right here that rotates a rectangle.

```auto
    pushMatrix();
    translate(xpos + 20, ypos - 10);
    rotate(radians(swing));
    rect(0, 0, 7, 35);
    popMatrix();

    swing += 1;

```

But when I run the code, the rectangle rotates around the center, but I want it to rotate around the edge. How do I achieve this effect?

---

<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:** [April 14, 2020, 12:30am UTC](https://discourse.processing.org/t/how-to-rotate-object-around-edge/19757/2 "2020-04-14T00:30:14Z")

</div>

> [@Cybernet](#):
>
> I have this code right here that rotates a rectangle.

Your code is translating and then rotating in that order… what if?

`:)`

---

<div class="post-metadata">

**Author:** ![Cybernet](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@Cybernet](https://discourse.processing.org/u/Cybernet)\
**Post date:** [April 14, 2020, 1:14am UTC](https://discourse.processing.org/t/how-to-rotate-object-around-edge/19757/3 "2020-04-14T01:14:37Z")

</div>

I see now! Thanks you

---

<div class="post-metadata">

**Author:** ![megarou](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@megarou](https://discourse.processing.org/u/megarou)\
**Post date:** [April 14, 2020, 1:32am UTC](https://discourse.processing.org/t/how-to-rotate-object-around-edge/19757/4 "2020-04-14T01:32:13Z")

</div>

Hello cybernet, try this code, you might wanna hard code the translate arguments & change these two zeros that are inside the rect() into also some hard coded argument, here is my code;

```auto
push();
  translate(200, 200);
  rotate(radians(x-159));
  rect(200, 0, 7, 35);
  pop();
 
  
  x = x + 3;

```

i hope that helps

---

<div class="post-metadata">

**Author:** ![megarou](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@megarou](https://discourse.processing.org/u/megarou)\
**Post date:** [April 17, 2020, 12:52am UTC](https://discourse.processing.org/t/how-to-rotate-object-around-edge/19757/5 "2020-04-17T00:52:03Z")

</div>

You very welcome, glad that i can help 😉
