How could I draw a quadratic curve or a trigonometric curve (such as sin(x)
) on a Canvas
?
Like you, I needed to draw a curved line from point(x1, y1)
to point (x2, y2)
. I did some searching around which lead me to the Path class (android.graphics.Path
). Path has numerous methods for drawing lines. Once you have created a path you use a draw method to make the actual line. The paths can be rotated, transformed, saved, and added to. There are arcs, circles, and rectangles that be drawn with this class too.
http://developer.android.com/reference/android/graphics/Path.html
Set start point of path → mPath.moveTo(x1, y1);
Set constant and end points → mPath.quadTo(cx, cy, x2, y2);
Convert path to line → canvas.drawPath(mPath, mPaint);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With