Copy link to clipboard
Copied
Hi Guys,
I need to find a way to extract true degrees from the rotation transform. So instead of reading 1x-90 or 2x270, It just needs to read the 270 degrees part.
So if somethings continuously rotates, if you go beyond 360, it goes to 1x1 on the display or 361 if you read it out in expressions. But I only need to now if something is beyond 180 degrees or not, everytime it rotates.
So if it says 1x179, then it needs to understand that it is 179 and therefore not greater then 180 or not beyond the half of the circle, but it reads this of course at (1x360+179) 539, which IS greater then 180. So my if-then doesn't detect when its in the second half of the circle past one rotation.
Is there anyone who has discovered a function or some sort that does that?
Kind regards,
Marten.
My expression simply always returns 0-360. If you want to do something after like check for greater than 180 you could add it after this:
a = thisComp.layer(1).transform.rotation;
if (a >= 0) b = a - (Math.floor(a / 360) * 360);
else b = 360 + (a - (Math.ceil(a / 360) * 360));
if (b....and so on
Copy link to clipboard
Copied
You could use something like this:
a = thisComp.layer(1).transform.rotation;
if (a >= 0) a - (Math.floor(a / 360) * 360);
else 360 + (a - (Math.ceil(a / 360) * 360));
Copy link to clipboard
Copied
Thanks for your reply. I tried running the value through your suggestion, but it doesn't work. I do not understand what the instruction set for itself mean's so maybe I'm doing it wrong here.
I had:
turn = transform.rotation
if (turn > 180){
[180];
}else{[0]; }
With your suggestion:
a = transform.rotation;
if (a >= 0) a - (Math.floor(a / 360) * 360);
else 360 + (a - (Math.ceil(a / 360) * 360));
turn = a
if (turn > 180){
[180];
}else{[0]; }
It still doesn't detect only the absolute degrees on the a 360 degrees scale. It works only the first time around, and then it keeps saying it's more then 180. (so 361 is of course more than one 180, but on an absolute 360 scale it is 1 again, which is less, which should test false)
Copy link to clipboard
Copied
My expression simply always returns 0-360. If you want to do something after like check for greater than 180 you could add it after this:
a = thisComp.layer(1).transform.rotation;
if (a >= 0) b = a - (Math.floor(a / 360) * 360);
else b = 360 + (a - (Math.ceil(a / 360) * 360));
if (b....and so on
Copy link to clipboard
Copied
This works! Thanks!
Copy link to clipboard
Copied
you can also write this a bit more compact:
a = thisComp.layer(1).transform.rotation;
b = (a%360 + 360) % 360;
// now b is between 0 and 360 (including 0 and excluding 360)