I need to perform a task using a math function (i'm a programer not a mathematician unfortunately).
The task i need to perform is to cycle through a list in a sinusoidal motion according to an increasing count.
the count (time) is increasing at a fixed rate, no problems there, however, I need the number of items in the cycle to change.
For example I have a 3 item cycle, 1->2->3->2->1->2 etc
I have managed to write an equation that will give me the result I need for this case:
So if t = x, number of items = 3:
(with rounding of the result)Code:t0 = 1, t1 = 2, t2 = 3, t3 = 2, t4 = 1
However, I may need to vary the number of items in the cycle to any arbitrary number, and as such would need for example the following to be true:
8 items:
how would I modify the equation to take into account the number of items in the cycle? (If at all possible)Code:t0 = 1, t1 = 2, t2 = 3, t3 = 4, t4 = 5, t6 = 7, t7 = 8, t8 = 7, t9 = 6, t10 = 5, ... t of 14 = 1
Thanks
Unfortunately, the structure of my application means it cannot be done programatically, there is no fixed number of times the calculation will be performed, nor is the time between calculations fixed and incrementing. I need it to be calculated on the spot according to whatever value of t is passed at the time.
In other words, as far as my application (abstract and programming) goes, time is not linearly increasing. It could be the same, it could be the same time for 10 or a hundred iterations before time changes.
It's hard for me to explain unless you can tell me you're a developer and I can use some technical terms?
I think I may have found a solution using modulus now, but for the sake of completion I'll explain the initial requirement.
I have a function in my program that is called every time the screen of the device is refreshed, this is an arbitrary, unknown number. Because I don't want the value to increment the function is called, I pass it a "tick" this tick is my "t" above, it checks against this if time has changed or not and calculates the new value accordingly.
Another method would be for me to store the previous time and check that way and increment if time has changed, but because my class and method are static storage isn't ideal.
Let be some parameter. Consider . Here is the remainder when n is divided by 2a.
Explanation. The absolute value |n| goes down to 0 when n is negative goes back up when n is positive. Next, |n-a| means shifting the graph of |n| to the right a units, so now the value at a is 0. Next, a-|n-a| flips the graph upside down and raises it a units, so now the value at 0 and 2a is 0, and the value at a is a. Finally, replacing n with (n mod 2a) makes the function periodic with the period 2a.