Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Oscillator o = new Oscillator(1);
- o.startOscillator();
- Console.ReadKey(true);
- }
- }
- public class Oscillator
- {
- private double r; //Радиус колеса, образующего циклоиду
- private double L;
- private double T; //Период колебаний
- private double phi; //Фаза колебаний
- private System.Timers.Timer timer; //Таймер, чтобы считать положение маятника в зависимости от времени
- private DateTime startTime; //Время запуска маятника
- private double maxSkewAngle;
- private double p;
- public Oscillator(double r)
- {
- this.r = r;
- this.L = 4 * r;
- T = 2 * Math.PI * Math.Sqrt(L / 9.81); //T = 2 * Pi * Sqrt(L/g), L = 4a
- timer = new System.Timers.Timer();
- if (T < 1)
- {
- timer.Interval = T * 1000; //В милисекундах
- }
- else
- {
- timer.Interval = 100;
- }
- timer.Elapsed += oscillatorCoord;
- timer.AutoReset = true;
- timer.Enabled = true;
- }
- void oscillatorCoord(object sender, System.Timers.ElapsedEventArgs e)
- {
- double phase = (e.SignalTime - startTime).TotalSeconds / T;
- //Привести фазу к фи[0; 2Pi]
- double n = phase / (2 * Math.PI);
- phi = (n - Math.Truncate(n)) * 2 * Math.PI;
- phi -= Math.PI;
- double x = r * (phi - Math.Sin(phi));
- double y = r * (1 + Math.Cos(phi));
- Console.Write("e.SignalTime - startTime = ");
- Console.Write((e.SignalTime - startTime).TotalSeconds);
- Console.Write("; phase = ");
- Console.Write(phase);
- Console.Write("; phi = ");
- Console.Write(phi);
- Console.Write("; x = ");
- Console.Write(x);
- Console.Write("; y = ");
- Console.WriteLine(y);
- }
- public void startOscillator()
- {
- startTime = DateTime.Now;
- timer.Start();
- p = 10;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement