Click here to Skip to main content
13,354,132 members (59,807 online)
Click here to Skip to main content
Add your own
alternative version


45 bookmarked
Posted 22 Dec 2009


, 22 Dec 2009
Rate this:
Please Sign up or sign in to vote.
A Windows Forms control to model the behaviour of a hypocycloid curve.


Math problems have a charm of their own. Besides, they help to develop a programmer's skill. Here, we describe a student's exam task: "Develop an application that models the behaviour of a Hypocycloid".



A cycloid is the curve defined by the path of a point on the edge of a circular wheel as the wheel rolls along a straight line. It was named by Galileo in 1599 (

A hypocycloid is a curve generated by the trace of a fixed point on a small circle that rolls within a larger circle. It is comparable to the cycloid, but instead of the circle rolling along a line, it rolls within a circle.

Use Google to find a wonderful book of Eli Maor, Trigonometric Delights (Princeton, New Jersey). The following passage is taken from this book.

I believe that a program developer must love formulas derivation. Hence, let us find the parametric equations of the hypocycloid.


A point on a circle of radius r rolls on the inside of a fixed circle of radius R. Let C be the center of the rolling circle, and P a point on the moving circle. When the rolling circle turns through an angle in a clockwise direction, C traces an arc of angular width t in a counterclockwise direction. Assuming that the motion starts when P is in contact with the fixed circle (figure on the left), we choose a coordinate system in which the origin is at O and the x-axis points to P. The coordinates of P relative to C are:

(r cos b; -r sin b)

The minus sign in the second coordinate is there because b is measured clockwise. Coordinates of C relative to O are:

((R - r) cos t, (R - r) sin t)

Note, angle b may be expressed as:

b = t + β; β = b - t

Thus, the coordinates of P relative to O are:

((R - r) cos t + r cos β, (R - r) sin t - r sin β) (1)

But the angles t and b are not independent: as the motion progresses, the arcs of the fixed and moving circles that come in contact must be of equal length L.

L = R t L = r b

Using this relation to express b in terms of t, we get

b = R t / r

Equations (1) become:

x = (R - r) cos t + r cos ((R / r - 1) t) (2)
y = (R - r) sin t - r sin ((R / r - 1) t)

Equations (2) are the parametric equations of the hypocycloid, the angle t being the parameter (if the rolling circle rotates with constant angular velocity, t will be proportional to the elapsed time since the motion began). The general shape of the curve depends on the ratio R/r. If this ratio is a fraction m/n in lowest terms, the curve will have m cusps (corners), and it will be completely traced after moving the wheel n times around the inner rim. If R/r is irrational, the curve will never close, although going around the rim many times will nearly close it.

Using the code

The demo application provided with this article uses a Hypocycloid control derived from UserControl to model a behaviour of a hypocycloid described above.

The functionality of the hypocycloid is implemented in the Hypocycloid class. It has a GraphicsPath path data field that helps to render the hypocycloid path over time. A floating point variable, angle, corresponds to the angle t described earlier.

  • Variable ratio = R / r
  • delta = R - r

All the math is done within the timer Tick event handler.

void timer_Tick(object sender, EventArgs e)
   angle += step;
    cosa = Math.Cos(angle),
    sina = Math.Sin(angle),
    ct = ratio * angle;

   movingCenter.X = (float)(centerX + delta * cosa);
   movingCenter.Y = (float)(centerY + delta * sina);
   PointF old = point;
   point = new PointF(
     movingCenter.X + r * (float)Math.Cos(ct),
     movingCenter.Y - r * (float)Math.Sin(ct));
   int n = (int)(angle / pi2);
   if (n > round)
     round = n;
     ParentNotify(msg + ";" + round);
   if (round < nRounds)
    path.AddLine(old, point);
   else if (!stopPath)
     ParentNotify(msg + ";" + round + ";" + path.PointCount);
     stopPath = true;

ParentNotify is the event of the generic delegate type Action<string>.

public event Action<string> ParentNotify;

We use it to notify a parent control of a current angle (round).

Besides a constructor, the class has the following public methods: Reset, Draw, Start, Stop, and SaveToFile. Remember also that the Y axis in a Windows window goes down.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Alexander Chernosvitov
Instructor / Trainer Peter the Great St.Petersburg Polytechnic Universi
Russian Federation Russian Federation
Peter the Great St. Petersburg Polytechnic University professor,
Microsoft Authorized Educational Center trainer,
Microsoft Certified Professional (C# Desktop Apps and MFC)
Lectures on OOP, C# and C++, Windows programming with C# and C++.
Have long practice and experience in finding the right way to formulate and numerically solve differential equations.

You may also be interested in...

Comments and Discussions

Suggestionestimate Pin
Member 1040519015-Nov-13 22:49
memberMember 1040519015-Nov-13 22:49 
GeneralMy vote of 5 Pin
manoj kumar choubey14-Mar-12 5:46
membermanoj kumar choubey14-Mar-12 5:46 
GeneralAll I have to say is Spirograph Pin
Keith Vinson10-May-11 9:13
memberKeith Vinson10-May-11 9:13 
GeneralMy vote of 5 Pin
Dima Popov3-Nov-10 5:29
memberDima Popov3-Nov-10 5:29 
GeneralMy vote of 4 Pin
Member 448140713-Oct-10 18:41
memberMember 448140713-Oct-10 18:41 
GeneralGood.. Pin
Steppenwolfe16-Jan-10 7:13
memberSteppenwolfe16-Jan-10 7:13 
Generalmy vote of 2 Pin
Maximus Byamukama12-Jan-10 3:13
memberMaximus Byamukama12-Jan-10 3:13 
Generalvery good Pin
manzoni8610-Jan-10 22:26
membermanzoni8610-Jan-10 22:26 
GeneralMy vote of 1 Pin
gbelov28-Dec-09 22:05
membergbelov28-Dec-09 22:05 
GeneralRe: My vote of 1 Pin
icetea9429-Dec-09 6:58
membericetea9429-Dec-09 6:58 
AnswerContributing to an open source .NET project about cryptography Pin
Member 189546128-Dec-09 12:41
memberMember 189546128-Dec-09 12:41 
GeneralCool Pin
Pierre Nocera28-Dec-09 10:00
memberPierre Nocera28-Dec-09 10:00 
GeneralGood one Pin
bigRahn28-Dec-09 9:55
memberbigRahn28-Dec-09 9:55 
GeneralRe: Good one Pin
konikula28-Dec-09 11:32
memberkonikula28-Dec-09 11:32 
General:: Yeahh Pin
DIEGO FELDNER28-Dec-09 6:47
memberDIEGO FELDNER28-Dec-09 6:47 
GeneralBravo, very nice Pin
Greizzerland23-Dec-09 1:47
memberGreizzerland23-Dec-09 1:47 
GeneralAmazing [modified] Pin
OmarGamil23-Dec-09 0:50
memberOmarGamil23-Dec-09 0:50 
GeneralNice Pin
Uroš Šmon22-Dec-09 20:56
memberUroš Šmon22-Dec-09 20:56 
GeneralPure Beaty Pin
Mos Dan - Lucian22-Dec-09 13:17
memberMos Dan - Lucian22-Dec-09 13:17 
GeneralThats pretty cool actually. Pin
Sacha Barber22-Dec-09 6:50
mvpSacha Barber22-Dec-09 6:50 
GeneralIt warms my heart Pin
sam.hill22-Dec-09 6:12
membersam.hill22-Dec-09 6:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 22 Dec 2009
Article Copyright 2009 by Alexander Chernosvitov
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid