13#include <Foundation/Foundation.h>
17@property(nonatomic, assign)
double zeta;
18@property(nonatomic, assign)
double omega0;
19@property(nonatomic, assign)
double omega1;
20@property(nonatomic, assign)
double v0;
27- (instancetype)initWithStiffness:(
double)stiffness
28 damping:(
double)damping
30 initialVelocity:(
double)initialVelocity
31 fromValue:(
double)fromValue
32 toValue:(
double)toValue {
42 _zeta = _damping / (2 *
sqrt(_stiffness * _mass));
43 _omega0 =
sqrt(_stiffness / _mass);
44 _omega1 = _omega0 *
sqrt(1.0 - _zeta * _zeta);
45 _v0 = -_initialVelocity;
50- (double)curveFunction:(
double)t {
51 const double x0 = _toValue - _fromValue;
56 const double envelope = exp(-_zeta * _omega0 * t);
57 y = _toValue - envelope * (((_v0 + _zeta * _omega0 * x0) / _omega1) * sin(_omega1 * t) +
58 x0 * cos(_omega1 * t));
61 const double envelope = exp(-_omega0 * t);
62 y = _toValue - envelope * (x0 + (_v0 + _omega0 * x0) * t);
SIN Vec< N, float > sqrt(const Vec< N, float > &x)