I need to connect three points by a smooth curve. I've looked at the same questions already answered on StackOverflow but they all suggest using Path.quadTo()
. I do not understand why this is considered a correct answer as Bezier curve is only approaching middle (control) point but not going through it. In my case I have to go exactly through it. So how can I achieve that?
Asked
Active
Viewed 5,098 times
9

Andrey Novikov
- 5,563
- 5
- 30
- 51
3 Answers
4
True, what you need is Catmull Rom splines which are guaranted to go through each point. However, I don't know any function in the Android API to draw them. You could also "trick" the quadTo function and pass it a virtual middle point that you compute according to the current point and the next one.

Vincent Mimoun-Prat
- 28,208
- 16
- 81
- 124
-
1Thanks for a clue, I've searched Internet thoroughly and have ended with the following computation of the control point for quadTo: // interpolate three points with second point at specified parameter value int[] interpolate(int x0, int y0, int x1, int y1, int x2, int y2, double t) { double t1 = 1.0 -t; double tSq = t * t; double denom = 2.0 * t * t1; int cx = (int) ((x1 - t1 * t1 * x0 - tSq * x2) / denom); int cy = (int) ((y1 - t1 * t1 * y0 - tSq * y2) / denom); return new int[] {cx, cy}; } – Andrey Novikov Jan 26 '11 at 20:03
-
1@AndreyNovikov you should post it as answer to help others – Tofeeq Ahmad Jan 08 '13 at 13:30
0
What about the cubicTo (or rCubicTo if you need it from a relative point) function? http://developer.android.com/reference/android/graphics/Path.html#cubicTo(float, float, float, float, float, float)

C0deAttack
- 24,419
- 18
- 73
- 81
-
cubicTo also uses Bezier splines, which do not provide what he needs. – Vincent Mimoun-Prat Jan 17 '11 at 10:54
-1
Here is a very nice, illustrated howto for javascript, but all the used methods are usual and there is an analogue in Androids Path Class

Skip
- 6,240
- 11
- 67
- 117