# Rotation of cell phone in landscape

**URL:** <https://discourse.processing.org/t/rotation-of-cell-phone-in-landscape/21494>\
**Category:** Coding Questions\
**Created:** [June 2, 2020, 2:12am UTC](https://discourse.processing.org/t/rotation-of-cell-phone-in-landscape/21494 "2020-06-02T02:12:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoeMcKay](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@JoeMcKay](https://discourse.processing.org/u/JoeMcKay)\
**Post date:** [June 2, 2020, 2:12am UTC](https://discourse.processing.org/t/rotation-of-cell-phone-in-landscape/21494/1 "2020-06-02T02:12:11Z")

</div>

Question.  
I am using rotationY to get the rotation of the phone. In portrait, rotationY gives a value between 0 and 360 which is awesome, but when the phone is in landscape the Y values are between 90 to 0, 0 to 90, -90 to 0 and 0 to -90. Is there an easy way to convert these numbers to values between 0 and 360?

---

<div class="post-metadata">

**Author:** ![Sven](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sven/32/8293_2.png) [@Sven](https://discourse.processing.org/u/Sven)\
**Post date:** [June 2, 2020, 5:47am UTC](https://discourse.processing.org/t/rotation-of-cell-phone-in-landscape/21494/2 "2020-06-02T05:47:47Z")

</div>

Hello @JoeMcKay,

This is not something I can reproduce on my device, an iPhone SE running Safari on iOS 13.5. The value of `rotationY` varies between -90 and 90 in both portrait and landscape orientation. Would you mind sharing your phone model and web browser make and version, along with the code you’re using?

To answer the general question, is there an easy way to convert from one range to another: you could use [`map()`](https://p5js.org/reference/#/p5/map).

```javascript
map(rotationY, -90, 90, 0, 360)

```

In this specific case, it doesn’t make much sense doing that, though.

---

<div class="post-metadata">

**Author:** ![JoeMcKay](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@JoeMcKay](https://discourse.processing.org/u/JoeMcKay)\
**Post date:** [June 2, 2020, 9:31pm UTC](https://discourse.processing.org/t/rotation-of-cell-phone-in-landscape/21494/3 "2020-06-02T21:31:08Z")

</div>

Mapping would make sense but it’s a little more complicated than that. The numbers don’t just go from -90 to 90. An image helps. Behold my Maya skills.

 ![phoneRotation](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/935883ef9483becd6a19d7f6f71b040ec5887665.jpeg)  
So there’s actually two of every number in a single rotation.  
I stripped down the code. I’m on a pixel (first gen) in Chrome.  
[https://editor.p5js.org/Joemckay/sketches/ij\_X-He38](https://editor.p5js.org/Joemckay/sketches/ij_X-He38)

---

<div class="post-metadata">

**Author:** ![Sven](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sven/32/8293_2.png) [@Sven](https://discourse.processing.org/u/Sven)\
**Post date:** [June 3, 2020, 7:30am UTC](https://discourse.processing.org/t/rotation-of-cell-phone-in-landscape/21494/4 "2020-06-03T07:30:31Z")

</div>

Hehe, yes, your Maya skills are impressive. 🙂 And the image helps illustrate the fact that `rotationY` does indeed vary between -90 and 90. So, when `rotationY` return -90, there’s no way for your code to tell which of the orientations below is the phone’s actual orientation (based on solely that value).

![rotation-y](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/eafe68fd1f657b3749d265eae004049a78bcf6f0.png)

Just scaling (mapping) `rotationY` is not enough. You have to rely on other sensor data to represent a single full rotation with values between 0–360. Maybe `rotationX` could be of assistance?

Thanks for sharing the sketch. I tried it on my iPhone, and `rotationY` (the label `Y`) does not show values outside the range -90–90 (neither in portrait nor landscape). The [documentation for `rotationY`](https://p5js.org/reference/#/p5/rotationY) states that “the value will be -90 to 90”, so something strange is definitely going on if your Pixel returns values in the range 0–360. Could you borrow a friend’s phone and see if the sketch acts weird there as well?

---

<div class="post-metadata">

**Author:** ![JoeMcKay](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@JoeMcKay](https://discourse.processing.org/u/JoeMcKay)\
**Post date:** [June 3, 2020, 5:49pm UTC](https://discourse.processing.org/t/rotation-of-cell-phone-in-landscape/21494/5 "2020-06-03T17:49:41Z")

</div>

Yeah, it turns out after I made the clarifying p5 sketch that I realized was wrong. The Y is giving me the same data in both orientations, is just doesn’t get in the way in the verticle view. This is actually good news because it means there’s hopefully some standardization across phones.  
Yeah, I agree that I can probably use RotationX data to quantify which quadrant the rotationY is in and then map that data accordingly. I was having one of those moments where you suddenly feel like you’re solving a problem that’s already been solved a thousand times. But if there’s no easy fix I’ll figure it out. 🙂  
Thanks for the help.

---

<div class="post-metadata">

**Author:** ![doodad](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@doodad](https://discourse.processing.org/u/doodad)\
**Post date:** [June 3, 2020, 6:09pm UTC](https://discourse.processing.org/t/rotation-of-cell-phone-in-landscape/21494/6 "2020-06-03T18:09:32Z")

</div>

Your Maya skills are awesome. LOL! 😃

But, It gets confusing if there is opposite result for same number!

Let us know when you figure it out.
