# Rotation of cell phone in landscape

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?

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()`.

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

In this specific case, it doesnâ€™t make much sense doing that, though.

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.

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

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).

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` 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?

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.

1 Like

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.