Synthia
Generic and flexible data structure generator
Lissajous.java
Go to the documentation of this file.
1 /*
2  Synthia, a data structure generator
3  Copyright (C) 2019-2021 Laboratoire d'informatique formelle
4  Université du Québec à Chicoutimi, Canada
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 package examples.oscilloscope;
20 
24 import ca.uqac.lif.synthia.util.Tick;
26 
27 /**
28  * Uses the {@link SineWave} picker with the {@link PrismPicker} to generate
29  * <a href="https://en.wikipedia.org/wiki/Lissajous_curve">Lissajous figures</a>
30  * on an oscilloscope screen.
31  * <p>
32  * The wiring diagram of pickers in this program is given below:
33  * <p>
34  * <img src="./doc-files/oscilloscope/Lissajous.png" alt="Wiring diagram" />
35  * <p>
36  * We recall that a {@link SineWave} picker produces an output that corresponds
37  * to the equation <i>A</i> sin(&omega;<i>t</i>+&phi;), where <i>A</i>, &omega;
38  * and &phi; are pickers corresponding to amplitude, frequency and phase,
39  * respectively. The program depends on two parameters:
40  * <ul>
41  * <li>the frequency ratio &omega;<sub>2</sub>/&omega;<sub>1</sub> between the
42  * two sine wave pickers, noted <i>m</i></li>
43  * <li>the phase difference &omega;<sub>2</sub>(&phi;<sub>2</sub> &minus;
44  * &phi;<sub>1</sub>), where the term &phi;<sub>2</sub> &minus;
45  * &phi;<sub>1</sub> is noted <i>n</i>
46  * </ul>
47  * <p>The program picks 1,000 points, and then plots them in a window that
48  * simulates the operation of an {@link Oscilloscope}.
49  * You can run the program by changing these values to produce various figures.
50  * Here are some classical examples:
51  * <p>
52  * <table cellpadding="5">
53  * <tr>
54  * <th>Figure</th>
55  * <td><img src="./doc-files/oscilloscope/Lissajous_r_1_p_0.png" alt="Lissajous figure" /></td>
56  * <td><img src="./doc-files/oscilloscope/Lissajous_r_2_p_5_pi_8.png" alt="Lissajous figure" /></td>
57  * <td><img src="./doc-files/oscilloscope/Lissajous_r_6_5_p_pi_4.png" alt="Lissajous figure" /></td>
58  * </tr>
59  * <tr>
60  * <th>Parameters</th>
61  * <td>m = 1, n = 0</td>
62  * <td>m = 2, n = 5&pi;/8</td>
63  * <td>m = 6/5, n = &pi;/4</td>
64  * </tr>
65  * </table>
66  * <p><strong>Caution:</strong> pay attention when entering ratios such as 4/3;
67  * you must make sure they are interpreted as a {@link double}; hence you must
68  * write <tt>4d/3</tt> (the <tt>d</tt> forces a cast to <tt>double</tt>).
69  *
70  * @ingroup Examples
71  */
72 public class Lissajous
73 {
74  @SuppressWarnings("unchecked")
75  public static void main(String[] args)
76  {
77  /* The frequency ratio between the two sine wave pickers. */
78  double ratio = 2;
79 
80  /* The phase difference between the two sine wave pickers. Since many
81  * interesting Lissajous figures have their phase expressed in multiples of
82  * frequency, the phase will multiplied by the frequency in the picker
83  * below. */
84  double phase = 5 * Math.PI / 8d;
85 
86  // Generator for x-coordinate
87  SineWave x = new SineWave(
88  new Constant<Number>(1), // amplitude
89  new Tick(new Constant<Number>(0), new Constant<Number>(1)), // frequency
90  new Constant<Number>(0) // phase
91  );
92  // Generator for y-coordinate
93  SineWave y = new SineWave(
94  new Constant<Number>(1), // amplitude
95  new Tick(new Constant<Number>(0), new Constant<Number>(ratio)), // frequency
96  new Constant<Number>(ratio * phase) // phase
97  );
98  // Create a list of 10000 points out of x and y values
99  PrismPicker points = new PrismPicker(x, y);
100  ComposeList<float[]> set = new ComposeList<float[]>(points, 1000);
101  // Display these points in our "oscilloscope"
102  Oscilloscope o = new Oscilloscope().addPoints(set.pick());
103  o.setVisible(true);
104  }
105 }
examples.oscilloscope.Oscilloscope.addPoints
Oscilloscope addPoints(List< float[]> points)
Definition: Oscilloscope.java:68
ca.uqac.lif.synthia.collection
Pickers generating and manipulating collections, such as lists and sets.
Definition: ComparableList.java:19
ca.uqac.lif.synthia.util
Miscellaneous pickers performing various functions.
Definition: ArrayPicker.java:19
examples.oscilloscope.Lissajous
Uses the SineWave picker with the PrismPicker to generate Lissajous figures on an oscilloscope screen...
Definition: Lissajous.java:72
ca.uqac.lif.synthia.vector.PrismPicker
Generates a vector by independently picking a value for each of its coordinates.
Definition: PrismPicker.java:38
ca.uqac.lif.synthia.vector
Pickers generating multi-dimensional numerical vectors.
Definition: HyperspherePicker.java:19
ca.uqac
ca.uqac.lif.synthia
Definition: Bounded.java:19
ca.uqac.lif.synthia.util.Constant
Picker that returns the same object every time.
Definition: Constant.java:37
ca.uqac.lif.synthia.signal
Pickers producing values representing a form of (periodic) signal.
Definition: package-info.java:24
examples.oscilloscope.Oscilloscope
A simple JFrame that simulates the operation of an oscilloscope.
Definition: Oscilloscope.java:46
ca.uqac.lif
ca.uqac.lif.synthia.util.Tick
Generates a sequence of monotonically increasing numerical values.
Definition: Tick.java:51
ca
examples.oscilloscope.Lissajous.main
static void main(String[] args)
Definition: Lissajous.java:75
ca.uqac.lif.synthia.signal.SineWave
A periodic signal picker producing a sine wave.
Definition: SineWave.java:28
ca.uqac.lif.synthia.collection.ComposeList
Definition: ComposeList.java:44