Bezier function n+1

52 Views Asked by At

I'm using the website: https://pomax.github.io/bezierinfo/

I currently have this cubic curve function, which works great.

Using the code:

                t2 = num * num
                t3 = t2 * num
                mt = 1-num
                mt2 = mt * mt
                mt3 = mt2 * mt
                r = (((p0.pos*mt3) + (3*p1.pos*mt2*num) + (3*p2.pos*mt*t2) + (p3.pos*t3)))

I want to be able to control the count of points along the line. How can i incorporate the math below with the function above.

Bezier n+1 function

Sadly my math isn't this advanced, very eager to learn!

Thanks!

1

There are 1 best solutions below

0
On

You need to know about Pascal's triangle (https://en.wikipedia.org/wiki/Pascal%27s_triangle) which gives you coefficients. In the case of the cubic, which you used, they are $1, 3, 3, 1$.

You will multiply the coordinates of every control point $P_i$ by the correponding coefficient in the $n^{th}$ row of the triangle and by $t^i(1-t)^{n-i}$ (recognize your factors $t$ and $mt$). It is advantageous to compute the powers incrementally, i.e. $t,t^2,t^3\cdots$.