<p>I'm devising an algorithm to take a freehand curve and make a bezier spline from it. I can do this already just fine, but it's a naive implementation that creates about as many bezier curves as there are unique stylus inputs, which is a large amount. It works, but it would be better if I could reduce the curve only to an essential number of bezier segments necessary to approximate the freehand drawing. I've studied the results in other vector drawing programs and they will typically have many points around areas of high curvature and then few in straight parts of the curve. My question is how to best accomplish this. The best idea I have right now is to simply compare a freehand point with the two prior freehand points and if it does not deviate from some angle threshold on the line created by those two points, do not make a new segment from it. This sort of approximates what the curvature would be. But I am wondering if there is a more established algorithm for this?</p>

CC BY-SA 4.0
2023-07-25T21:20:11.233Z
You probably want to look into line simplification algorithms. One of the most well-known ones is the [Ramer-Douglas-Peucker algorithm](https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm). See also the "Similar algorithms" section for other approaches.
waldyrious
CC BY-SA 4.0
2023-07-26T19:31:01.733Z
@waldyrious that's a neat algorithm, thanks!
johnbakers
<vector-graphics><bezier-curve><drawing><spline>
How do freehand vector drawing tools typically decide where to place the control points?
johnbakers
# How do freehand vector drawing tools typically decide where to place the control points?

(Asked by: username_0 on 2023-07-25)

I'm devising an algorithm to take a freehand curve and make a bezier spline from it. I can do this already just fine, but it's a naive implementation that creates about as many bezier curves as there are unique stylus inputs, which is a large amount. It works, but it would be better if I could reduce the curve only to an essential number of bezier segments necessary to approximate the freehand drawing. I've studied the results in other vector drawing programs and they will typically have many points around areas of high curvature and then few in straight parts of the curve. My question is how to best accomplish this. The best idea I have right now is to simply compare a freehand point with the two prior freehand points and if it does not deviate from some angle threshold on the line created by those two points, do not make a new segment from it. This sort of approximates what the curvature would be. But I am wondering if there is a more established algorithm for this?

**Tags:** vector-graphics, bezier-curve, drawing, spline

> **Comments:**
> **username_1**: You probably want to look into line simplification algorithms. One of the most well-known ones is the [Ramer-Douglas-Peucker algorithm](https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm). See also the "Similar algorithms" section for other approaches.  
> **username_0**: @username_1 that's a neat algorithm, thanks!  

---

## 0 answers

