Which is the best Line SMoothing Algo for android
I want to make a smoother line which I draw by getting the points on touch. The line is a drawing, but with corners. I am using quad function to draw the curve, but the curve sometime开发者_开发知识库s has corners in it when the points are near to each other. What could be done to figure out the solution for this problem?
I deliberately didn't answer this question earlier, because you are using Android API and Quad function, and i thought there would be a way to increase the no. of points in the Quadratic Bezier Curve it is drawing. I did a google, and didn't find anything myself, but i was waiting for someone to post a trick using Android API.
It seems that the smoothness will have to be achieved manually by drawing a higher resolution Bezier Curve using code: Quad function is drawing the Quadratic Bezier Curve, here is a good link for algorithm to draw Bezier Curves, all you have to do is to increase the no. of points in your curve: Formula of Quadratic Bezier Curve is: `
[x,y]=(1 – t) 2P0 + 2(1 – t)tP1 + t2P2
`And you have to make t smaller to make the loop iterate more, so there will be more points and you'll be able to draw a smoother curve.
Here is the code that is interesting (I have slightly changed it to make it simpler for me to explain):
double t = 0;
Point prevPoint = CalculateBezierPoint(t, p0, p1, p2, p3);
for(int i = 0; i <= 100; i++)
{
Point nextPoint = CalculateBezierPoint(t, p0, p1, p2, p3); //see this part from the link i have given
//Draw line from previous point to next point.
prevPoint = nextPoint;
t = t + (1/100)
}
To make a smoother curve, increase the number of segments in the for loop (1000 etc, experiment with it), also change this line t = t + (1/100)
(divide the value by the larger no. of segments you choose, the i
Use this solution as a last option, if you find a way to do it using Android API, please post it here as well, and if someone else has a way to do it, please post, i am waiting for answers.
精彩评论