3

This may be too easy for you, but here goes: I'm creating a kind of ski slalom game where I want the horizontal speed/direction to follow the attached graph. X is time, Y is horizontal speed. Positive horizontal speed makes my skier go right, negative horizontal speed makes the skier go left.

I want to be able to adjust the max speed (A), the time to maintain max speed (B), and the time it takes for the skier to make a turn (C).

What is the function for this? Thanks!

enter image description here

2 Answers2

1

It's not clear exactly what shapes you want for your family of functions, but here is one family of functions that will capture the qualitative type of variability you want, and matches your given shape nicely e.g. for $\alpha = 3$:

$$f(x) = A \cdot \hbox{sign}(\cos Dx) \cdot |\cos (Dx)|^{\alpha}$$

where $A$ controls the height, $D$ controls the overall width of each cycle ($B + C$ in your diagram), and $\alpha > 0$ controls how big $B$ is compared to $C$. Try values of $\alpha$ like $0.25,0.5,1,2,3$ and make plots and you'll see what you can get. Hopefully the types of shapes are to your liking; these plots definitely have the property though that you get tradeoff between $B$ and $C$ as you vary $\alpha$, and controlling $A$ is trivial as it just requires a constant multiplier.

user2566092
  • 26,142
0

How about $$(Ae^{-2(x-{{b+2C}\over 2})^2\over B^2}\mod{B+2C})*(-1)^{\lfloor {x\over B+2C} \rfloor}$$, if I'm interpreting your graph correctly? That's a bell curve, which isn't exactly the same shape as in your graph but pretty close, repeated every $B+2C$, where I'm assuming that $B$ is twice the standard deviation, which looks about right, and $C$ is the length from one standard deviation away from the peak of the curve until the end of the period. I may have something wrong somewhere in here, but I think the general idea should work.

Avi
  • 1,780
  • 11
  • 21
  • Thanks! This would have worked fine, but eventually, I used the trigonometry based solution provided by @user2566092 – Hunkpapa Jul 12 '14 at 08:16