Getting Each Pixel Covered by a Bezier Curve

For a project of mine, I have a bezier curve’s control points. I need to get the pixels that the curve passes over. I haven’t been able to find anything that does this and was wondering if any of you knew of something. This gets called a lot, so speed is preferable.

One way would be to evaluate the Bezier curve along its path to convert it into polygons.

bseg = [Point(-100, 0), Point(0, 100), Point(100, -100), Point(150, 0)]

bezier(t, A::Point, A1::Point, B1::Point, B::Point) =
      A * (1.0 - t)^3 +
      (A1 * 3t * (1.0 - t)^2) +
      (B1 * 3t^2 * (1.0 - t)) +
      (B * t^3)

bezier.(range(0, 1, length=10), bseg...)

Presumably you can then find the pixels for the straight line sections.

1 Like

This reference seems to be a good resource.

1 Like

That’s quite a nice source, thanks :slight_smile:

There is more in GMT.jl then I can possibly remember. The GDAL gdal_rasterize program seems indicated for that and it’s implemented in GMT.jl in the gdalrasterize function that I see I’m using here

Maybe you can try to replicate its use for your purpose.