hasanghaforian
hasanghaforian

Reputation: 14022

Drawing 2D curves in Android canvas?

How we can draw 2D curves like this in Canvas?

enter image description here enter image description here enter image description here

All similar curves have mathematical formula or are fractals, but the canvas only has some methods for drawing simple shapes like a triangle or rectangle. I know that most curves can divide into simpler shapes such as with drawing a Heart Curve, but is there an easier way to draw 2D curves with the canvas?

Upvotes: 1

Views: 5626

Answers (3)

Morrison Chang
Morrison Chang

Reputation: 12121

If you look up how to draw 2D curves in general you'll either be drawing points or lines and it only looks smooth.

Your question has two parametric forms and one fractal form. All can be drawn with lines and points. The parametric forms can be done directly via the algorithms in your question or could be transformed into more general ones like the Bezier curve as mentioned by @leenephi

Most of the time the equations/algorithms for generating fractals are using lines, Koch Snowflake, or points, the Mandelbrot set. If you actually understand how to generate them, you'll see that fractals are less about drawing 'a curve' and more about process (recursion) and results (self-similarity).

Upvotes: 1

leenephi
leenephi

Reputation: 900

Using the Path object you can do some fancier lines and curves in the Canvas. Just randomly found these two questions concerning those; I hope they can point you in the right direction as I personally have not used them.

Draw a perfect curve connecting three points

Bezier curve and canvas

Upvotes: 3

Henry
Henry

Reputation: 43728

You have to approximate the curve by simpler primitives for example short line segments.

Upvotes: 0

Related Questions