ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
FunctionGenerator.h
Go to the documentation of this file.
1/**
2 * @file FunctionGenerator.h
3 * @brief Provides a generator for common mathematical wave functions.
4 *
5 * @date 22/12/2024
6 * @version 1.0
7 * @author Coela Can't
8 */
9
10#pragma once
11
12#include <Arduino.h>
13#include "../Math/Mathematics.h"
14
15/**
16 * @class FunctionGenerator
17 * @brief A class to generate various waveform functions with customizable parameters.
18 */
20public:
21 /**
22 * @enum Function
23 * @brief Enumerates the supported wave functions.
24 */
25 enum Function {
26 Triangle, ///< Triangle waveform.
27 Square, ///< Square waveform.
28 Sine, ///< Sine waveform.
29 Sawtooth, ///< Sawtooth waveform.
30 Gravity ///< Gravity-like function.
31 };
32
33private:
34 Function function; ///< Current waveform function.
35 float minimum = 0.0f; ///< Minimum value of the waveform.
36 float maximum = 0.0f; ///< Maximum value of the waveform.
37 float period = 0.0f; ///< Period of the waveform.
38
39 /**
40 * @brief Generates a triangle wave value.
41 * @param ratio The input ratio (0 to 1).
42 * @return The output wave value.
43 */
44 float TriangleWave(float ratio);
45
46 /**
47 * @brief Generates a square wave value.
48 * @param ratio The input ratio (0 to 1).
49 * @return The output wave value.
50 */
51 float SquareWave(float ratio);
52
53 /**
54 * @brief Generates a sine wave value.
55 * @param ratio The input ratio (0 to 1).
56 * @return The output wave value.
57 */
58 float SineWave(float ratio);
59
60 /**
61 * @brief Generates a sawtooth wave value.
62 * @param ratio The input ratio (0 to 1).
63 * @return The output wave value.
64 */
65 float SawtoothWave(float ratio);
66
67 /**
68 * @brief Generates a gravity-like function value.
69 * @param ratio The input ratio (0 to 1).
70 * @return The output wave value.
71 */
72 float GravityFunction(float ratio);
73
74public:
75 /**
76 * @brief Constructor to initialize the FunctionGenerator with parameters.
77 * @param function The waveform function to use.
78 * @param minimum The minimum value of the waveform.
79 * @param maximum The maximum value of the waveform.
80 * @param period The period of the waveform.
81 */
83
84 /**
85 * @brief Sets the period of the waveform.
86 * @param period The new period.
87 */
88 void SetPeriod(float period);
89
90 /**
91 * @brief Sets the waveform function.
92 * @param function The new waveform function.
93 */
95
96 /**
97 * @brief Updates and calculates the next value of the waveform.
98 * @return The calculated wave value.
99 */
100 float Update();
101};
A class to generate various waveform functions with customizable parameters.
float SquareWave(float ratio)
Generates a square wave value.
void SetPeriod(float period)
Sets the period of the waveform.
float SawtoothWave(float ratio)
Generates a sawtooth wave value.
float minimum
Minimum value of the waveform.
float maximum
Maximum value of the waveform.
Function
Enumerates the supported wave functions.
@ Square
Square waveform.
@ Gravity
Gravity-like function.
@ Sawtooth
Sawtooth waveform.
@ Sine
Sine waveform.
@ Triangle
Triangle waveform.
float GravityFunction(float ratio)
Generates a gravity-like function value.
float Update()
Updates and calculates the next value of the waveform.
Function function
Current waveform function.
float SineWave(float ratio)
Generates a sine wave value.
void SetFunction(Function function)
Sets the waveform function.
float TriangleWave(float ratio)
Generates a triangle wave value.
float period
Period of the waveform.