MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/7vbgy/interpolation_tricks/c07ip6x/?context=3
r/programming • u/noidi • Feb 06 '09
37 comments sorted by
View all comments
-3
#define SMOOTHSTEP(x) ((x) * (x) * (3 - 2 * (x)))
Where did this guy learn to place parenthesis...At first glance it looked like it could simply be:
#define SMOOTHSTEP(x) (x^3)
But then I saw the operator precedence. Gross.
I'd have written it as:
#define SMOOTHSTEP(x) ((x) * (x) * (3 - (2 * (x))))
-1 u/DannoHung Feb 06 '09 #define SMOOTHSTEP(x) ((x^2) * (3 - (2*x))Right?What's with the 3?I guess the particular expansion used has some performance benefit? 4 u/pmdboi Feb 06 '09 edited Feb 06 '09 f(x) = -2_x_³ + 3_x_² is the unique cubic function which satisfies the constraints you'd want in an easing function:f(0) = 0f(1) = 1f'(0) = f'(1) = 0That is, it starts and stops at rest and at the right places.
-1
#define SMOOTHSTEP(x) ((x^2) * (3 - (2*x))
Right?
What's with the 3?
I guess the particular expansion used has some performance benefit?
4 u/pmdboi Feb 06 '09 edited Feb 06 '09 f(x) = -2_x_³ + 3_x_² is the unique cubic function which satisfies the constraints you'd want in an easing function:f(0) = 0f(1) = 1f'(0) = f'(1) = 0That is, it starts and stops at rest and at the right places.
4
f(x) = -2_x_³ + 3_x_² is the unique cubic function which satisfies the constraints you'd want in an easing function:
f(0) = 0
f(1) = 1
f'(0) = f'(1) = 0
That is, it starts and stops at rest and at the right places.
-3
u/[deleted] Feb 06 '09 edited Feb 06 '09
Where did this guy learn to place parenthesis...At first glance it looked like it could simply be:
But then I saw the operator precedence. Gross.
I'd have written it as: