Cardioid Simulations in C++ ImGui

Markus Buchholz
3 min readMar 18, 2023

--

Carodoid is a geometrical shape drawn on the surface by a rolling circle on the other circle with the same radius. Please considered the process of generation on the below simulation,

Generation of cardioid (by author)

The following article describes the generation process of the cardioid curve and later depicts the process of creation of cardioid as the envelope of a pencil of lines.

The introduction to the C++ ImGui and information on how to compile and build programs you will find in one of my previous articles.

The source code for all presented simulations you will find on my GitHub.

Mathematical model and simulations

The parametric representation of the cardioid can be expressed by following set of equations,

where a is the radius of the circle.

The above stimulation explains visually the creation process.

Besides cardioid can be drawn by rolling the circle on the other circle (as shown above) there exists another approach to creating this beautiful shape. One of them can be explained as follows.

Circe has to be decided by a particular number of points. The below figure displays the circle divided by 10 points. The length of the arc between is equal. Now we need to draw the lines between the points depending on some factor (here I applied factor equals 2). The factor equals 2 which means that we have to connect (by line) the following points (0, 0), (1,2), (2, 4) , (3, 6), (4, 8) etc. If the factor equals 3 so we connect as follows (0, 0), (1,3) (2, 6) , (3, 9), (4, 9+3) etc. The other point of the connecting line as you can see always equals the number of start point times factor.

Process of creation cardioid by lines between points on the circle (by author)

Now the magic happens. If we enlarge the number of points to 200 (for example) and keep the same factor equals so we cardioid shape can be raised. See below.

Cardioid “created” by lines. (by author)

If the factor, we discuss before will be increased to 3 so we receive another interesting shape called nephroid.

Nephroid (by author)

Similarly to the previous one adjusting the factor to 7, we can draw another interesting shape.

“Cardioid” with the factor equals 7 (by author)

The extraordinary effect can be achieved in the simulation process where during the simulation run we change the factor. Enjoy simulation.

Simulation of changeable connecting factor (by author)

Than you for reading.

--

--