Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to smooth a hand-drawn line with Graphics2D

I've used this code to implement a freehand drawing tool in Java and Graphics2D. So I have a Path2D made up of a lot points. Is there an algorithm to smooth this line? I don't mean anti-aliasing, I mean something like converting the path to a path of bezier curves. Something like this, but with a Path2D as input. I would think this a recurring problem but I couldn't really find something useful.

like image 985
Nicolas Mommaerts Avatar asked Jan 17 '23 19:01

Nicolas Mommaerts


1 Answers

I've found what I needed at: http://javagraphics.blogspot.com/2010/06/shapes-implementing-freehand-pencil.html

Edit: and since I now know the exact term for this problem (curve fitting) I can google it better and also found this post: Java curve fitting library

Edit: also look at http://johnsogg.blogspot.com/2010/01/cardinal-splines-and-catmull-rom.html

like image 121
Nicolas Mommaerts Avatar answered Jan 19 '23 08:01

Nicolas Mommaerts