Search code examples
android2dandroid-canvascurve

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?


Solution

  • 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).