Understanding Periodic Functions | Maths Explanation for C# Kids
Periodic functions are fundamental in both mathematics and computer programming. In senior secondary maths, students learn that functions such as sine and cosine repeat their values at regular intervals. In this lesson, we extend that understanding by exploring how periodic functions in C# can be used to animate and visualise sine and cosine waves using the C# Windows Form.
By combining mathematical theory with coding, students can clearly see how amplitude, period, and frequency affect the shape and motion of a wave.
What Are Periodic Functions? | Maths Explanation for C# Kids
A periodic function is a function that repeats its values at fixed intervals. The length of one complete cycle is called the period.
For example:
- The sine function repeats every \( 2\pi \)
- The cosine function repeats every \( 2\pi \)
Mathematically, a function \( f(x) \) is periodic if:
where $T$ is the period.
Common real-world examples of periodic motion include:
- Ocean waves
- Sound waves
- Alternating current (AC electricity)
- Pendulum motion
Understanding periodic behaviour in mathematics makes it easier to model these phenomena in code.
Properties of Periodic Functions: Period, Amplitude & Frequency | Maths Explanation for C# Kids
Every periodic function has three key properties:
- Amplitude - the maximum height of the wave from its central position.
- Period - the horizontal distance over which the function repeats.
- Frequency - the number of complete cycles per unit interval.
Understanding these properties helps in analyzing periodic function graphs and predicting their patterns.
How to Simulate Sinusoidal Curves in C#
Periodic functions produce an infinite order of sinusoidal curves.
The sine function has the general form
$$ y = a \times sin(\theta) + c; $$
and the cosine function has the general form
$$ y = a \times cos(\theta) + c; $$
where $\theta$ is angle in radians and $a$ is an arbitrary constant that heightens the curve.
Animating a Periodic Wave Using C#
We can animate a sine or cosine wave in C# using the C# Windows Form. By incrementing $\theta$ continuously and computing y using the trigonometric function, a dot or object moves along a periodic path that represents the wave. The angle $\theta$ is in radians, and you can use any $c$ value that gives a satisfactory amplitude.
Create a new C# Windows Forms Application
project
;
call it Dymetric_CS.
Create 2 new C# classes;
Call them Dymetric and PeriodicFunction.
Type out the adjoining C# code for animating an image body through the path of a sine / cosine curve.
This code draws one complete periodic sine wave, allowing students to observe how the function repeats its pattern.
Exploring the Cosine Function in C#
Similar to the sine wave, we can animate the cosine curve using C# trigonometric animation techniques.
Note: To create a C# cosine wave animation, simply replace Math.Sin with Math.Cos.
Why Visualising Periodic Functions Matters
Seeing a moving wave helps reinforce important mathematical ideas:
- The connection between algebraic equations and graphs
- The meaning of amplitude and frequency
- How transformations change a function's appearance
- The relationship between maths and real-world wave motion
By combining trigonometry with programming, students gain a deeper conceptual understanding of periodic functions.
Real-World Applications of Periodic Functions with C#
Periodic functions are used in:
- Electrical engineering (AC signals)
- Audio processing (sound waves)
- Physics (simple harmonic motion)
- Computer graphics
- Game development
- Signal processing
Understanding periodic functions in mathematics and implementing them in C# provides practical computational skills.
Key Takeaways on Periodic Wave Animation in C#
In this tutorial, you've learned:
- Periodic functions repeat after a fixed interval called the period
- They are fundamental in trigonometry, wave analysis, and C# visualizations.
- Use the C# graphing example to explore amplitude, period, and phase shift interactively.
By blending mathematics and coding, students can better visualize abstract periodic concepts and prepare for advanced studies in both fields.
Summary: Periodic vs Aperiodic Functions | Maths Explanation for C# Kids
Not every function repeats itself.
- A periodic function has a consistent cycle (e.g., sine, cosine).
- An aperiodic function does not repeat (e.g., linear or exponential functions).
Understanding this difference helps students see why periodic motion is predictable - an important skill in physics, sound, and electrical circuits.
Periodic functions are essential in senior secondary mathematics and have powerful applications in programming. By using C# to animate sine and cosine waves, students can visually explore amplitude, period, and frequency in action.
Understanding periodic functions in C# bridges the gap between mathematical theory and practical coding skills — making abstract concepts interactive, dynamic, and easier to understand.
So! C# Fun Practice Exercise - Animate along Periodic Wave
As a fun practice exercise, try modifying parameters like amplitude or frequency to explore how periodic functions in C# behave. You can also:
- Plot \( f(\theta) = a \times cos(\theta) + c \)
- Plot \( f(\theta) = a \times sin(2\theta) + c \)
- Write a C# function that combines sine and cosine
This will be a great way to connect mathematics and programming, and help you understand more about C# animations and periodic functions.
C# Periodic Wave Window Display Code Stub
C# Periodic Wave Code for Dymetric Class
namespace Dymetric
{
class Dymetric
{
private PeriodicFunction sine_curve;
private bool do_simulation;
public Dymetric(int screen_width, int screen_height)
{
sine_curve = new PeriodicFunction(screen_width, screen_height);
do_simulation = false;
}
// decide what course of action to take
public void decideAction(PaintEventArgs e, bool click_check)
{
if (do_simulation && click_check)
{
// do animation
sine_curve.inPlay(e);
do_simulation = false;
}
else
{
// Put ball on screen
sine_curve.clearAndDraw(e);
do_simulation = true;
}
}
}
}
C# Animation Code for Periodic Function Class
using System.Threading;
using System.Drawing;
using System.Windows.Forms;
namespace Dymetric
{
class PeriodicFunction
{
private int theta, a, y, half_vert_screen;
private const int dotDIAMETER = 10;
// we'll be drawing to and from a bitmap image
private Bitmap offscreen_bitmap;
Graphics offscreen_g;
private Brush dot_colour, bg_colour;
public PeriodicFunction(int screen_width, int screen_height)
{
dot_colour = new SolidBrush(Color.Yellow);
bg_colour = new SolidBrush(Color.LightGray);
// Create bitmap image
offscreen_bitmap = new Bitmap(screen_width, screen_height - 55,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
// point graphic object to bitmap image
offscreen_g = Graphics.FromImage(offscreen_bitmap);
// Set background of bitmap graphic
offscreen_g.Clear(Color.LightGray);
theta = 0;
a = offscreen_bitmap.Height / 3; // constant
// half way down the vertical section of the screen
half_vert_screen = offscreen_bitmap.Height / 2 - dotDIAMETER / 2;
y = (int)Math.Round(a * Math.Sin(theta * Math.PI / 180)) + half_vert_screen;
}
// draw first appearance of dot on the screen
public void clearAndDraw(PaintEventArgs e)
{
/*
* draw to offscreen bitmap
*/
// clear entire bitmap
offscreen_g.Clear(Color.LightGray);
// draw x-axis line
offscreen_g.DrawLine(Pens.Black, 0, half_vert_screen + dotDIAMETER / 2,
offscreen_bitmap.Width, half_vert_screen + dotDIAMETER / 2);
// draw dot
offscreen_g.FillEllipse(dot_colour, theta, y, dotDIAMETER, dotDIAMETER);
// draw to screen
Graphics gr = e.Graphics;
gr.DrawImage(offscreen_bitmap, 0, 55, offscreen_bitmap.Width, offscreen_bitmap.Height);
}
// repetitively clear and draw dot on the screen - Simulate motion
public void inPlay(PaintEventArgs e)
{
Graphics gr = e.Graphics;
// condition for continuing motion
while (theta < offscreen_bitmap.Width - dotDIAMETER)
{
// redraw dot
offscreen_g.FillEllipse(dot_colour, theta, y, dotDIAMETER, dotDIAMETER);
// draw to screen
gr.DrawImage(offscreen_bitmap, 0, 55, offscreen_bitmap.Width, offscreen_bitmap.Height);
theta += 15;
y = (int)Math.Round(a * Math.Sin(theta * Math.PI / 180)) + half_vert_screen;
// take a time pause
Thread.Sleep(50);
}
theta = 0;
y = (int)Math.Round(a * Math.Sin(theta * Math.PI / 180)) + half_vert_screen;
}
}
}