MathPlot
Sample.h
1 /*
2  * Sample.cpp
3  *
4  * Created on: 4 avr. 2023
5  * Author: Lionel
6  *
7  * This is the sample of the official wxMathplot widget
8  */
9 
10 #include "mathplot.h"
11 
15 class MySIN: public mpFX
16 {
17  public:
18  MySIN(double freq, double amp) :
19  mpFX(wxT("f(x) = SIN(x)"), mpALIGN_LEFT)
20  {
21  m_freq = freq;
22  m_amp = amp;
23  wxPen FXpen(*wxGREEN, 1, wxPENSTYLE_SOLID);
25  SetContinuity(false);
26  SetPen(FXpen);
28  SetStep(8);
29  }
30  virtual double GetY(double x)
31  {
32  return m_amp * sin(x / 6.283185 / m_freq);
33  }
34  virtual double GetMinY()
35  {
36  return -m_amp;
37  }
38  virtual double GetMaxY()
39  {
40  return m_amp;
41  }
42  protected:
43  double m_freq, m_amp;
44 };
45 
46 class MyFunction: public mpFXGeneric
47 {
48  public:
49  MyFunction() :
50  mpFXGeneric(wxT("f(x) = x/sqrt(sin(x)+2)"), mpALIGN_LEFT)
51  {
52  wxPen FXpen(*wxBLUE, 1, wxPENSTYLE_SOLID);
54  SetContinuity(false);
55  SetPen(FXpen);
57  }
58 
59  protected:
60  virtual double ComputeY(double x)
61  {
62  return x / (sqrt(sin(x) + 2));
63  }
64 };
65 
66 class MyPower: public mpFXGeneric
67 {
68  public:
69  MyPower() :
70  mpFXGeneric(wxT("f(x) = 10^x"), mpALIGN_LEFT)
71  {
72  SetContinuity(false);
74  }
75 
76  protected:
77  virtual double ComputeY(double x)
78  {
79  return pow(10, x);
80  }
81 };
82 
83 // MyCOSinverse
84 class MyCOSinverse: public mpFY
85 {
86  public:
87  MyCOSinverse(double freq, double amp) :
88  mpFY(wxT("g(y) = COS(y)"), mpALIGN_BOTTOM)
89  {
90  m_freq = freq;
91  m_amp = amp;
92  wxPen FYpen(*wxCYAN, 2, wxPENSTYLE_SOLID);
93  SetDrawOutsideMargins(false);
94  SetContinuity(true);
95  SetPen(FYpen);
97  SetSymbolSize(8);
98  SetStep(8);
99  }
100  virtual double GetX(double y)
101  {
102  return m_amp * cos(y / 6.283185 / m_freq);
103  }
104  virtual double GetMinX()
105  {
106  return -m_amp;
107  }
108  virtual double GetMaxX()
109  {
110  return m_amp;
111  }
112  protected:
113  double m_freq, m_amp;
114 };
115 
116 // MyLissajoux
117 class MyLissajoux: public mpFXY
118 {
119  double m_rad;
120  int m_idx;
121  public:
122  MyLissajoux(double rad) :
123  mpFXY(wxT("Lissajoux"))
124  {
125  m_rad = rad;
126  m_idx = 0;
127  wxPen FXYpen(*wxRED, 1, wxPENSTYLE_SOLID);
128  SetDrawOutsideMargins(false);
129  SetContinuity(false);
130  SetPen(FXYpen);
132  }
133  virtual bool GetNextXY(double* x, double* y)
134  {
135  if (m_idx < 360)
136  {
137  *x = m_rad * cos(m_idx / 6.283185 * 360);
138  *y = m_rad * sin(m_idx / 6.283185 * 360 * 3);
139  m_idx++;
140  return true;
141  }
142  else
143  {
144  return false;
145  }
146  }
147  virtual void Rewind()
148  {
149  m_idx = 0;
150  }
151  virtual double GetMinX()
152  {
153  return -m_rad;
154  }
155  virtual double GetMaxX()
156  {
157  return m_rad;
158  }
159  virtual double GetMinY()
160  {
161  return -m_rad;
162  }
163  virtual double GetMaxY()
164  {
165  return m_rad;
166  }
167 };
168 
169 class FixedBitwidth: public mpFX
170 {
171  int m_bitwidth;
172  public:
173  FixedBitwidth(int bitwidth) :
174  mpFX(wxT("Feste Bitbreite"))
175  {
176  m_bitwidth = bitwidth;
177  }
178 
179  virtual double GetY(double x)
180  {
181  if (x >= 0)
182  return m_bitwidth;
183  else
184  return 0;
185  }
186 };
187 
188 double ld(const double x)
189 {
190  return log(x) / log(2.0f);
191 }
192 
193 class Optimum: public mpFX
194 {
195  public:
196  Optimum() :
197  mpFX(wxT("Optimum ld(N)"))
198  {
199  }
200 
201  virtual double GetY(double x)
202  {
203  if (x >= 1)
204  return ld(x);
205  else
206  return 0;
207  }
208 };
209 
210 class Elias: public mpFX
211 {
212  public:
213  Elias() :
214  mpFX(wxT("Elias-Kodes"))
215  {
216  }
217 
218  virtual double GetY(double x)
219  {
220  if (x >= 1)
221  return floor(ld(x)) + 2.0 * floor(ld(1.0 + floor(ld(x))));
222  else
223  return 0;
224  }
225 };
226 
227 class Fibonacci: public mpFX
228 {
229  public:
230  Fibonacci() :
231  mpFX(wxT("Fibonacci-Kodes"))
232  {
233  }
234 
235  virtual double GetY(double N)
236  {
237  if (N >= 1)
238  {
239  /*
240  for (DWORD mask = 0; mask<N; mask++)
241  {
242  for (int i=0; i<N; i++)
243  {
244  if (mask
245 
246  }
247  }
248  */
249 
250  return N;
251  }
252  else
253  return 0;
254  }
255 };
virtual double GetMaxX()
Get inclusive right border of bounding box.
Definition: Sample.h:108
Draw a circle.
Definition: mathplot.h:670
Definition: Sample.h:46
virtual double GetY(double N)
Get function value for argument.
Definition: Sample.h:235
virtual double GetMaxX()
Get inclusive right border of bounding box.
Definition: Sample.h:155
virtual bool GetNextXY(double *x, double *y)
Get locus value for next N.
Definition: Sample.h:133
Draw a cross X.
Definition: mathplot.h:674
void SetPen(const wxPen &pen)
Set layer pen.
Definition: mathplot.h:1005
void SetDrawOutsideMargins(bool drawModeOutside)
Set Draw mode: inside or outside margins.
Definition: mathplot.h:1051
void SetContinuity(bool continuity)
Set the &#39;continuity&#39; property of the layer.
Definition: mathplot.h:1498
Abstract base class providing plot and labeling functionality for functions F:Y->X.
Definition: mathplot.h:1785
Abstract base class providing plot and labeling functionality for a locus plot F:N->X,Y.
Definition: mathplot.h:1850
virtual double ComputeY(double x)
The main computation of the FX function.
Definition: Sample.h:60
virtual double GetMinX()
Get inclusive left border of bounding box.
Definition: Sample.h:104
Definition: Sample.h:227
mpFX(const wxString &name=wxEmptyString, int flags=mpALIGN_RIGHT, unsigned int yAxisID=0)
Definition: mathplot.cpp:1166
Definition: Sample.h:193
Align the y-axis towards left plot.
Definition: mathplot.h:636
Create a generic FX function Override the ComputeY() function with your function. ...
Definition: mathplot.h:2179
Draw a square.
Definition: mathplot.h:671
Classic sinus curve.
Definition: Sample.h:15
void SetSymbolSize(int size)
Set symbol size.
Definition: mathplot.h:1541
Definition: Sample.h:84
Definition: Sample.h:210
virtual void Rewind()
Rewind value enumeration with mpFXY::GetNextXY.
Definition: Sample.h:147
virtual double GetMinX()
Get inclusive left border of bounding box.
Definition: Sample.h:151
virtual double GetY(double x)
Get function value for argument.
Definition: Sample.h:179
void SetStep(unsigned int step)
Set step for plot.
Definition: mathplot.h:1513
virtual double GetMaxY()
Get inclusive top border of bounding box.
Definition: Sample.h:163
Abstract base class providing plot and labeling functionality for functions F:X->Y.
Definition: mathplot.h:1723
virtual double GetY(double x)
Get function value for argument.
Definition: Sample.h:218
virtual double GetMinY()
Get inclusive bottom border of bounding box.
Definition: Sample.h:34
Definition: Sample.h:66
Align the x-axis towards bottom plot.
Definition: mathplot.h:626
virtual double GetMinY()
Get inclusive bottom border of bounding box.
Definition: Sample.h:159
Definition: Sample.h:117
Definition: Sample.h:169
virtual double GetY(double x)
Get function value for argument.
Definition: Sample.h:201
virtual double GetY(double x)
Get function value for argument.
Definition: Sample.h:30
virtual double ComputeY(double x)
The main computation of the FX function.
Definition: Sample.h:77
virtual double GetMaxY()
Get inclusive top border of bounding box.
Definition: Sample.h:38
void SetSymbol(mpSymbol symbol)
Set symbol.
Definition: mathplot.h:1527
virtual double GetX(double y)
Get function value for argument.
Definition: Sample.h:100