Fast way to smooth a 2D polygon

Started by
18 comments, last by snaileri 11 years, 9 months ago
samoth, could you please explain your approach visually? I don't understand what kind of vector you mean.
I am talking about the vector that you refer to as "normal" in your 5:05 post. Which I guess is somewhat kind of the correct term too, although this "normal" is not necessarily "normal length" in the soft body calculation. I called it "pressure" vector for that reason. Maybe "perpendicular" is a better term... but let's not dispute what we call it, if everyone knows what vector we talk about.

Either way, it's that vector one would be interested in, as it is already available for free and it points into the correct direction. If you imagine a straight line between two control points, then the smoothed point in the middle would be "pulled" outside in the direction of the normal (by a small amount, say, 1/3 of the normal's length, one would need to experiment what looks best).

Note that coincidentially, drawing the outline and smoothing is almost the same. Except for the outline, you will need to normalize the "non-normal normal".

As for "fast inverse square root in Java", this is probably a bit of a non-optimization. Executing half a dozen lines of Java code including two rounding operations is almost guaranteed to be much slower than to just tell the Java compiler to divide by a square root.
Advertisement
Yeah, I created a little timer app that measures how many milliseconds are spent when calculating 1 000 000 times the square root. The "inverse square root" algorithm didn't do any better than the default "Math.sqrt".

Okay... I'll go with the Math.sqrt.
Later when I optimize the code, I want to learn how to implement OpenCL with LWJGL and Slick2D so i can calculate all this smoothing and outlines on GPU.

This topic is closed to new replies.

Advertisement