T Periodic Functions in C++
usingMaths.com
Demonstrating and showing pupils and students one application of Mathematics.







<< PreviousNext >>

Code to Animate an Image Body through a Sine or Cosine Curve in C++




How to Simulate Sinusoidal Curves in C++

Periodic functions produce an infinite order of sinusoidal curves.
The sine function has the general form y = asinθ;
and the cosine function has the general form y = acosθ + c;
where θ is angle in radians and a is an arbitrary constant that heightens the curve.



Code to Animate a Graphic Object through a Periodic Curve in C++

To make a graphic (dot) travel by the equation of a sine / cosine function, continuously increment θ by some angle interval (in radians), and use the equation to get the corresponding y value; using any c that gives a satisfactory height.

Create a new class;
Call it PeriodicFunction.
Type out the adjoining C++ code for animating an image body through the path of a sine / cosine curve.



Note: To get a cosine curve animation, just replace sin with cos.










<< PreviousNext >>