# Getting Each Pixel Covered by a Bezier Curve

**URL:** <https://discourse.julialang.org/t/getting-each-pixel-covered-by-a-bezier-curve/89162>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 23, 2022, 9:08pm UTC](https://discourse.julialang.org/t/getting-each-pixel-covered-by-a-bezier-curve/89162 "2022-10-23T21:08:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GameDungeon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gamedungeon/32/38609_2.png) [@GameDungeon](https://discourse.julialang.org/u/GameDungeon)\
**Post date:** [October 23, 2022, 9:08pm UTC](https://discourse.julialang.org/t/getting-each-pixel-covered-by-a-bezier-curve/89162/1 "2022-10-23T21:08:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [October 24, 2022, 8:29am UTC](https://discourse.julialang.org/t/getting-each-pixel-covered-by-a-bezier-curve/89162/2 "2022-10-24T08:29:53Z")

</div>

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

```julia
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.

 ![Screenshot 2022-10-24 at 09.27.42](https://global.discourse-cdn.com/julialang/original/3X/c/e/cec89bc3d53bfcf159530cfc80bf14acc07684e7.png)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [October 25, 2022, 9:47pm UTC](https://discourse.julialang.org/t/getting-each-pixel-covered-by-a-bezier-curve/89162/3 "2022-10-25T21:47:04Z")

</div>

> [@GameDungeon](#):
>
> 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 reference](https://zingl.github.io/Bresenham.pdf) seems to be a good resource.

---

<div class="post-metadata">

**Author:** ![GameDungeon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gamedungeon/32/38609_2.png) [@GameDungeon](https://discourse.julialang.org/u/GameDungeon)\
**Post date:** [October 25, 2022, 9:49pm UTC](https://discourse.julialang.org/t/getting-each-pixel-covered-by-a-bezier-curve/89162/4 "2022-10-25T21:49:38Z")

</div>

That’s quite a nice source, thanks 🙂

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [October 25, 2022, 10:24pm UTC](https://discourse.julialang.org/t/getting-each-pixel-covered-by-a-bezier-curve/89162/5 "2022-10-25T22:24:21Z")

</div>

There is more in GMT.jl then I can possibly remember. The GDAL [gdal\_rasterize](https://gdal.org/programs/gdal_rasterize.html) program seems indicated for that and it’s implemented in GMT.jl in the [gdalrasterize](https://github.com/GenericMappingTools/GMT.jl/blob/master/src/gdal.jl#L1573) function that I see I’m using [here](https://github.com/GenericMappingTools/GMT.jl/blob/master/src/rasterpolygonfuns.jl#L139)

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