Thomas Engel thomas.engel1 at gmx.net
Fri Feb 3 19:55:03 CET 2012

```Hello,

I'm new to haskell. I want to write a function for a s-curve acceleration in haskell.
A solution in VBA is already working.

Are there nested guards in haskell available or how can I rewrite this function?

The function should calculate the acceleration for a given distance, max acceleration, velocity, jerk at time since start

acc_skurve::Float->Float->Float->Float->Float->Float
acc_skurve str acc v jerk taktuell
| str <= str2jerk                  |taktuell <= (0.5 * str / jerk)**(1/3::Float)    = jerk * taktuell
|taktuell <= (4 * str / jerk)**(1/3::Float)      = jerk**(2/3::Float) * 2**(2/3::Float) * str**(1/3::Float) - jerk * taktuell
|taktuell <= (27/2 * str / jerk)**(1/3::Float)   = - jerk * taktuell + 2**(2/3::Float) * str**(1/3::Float) * jerk**(2/3::Float)
|taktuell <= (32 * str / jerk)**(1/3::Float)     = -2 * 2**(2/3::Float) * str**(1/3::Float) * jerk**(2/3::Float) + jerk * taktuell
| str > str2jerk && str < str2acc  |taktuell <= acc / jerk                                                                     = jerk * taktuell
|taktuell <= - acc / 2 / jerk + sqrt(acc^3 + 4 * str * jerk^2) / (2 * jerk * sqrt(acc))     = acc
|taktuell <=  acc / 2 / jerk + sqrt(acc^3 + 4 * str * jerk^2) / (2 * jerk * sqrt(acc))      = acc / 2 - jerk * taktuell + sqrt(acc^3 + 4 * str * jerk^2) / (2 * sqrt(acc))
|taktuell <=  3 * acc / 2 / jerk + sqrt(acc^3 + 4 * str * jerk^2) / (2 * jerk * sqrt(acc))  = acc / 2 - jerk * taktuell + sqrt(acc^3 + 4 * str * jerk^2) / (2 * sqrt(acc))
|taktuell <=  sqrt(acc^3 + 4 * str * jerk^2) / (sqrt(acc * jerk))                           = - acc
|taktuell <=  acc / jerk + sqrt(acc^3 + 4 * str * jerk^2) / (sqrt(acc * jerk))              = - acc + jerk * taktuell - sqrt(acc^3 + 4 * str * jerk^2) / sqrt(acc)
| str >= str2acc                   |taktuell <= acc / jerk                 = jerk * taktuell
|taktuell <= v / acc                    = acc
|taktuell <= acc / jerk + v / acc       = acc - jerk * taktuell + v * jerk / acc
|taktuell <= str / v                    = 0
|taktuell <= str / v + acc / jerk       = jerk * str / v - jerk * taktuell
|taktuell <= str / v + v / acc          = - acc
|taktuell <= str / v + acc / jerk + v / acc = -(str / v + acc / jerk + v / acc - taktuell) * jerk
where str2jerk = 2 * acc^2 / jerk^2
str2acc  = acc^2 * v + v^2 * jerk / (jerk * acc)

best regards
Thomas

```