# \[SOLVED\] Need help with rotations

**URL:** <https://discourse.processing.org/t/solved-need-help-with-rotations/7861>\
**Category:** Processing.py\
**Created:** [January 26, 2019, 4:53pm UTC](https://discourse.processing.org/t/solved-need-help-with-rotations/7861 "2019-01-26T16:53:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [January 26, 2019, 4:53pm UTC](https://discourse.processing.org/t/solved-need-help-with-rotations/7861/1 "2019-01-26T16:53:45Z")

</div>

```auto
width = 700
height = 500
recto = PVector(0,0)
mouse = PVector(0,0)
def setup():
    size(width,height)
    rectMode(CENTER)
    
def draw():
    background(191)
    mouse.x = mouseX
    mouse.y = mouseY
    pushMatrix()
    angle = PVector.angleBetween(recto,mouse)
    translate(width/2,height/2)
    rotate(angle)
    print(degrees(angle))
    rect(recto.x,recto.y,100,100)
    popMatrix()
    ellipse(width/2,height/2,50,50)

```

I need to rotate the rect() when i move the mouse, but I want that the angle is from rect center, and not X axis like in atan2()

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [January 26, 2019, 5:50pm UTC](https://discourse.processing.org/t/solved-need-help-with-rotations/7861/2 "2019-01-26T17:50:02Z")

</div>

I think what you should keep in mind is that `rotate` function rotates around the point you set in `translate` function. So, with `translate(width/2,height/2)` is rotates around the `(width/2,height/2)` point.

What I suggest is to translate to the point that should be `rect`'s center, so that it would rotate around that point, and this way would do the thing you want. So, replace corresponding lines with this:

```auto
    translate(width/2+recto.x+50,height/2+rectoy+50) #50 is to set to rect's middle point, not top left corner
    ...
    rect(-50,-50,100,100) #-50 is because rect draws from top left, and we need it's center to align with the axis point

```

I think this should work like you want.

---

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [January 27, 2019, 12:12pm UTC](https://discourse.processing.org/t/solved-need-help-with-rotations/7861/3 "2019-01-27T12:12:01Z")

</div>

Hi @Sky,

Not sure to perfectly understand what you want (it seems to me you _can_ operate a rotation from the center of a rectangle with `atan2()`). Does the following correspond to what you’re trying to achieve ?

```auto
def setup():
    size(700, 500)
    rectMode(CENTER)
    
def draw():
    background(191)
    
    angle = atan2(mouseY-height/2, mouseX-width/2)

    translate(width>>1, height>>1)    
    rotate(angle)

    rect(0, 0, 100, 100)
    ellipse(0, 0, 50, 50)
    line(0, 0, 25, 0)
    
    print degrees(angle)

```
