Why doesn't my formula for calculating a cubic bezier curve work?

108 Views Asked by At

I am trying to calculate the y values of a cubic bezier curve given 0 <= t <= 1 and given the values for p0, p1, p2, p3.

(The purpose is to create a JavaScript animation that follows a cubic bezier curve -- I have done my best to comment the code clearly for non-coders who will understand the math.)


Here's my attempt (does not work, notice how the output decreases before increasing -- it should only increase): https://codepen.io/anon/pen/QpRzBg

My attempt is based off of "the explicit formula" (I don't know what this means, which may be a source of my confusion) enter image description here

0.42
0.30258648702111546
0.29458762974594366
0.2879653408110369
0.28268740148996013
0.2787215937224825
0.27603569893061736
0.274597498909286
0.2743747752217487
0.27533530952528085
0.2774468835171878
0.28067727872430076
0.2849942768352678
0.2903656596601793
0.29675920854370297
0.30414270548674993
0.3124839317215477
0.3217506693578464
0.3319106995226354
0.3429318044273023
0.3547817651007996
0.36742836384895117
0.3808393816098741
0.3949826007766266
0.40982580220369247
0.42533676836416223
0.44148328003608805
0.4582331197653917
0.47555406826089475
0.4934139081341484
0.511780420031946
0.5306213866242662
0.5499045885030753
0.5695978078339063
0.5896688268281166
0.6100854260089352
0.6308153881609031
0.6518264937704267
0.6945632642722144
0.7162244924650468
0.7380379906681318
0.7599715417440711
0.8040699266461753
0.8261703237576904
0.8482619003251926
0.8703124367589987
0.892289715934957
0.9141615182697712
0.9574598214438416
0.9788218855620608
0.9999495994350432
1

Now here is someone else's attempt, which DOES work but I have no idea why -- and I'd like to know why, so that in the future, I will know how to translate wikipedia equations into useable formulae for my own needs: https://codepen.io/anon/pen/evabrr

0
0.0004999400103243676
0.0011850429708800167
0.002314537071901034
0.003999520026720056
0.006351089634034126
0.009480343767040133
0.013498380027320945
0.018516296420000262
0.0246451904411195
0.03199616021376045
0.040680303103589804
0.05080871737648072
0.062492500242891866
0.07584275013632107
0.0909705640871857
0.10798704072144152
0.12700327686463134
0.1481303713600021
0.17147942080338874
0.1971615242801628
0.225287778131618
0.2559692817100836
0.28931713107747903
0.3254424258779246
0.36445626186913194
0.40646973901184574
0.4515939527347367
0.4999400019431349
0.5482939140741039
0.5934257274782899
0.6354465376582473
0.6744674400422368
0.7439539170630621
0.7746416871017152
0.8027739407689262
0.8518162933879888
0.8919697571484102
0.9089909003772693
0.9241231142783501
0.9374774974778546
0.9491651470059689
0.959297161296407
0.9753386740610863
0.9814703681668824
0.9905111210564972
0.993642375265362
0.9959956784564308
0.9976821282746474
0.998812822594843
0.9998513356998942
0.999999999999744
1