How do I draw a curve through tree points in Android?

北战南征 提交于 2019-12-04 19:23:14

问题


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?


回答1:


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.




回答2:


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)




回答3:


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



来源:https://stackoverflow.com/questions/4712003/how-do-i-draw-a-curve-through-tree-points-in-android

标签

工具导航Map