1
\$\begingroup\$

So I am using Kinect with Unity.

With the Kinect, we detect a hand gesture and when it is active we draw a line on the screen that follows where ever the hand is going. Every update the location is stored as the newest (and last) point in a line. However the lines can often look very choppy.

Here is a general picture that shows what I want to achieve:

Smoother versus Rough Lines

With the red being the original line, and the purple being the new smoothed line. If the user suddenly stops and turns direction, we think we want it to not exactly do that but instead have a rapid turn or a loop.

My current solution is using Cubic Bezier, and only using points that are X distance away from each other (with Y points being placed between the two points using Cubic Bezier). However there are two problems with this, amongst others:

1) It often doesn't preserve the curves to the distance outwards the user drew them, for example if the user suddenly stop a line and reverse the direction there is a pretty good chance the line won't extend to point where the user reversed the direction.

2) There is also a chance that the selected "good" point is actually a "bad" random jump point.

So I've thought about other solutions. One including limiting the max angle between points (with 0 degrees being a straight line). However if the point has an angle beyond the limit the math behind lowering the angle while still following the drawn line as best possible seems complicated. But maybe it's not. Either way I'm not sure what to do and looking for help.

Keep in mind this needs to be done in real time as the user is drawing the line.

\$\endgroup\$
1
\$\begingroup\$

You could try using Chaikin's smoothing algorithm. It's an alternative to using spline curves.

In this article, which details an implementation of a swipe gesture in the style of Fruit Ninja's swiping, you can see a couple of steps taken to first simplify and then smoothen the input points to generate the swipe path.

\$\endgroup\$
  • \$\begingroup\$ This answer would be even better if it included a summary of the steps in the article by Matt DesLauriers that you link. In case linked resources ever become unavailable, answers should be able to stand on their own. \$\endgroup\$ – DMGregory Mar 3 '16 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.