Answer the question
In order to leave comments, you need to log in
What is the correct way to draw a smooth curve given a set of points?
The task is as follows: the user swipes the screen with a finger and a beautiful smooth curve should be displayed on the screen after the finger. As an example, you can see how the ipad penultimate program works. There are very nice lines.
Now I'm building a curve from segments that are cubic bezier curves. Tried different options. So far, two methods have given the best result:
1) Segments are built between each pair of points received from the user (between the first and second, then between the second and third, etc.). The missing points are approximately calculated mathematically.
I count the points like this:
P1' = (P2 - P1) / a
Pi' = (Pi+1 - Pi-1) / a (for i=2..n-1)
Pn' = (Pn - Pn-1) / a
B1i = Pi + Pi'/3
B2i = Pi+1 - Pi+1'/3
where Pi is the point received from the user, and B1i and B2i are the desired points.
Bottom line: the curve is definitely there, but not smooth enough. Either I'm not counting the points correctly, or the method is not the best.
2) I take all four points for the segment from the set received from the user. To avoid sharp corners between neighboring segments, I shift the second point of the current segment based on the position of the third point of the previous one (so that the 3rd and 4th points of the previous segment, as well as the 2nd point of the current one, lie on the same line).
Bottom line: no better than the first case.
How to make the curve smoother like in penultimate?
Answer the question
In order to leave comments, you need to log in
Try the Iterative Path Smoothing Algorithm for Robot www.udacity.com/view#Course/cs373/CourseRev/apr2012/Unit/513063/Nugget/510049
- there are a few videos to watch starting from this one.
In my opinion, something similar is described by Knuth in the book "All about Metafont" (in the third chapter). In general, Bezier curves are used there, but the operator directly sets only the extreme points through which the curve will actually pass, and the algorithm calculates the auxiliary points itself.
See also StackOverflow .
To avoid angles at points, it is necessary to introduce the continuity condition for first-order derivatives at points in the original formulas, because the continuity of the first derivative is the criterion for a smooth curve.
I suggest using a hybrid. Output: the equation of the curve, the order of smoothness that suits you and the equation of the straight line. We use the first type of curve near the touch points, and the second one far away. We regulate this process using a weight function that depends on the distance to the nearest point:
(1-p®)*f1(x)+p®*f2(x). When the removal r is large, the result is f2(x). When aiming for a point, the result is f1. In between, we summarize the functions. Weight function from 0 to 1.
It remains to choose a weight function that will ideally combine smoothness around a point and straightness between points. This approach works well for some mapping tasks.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question