# The rotation of a rectangle

**URL:** <https://forum.inductiveautomation.com/t/the-rotation-of-a-rectangle/83022>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [December 12, 2023, 10:00am UTC](https://forum.inductiveautomation.com/t/the-rotation-of-a-rectangle/83022 "2023-12-12T10:00:07Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![chen\_xiaodong](https://avatars.discourse-cdn.com/v4/letter/c/7bcc69/32.png) [@chen\_xiaodong](https://forum.inductiveautomation.com/u/chen_xiaodong)\
**Post date:** [December 12, 2023, 10:00am UTC](https://forum.inductiveautomation.com/t/the-rotation-of-a-rectangle/83022/1 "2023-12-12T10:00:07Z")

</div>

I drew a rectangle in the vision, and when a bool variable is true, the rectangle starts rotating 10 ° every second. What should I do? Thank you very much 🤩

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 12, 2023, 10:32am UTC](https://forum.inductiveautomation.com/t/the-rotation-of-a-rectangle/83022/2 "2023-12-12T10:32:26Z")

</div>

My original answer was incorrect. `toRadians` is not required as the angle property uses degrees. Correct version shown below.

 ![Rotating rectangle](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/2/f2f4615cfc20a87a192d6a64ed6d9fa05e352110.png)

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 12, 2023, 12:05pm UTC](https://forum.inductiveautomation.com/t/the-rotation-of-a-rectangle/83022/3 "2023-12-12T12:05:45Z")

</div>

While this will probably work for a while, this approach is prone to a cumulative floating point errors that will eventually result in unexpected behaviors. Something with explicitly integer angles, such as the style customizer, a timer component, or evan an expression binding with a case statement are the preferred method for rotating animations in Vision.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 12, 2023, 12:10pm UTC](https://forum.inductiveautomation.com/t/the-rotation-of-a-rectangle/83022/4 "2023-12-12T12:10:44Z")

</div>

> [@justinedwards.jle](#):
>
> ... is prone to a cumulative floating point errors ...

How come? I appreciate that the `now(1000)` won't fire on a 0 ms transition so the script could probably do with an `int()` to fix this, but where is the opportunity for cumulative errors? The `%` modulo arithmetic should prevent that.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 12, 2023, 12:19pm UTC](https://forum.inductiveautomation.com/t/the-rotation-of-a-rectangle/83022/5 "2023-12-12T12:19:48Z")

</div>

Perhaps you're right. On my phone, I see this in your picture, so it makes me think there is a fractional element to this approach.  
 ![Screenshot_20231212-061711-266](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/b/1b9d16ba9c647fa5c7ef5cf31653bb81d219cd40.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 12, 2023, 12:24pm UTC](https://forum.inductiveautomation.com/t/the-rotation-of-a-rectangle/83022/6 "2023-12-12T12:24:44Z")

</div>

That's probably from the `toRadians()` function.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 12, 2023, 12:27pm UTC](https://forum.inductiveautomation.com/t/the-rotation-of-a-rectangle/83022/7 "2023-12-12T12:27:55Z")

</div>

> [@Transistor](#):
>
> How come?

Because converting to radians requires the use of Pi

A better solution in this instance is to just force the addition of 10 every second. I would probably lean towards a timer component.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 12, 2023, 12:30pm UTC](https://forum.inductiveautomation.com/t/the-rotation-of-a-rectangle/83022/8 "2023-12-12T12:30:35Z")

</div>

I also like to use the canvas with a timer component for this sort of thing.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 12, 2023, 12:32pm UTC](https://forum.inductiveautomation.com/t/the-rotation-of-a-rectangle/83022/9 "2023-12-12T12:32:29Z")

</div>

> [@justinedwards.jle](#):
>
> use the canvas

Agree particularly for complex shapes. Also prevents the shape from flying off the screen, though if the position isn't changing that shouldn't be an issue.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 12, 2023, 12:40pm UTC](https://forum.inductiveautomation.com/t/the-rotation-of-a-rectangle/83022/10 "2023-12-12T12:40:00Z")

</div>

> [@lrose](#):
>
> A better solution in this instance is to just force the addition of 10 every second.

That will definitely cause a creep due to the π rounding error (but see below).

I'm not arguing for my solution in particular. I don't work in Vision anymore and on further inspection the angle is in degrees, not radians! I'll edit my original answer. The new one uses `floor()` to ensure that the rectangle starts at 0° and there is no creep.

---

<div class="post-metadata">

**Author:** ![chen\_xiaodong](https://avatars.discourse-cdn.com/v4/letter/c/7bcc69/32.png) [@chen\_xiaodong](https://forum.inductiveautomation.com/u/chen_xiaodong)\
**Post date:** [December 13, 2023, 12:27am UTC](https://forum.inductiveautomation.com/t/the-rotation-of-a-rectangle/83022/11 "2023-12-13T00:27:10Z")

</div>

Thank you very much for your enthusiastic help

---

<div class="post-metadata">

**Author:** ![chen\_xiaodong](https://avatars.discourse-cdn.com/v4/letter/c/7bcc69/32.png) [@chen\_xiaodong](https://forum.inductiveautomation.com/u/chen_xiaodong)\
**Post date:** [December 13, 2023, 1:27am UTC](https://forum.inductiveautomation.com/t/the-rotation-of-a-rectangle/83022/12 "2023-12-13T01:27:30Z")

</div>

As a user of traditional scada, I was greatly shocked by the experience with igniton. Once again, thank you and other friends for providing me with ideas

---

<div class="post-metadata">

**Author:** ![chen\_xiaodong](https://avatars.discourse-cdn.com/v4/letter/c/7bcc69/32.png) [@chen\_xiaodong](https://forum.inductiveautomation.com/u/chen_xiaodong)\
**Post date:** [December 13, 2023, 5:58am UTC](https://forum.inductiveautomation.com/t/the-rotation-of-a-rectangle/83022/13 "2023-12-13T05:58:32Z")

</div>

getsecond( now() )\*10.  
This should be simpler.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 13, 2023, 8:37am UTC](https://forum.inductiveautomation.com/t/the-rotation-of-a-rectangle/83022/14 "2023-12-13T08:37:17Z")

</div>

> `getsecond( now() ) * 10`  
> should be simpler.

Yes, but gives you 0°, 10°, 20°, ... 340°, 350° 360°, 370° ..., 580°, 590° before resetting with a big jump.
