Bezier curve evaluation
I'm currently working on a small vector graphics rasterizer to try out some different techniques. Basically, what I do is to take a spline outline consiting of straight lines and quadratic bezier curves, and fill that outline. I'm not satisfied with the performance and accuracy of my current scanline rasterizer...
The new approach is more similar to how triangles in "regular 3d graphics" are rasterized. I evaluate if pixels lie within a triangle by using the edge functions of the three edges (implicit line ax + by + c) and checking the sign.
But there are alot of bezier curves in the outline... It takes some time to convert the bezier curves into line segments (and then to proceed as described above).
So my question is, is there any way to rewrite a bezier curve into something that resembles the edge function? I can't seem to figure it out quite...
I've tried to rewrite a curve on the form ax + by + cx^2 + dx^2 + e (+ 0*xy) = 0, but it gets very messy, with roots and stuff which is not really cpu-friendly. I also tried converting the pixel coordinates to be evaluated into barycentric coordinates, but this also gets a bit messy, and I can't get rid of the divisions (two, one per coordinate)...
I'm very thankful for any help, or even just a hint in any direction, because I fell a bit stuck. I really feel like I'm overlooking something, and this really shouldn't be too difficult :/
I think I need a break and some coffee :)
Thanks in advance!
Ok, perhaps I expressed myself in a too complicated way :)
What I basically want to do is:
For any given point, determine on which side of a quadratic bezier curve that point is.
Secondarily I would like to know if it anyone knows if you can write a (all) quadratic bezier curve on the form, (and how to get it):
Ax + By + Cx^2 + Dy^2 + E = 0
I havn't found any info on the net regarding this :/
Originally Posted by repstosw
From Bezier curve - Wikipedia, the free encyclopedia, the parametric equation for a quadratic Bezier curve is
Originally Posted by repstosw
From Parabola - Wikipedia, the free encyclopedia, the general equation for a parabola is
and there are further conditions, including .
I don't know for a fact that a quadratic Bezier curve determines a parabola, but I'll assume it does. Given the condition on , it cannot assumed that as you indicate.
Given the 3 points defining the Bezier curve, you want to determine the 6 coefficients of the parabola. Under the invertibility requirement below, you may set the coefficient arbitrarily to a non-zero number, say Then you need 5 linear equations to determine the other 5 unknown coefficients.
Then the required 5 linear equations are
To solve these equations requires that the matrix be invertible. That is the invertibility requirement that allows you to set to an arbitrary non-zero number.
There is a question whether the condition will be satisfied. I think it must if the Bezier curve does indeed determine a parabola, which as I said I'm assuming is true.
Once you have the coefficients, then which side of the Bezier curve a point is on is determined by how the sign of compares to the sign of where the middle control point for the Bezier curve.