Search code examples
javarenderinggraphics2dcurvesmoothing

Draw a smooth curve through a set of n points


I'm working on a game displaying a route from a specific start point to the cursor. Since the current system is very old (probably about 10 years or so...) and partly broken, I want to rewrite this code from scratch. Let's say I have an array of points on my screen -the last point being my cursor-, and a Graphics2D object. How would I draw a line going smooth through all of those points using the shortest way possible?


Solution

  • How would I draw a line going smooth through all of those points using the shortest way possible

    This requirement is a bit contradictory. The shortest curve through a list of points is a polygon but a polygon is in general not smooth.

    However, what you are looking for is probably spline interpolation. This is not available in the standard Java packages but you could use SplineInterpolator in Apache Commons Math.