Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw a curved path on Canvas?

How could I draw a quadratic curve or a trigonometric curve (such as sin(x)) on a Canvas?

like image 473
Mohit Deshpande Avatar asked Mar 17 '11 02:03

Mohit Deshpande


1 Answers

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);

like image 62
droid1698104 Avatar answered Sep 22 '22 22:09

droid1698104