Microscopic Traffic Simulator
ZoomValuesGenerator.cs
Go to the documentation of this file.
1 using System;
2 using System.Globalization;
3 using System.Windows;
4 using System.Windows.Media;
5 
6 namespace Microscopic_Traffic_Simulator.Renderers
7 {
9  {
15  public double GetYValue(double x)
16  {
17  Point P0 = new Point(0.0, 0.01);
18  Point P1 = new Point(50.0, 1.0);
19  Point P2 = P1;
20  Point P3 = new Point(100.0, 100.0);
21  Point V0 = new Point(125.0, 0);
22  Point V1 = new Point(1.0, 0.1);
23  Point V2 = V1;
24  Point V3 = new Point(0.0, 287.0);
25 
26  double eps = 0.000001;
27 
28  if (x <= 0.0)
29  return 0.01;
30  else if (x == 50.0)
31  return 1.0;
32  else if (x >= 100.0)
33  return 100.0;
34  //assign value t to 0.5
35  double t = 0.5;
36  //number to add or subtract to t
37  double toAddOrSubtract = 0.25;
38  //determine which part of curve to search
39  Point p0, p1, v0, v1;
40  if (x < 50.0)
41  { //lower part 0-5
42  p0 = P0;
43  p1 = P1;
44  v0 = V0;
45  v1 = V1;
46  }
47  else
48  { //higher part 5-10
49  p0 = P2;
50  p1 = P3;
51  v0 = V2;
52  v1 = V3;
53  }
54  //ofdResult point
55  Point point = new Point();
56  //coefficients
57  double f1, f2, f3, f4;
58  //search for linear number
59  do
60  {
61  //compute coefficients
62  f1 = F1(t);
63  f2 = F2(t);
64  f3 = F3(t);
65  f4 = F4(t);
66  //compute X ofdResult
67  point.X = p0.X * f1 + p1.X * f2 + v0.X * f3 + v1.X * f4;
68  //adjust t
69  if (x > point.X)
70  t += toAddOrSubtract;
71  else
72  t -= toAddOrSubtract;
73  toAddOrSubtract /= 2;
74  } while (Math.Abs(x - point.X) > eps);//end if we are too close
75  //return Y value
76  double Yvalue = p0.Y * f1 + p1.Y * f2 + v0.Y * f3 + v1.Y * f4;
77  return Yvalue;
78  }
79 
85  protected double F1(double t)
86  {
87  return 2 * Math.Pow(t, 3) - 3 * Math.Pow(t, 2) + 1;
88  }
89 
95  protected double F2(double t)
96  {
97  return -2 * Math.Pow(t, 3) + 3 * Math.Pow(t, 2);
98  }
99 
105  protected double F3(double t)
106  {
107  return Math.Pow(t, 3) - 2 * Math.Pow(t, 2) + t;
108  }
109 
115  protected double F4(double t)
116  {
117  return Math.Pow(t, 3) - Math.Pow(t, 2);
118  }
119 
124  public void Draw(DrawingContext dc)
125  {
126  double ellipseRadius = 2.0;
127  double enhancer = 8.0;
128  double enhancerX = 1.0;
129  double enhancerY = 1.0;
130  for (int x = 0; x <= 100; x++)
131  {
132  double y = GetYValue(x);
133  Brush br = Brushes.Black;
134  if (x == 50 || x == 0 || x == 100)
135  {
136  br = Brushes.Red;
137  }
138  //Console.WriteLine("X: " + x + ", Y: " + y);
139  Console.Write(y.ToString(CultureInfo.InvariantCulture) + ",");
140  dc.DrawEllipse(br, null, new Point(x * enhancer * enhancerX, (100.0 * enhancer * enhancerY) -
141  (y * enhancer * enhancerY)), ellipseRadius, ellipseRadius);
142  }
143 
144  enhancer = 8.0;
145  enhancerX = 1.0;
146  enhancerY = 48.0;
147  for (int x = 0; x <= 55; x++)
148  {
149  double y = GetYValue(x);
150  Brush br = Brushes.Green;
151  if (x == 50 || x == 0 || x == 100)
152  {
153  br = Brushes.Red;
154  }
155  dc.DrawEllipse(br, null, new Point(x * enhancer * enhancerX, (100.0 * enhancer) -
156  ((100.0 * enhancer * enhancerY) - ((100 - y) * enhancer * enhancerY))),
157  ellipseRadius, ellipseRadius);
158  }
159  }
160  }
161 }
double GetYValue(double x)
Gets Y Value for X value for Ferguson cubics.
void Draw(DrawingContext dc)
Draw points to visualize Ferguson cubic used for determining zoom rates from some interval...
double F3(double t)
Method as part of computing value in X axis for Ferguson cubic.
double F4(double t)
Method as part of computing value in X axis for Ferguson cubic.
double F1(double t)
Method as part of computing value in X axis for Ferguson cubic.
double F2(double t)
Method as part of computing value in X axis for Ferguson cubic.