BlueVoodoo
BlueVoodoo

Reputation: 3686

cubic bézier curve issue

I am trying to optimize a bezier curve implementation by using the formula used in this wikipedia article. I have a horribly slow implentation now but at least it should be accurate. Using the following:

p0 = (0, 256) //Violet dot
p1 = (70, 223) //Green dot
p2 = (24, 472) //Blue dot
p3 = (255, 256) //Yellow dot
t = 0.5

Drawn with my current code below, the point at T = 0.5 is (67.125, 324.625)

enter image description here

Trying the formula for the X-axis, I do a calculation like this:

var x = Math.Pow(1 - t, 3) * p0.X + 3 * Math.Pow(1 - t, 2) * t * p1.X + 3 
        * (1 - t) * Math.Pow(t, 2) * p2.X + Math.Pow(t, 3) + p3.X;

But this gives me an X coordinate of 290.375 which is obviously not right. What am I missing here?

Upvotes: 2

Views: 788

Answers (1)

BlueVoodoo
BlueVoodoo

Reputation: 3686

Duh! Looking at my own question now, I see the obvious. The last bit Math.Pow(t, 3) + p3.X; should have been Math.Pow(t, 3) * p3.X;. Now it works.

Upvotes: 2

Related Questions