0
$\begingroup$

I have an object that continually rotates on the y-axis. I want to scale it, so that it periodically gets scaled down to -1 and then back up to +1. So at 0° the scale should be 1, at 180° -1, at 360° 1 again and continuing that over 360°.

I tried using a driver, but didn't get anywhere. First I convert the total rotation into the amount over the next lower full multiple of 360 using this function:

((x * 180 / pi) / 180) % 1

It converts radians to degrees, than divides by 180 to find out how many multiples of 180 is inside of x and reduces the result modulo 1. This linearlly maps 0° to 0 and 180° to 1. Now, I moved it down using -0.5 and multiplied it by 2 to get 180° back up to 1, to get this function:

((((x * 180 / pi) / 180) % 1)-0.5)*2

Graphing this function looks like this: Graph of the function "((((x * 180 / pi) / 180) % 1)-0.5)*2"

The Problem here is the jarring jump from 1 to -1.

Ideally, I need a function that looks roughly like the green graph in the picture below, however it doesn't need to be linear, the important thing is that 0° matches -1 and 180° 1 etc. as exact as possible to prevent small shifts turning into big shifts at values like 30,000°+: Graph of the function "((((x * 180 / pi) / 180) % 1)-0.5)*2" and hand drawn graph

$\endgroup$
0

1 Answer 1

1
$\begingroup$

Why not using a cosine function?

Otherwise try the triangle wave function described here on Wikpedia: https://en.wikipedia.org/wiki/Triangle_wave

$\endgroup$
2
  • $\begingroup$ I tried sine before, but that didn't work out. Cosine makes more sense, I didn't think of that before. Thanks! $\endgroup$ Commented Nov 12, 2022 at 14:23
  • $\begingroup$ Glad it worked. You're welcome :) $\endgroup$
    – Jag JB
    Commented Nov 12, 2022 at 16:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .