13 double[][,] vectorField,
14 double xMin,
double xMax,
15 double yMin,
double yMax,
16 double[,]? divergence =
null,
17 double[,]? rotation =
null,
21 InitializeComponent();
24 this.Text =
"Vektorfeld Visualisierung";
25 this.Size =
new Size(900, 700);
26 this.BackColor = System.Drawing.Color.FromArgb(33, 33, 33);
29 var formsPlot =
new FormsPlot();
30 formsPlot.Dock = DockStyle.Fill;
31 var plt = formsPlot.Plot;
33 int sizeX = vectorField[0].GetLength(0);
34 int sizeY = vectorField[0].GetLength(1);
35 double stepX = (xMax - xMin) / sizeX;
36 double stepY = (yMax - yMin) / sizeY;
39 for (
int i = 0; i < sizeX; i++)
41 for (
int j = 0; j < sizeY; j++)
43 double x = xMin + i * stepX;
44 double y = yMin + j * stepY;
45 double fx = vectorField[0][i, j];
46 double fy = vectorField[1][i, j];
48 if (
double.IsFinite(fx) &&
double.IsFinite(fy))
50 var arrow = plt.Add.Arrow(x, y, x + fx * 0.2, y + fy * 0.2);
57 Panel? leftPanel =
null;
58 if ((divergence !=
null || rotation !=
null) && px.HasValue && py.HasValue)
60 leftPanel =
new Panel();
61 leftPanel.Dock = DockStyle.Fill;
62 leftPanel.Width = 200;
63 leftPanel.BackColor = System.Drawing.Color.FromArgb(33, 33, 33);
67 if (divergence !=
null)
69 int i = (int)((px.Value - xMin) / (xMax - xMin) * divergence.GetLength(0));
70 int j = (int)((py.Value - yMin) / (yMax - yMin) * divergence.GetLength(1));
71 i = Math.Clamp(i, 0, divergence.GetLength(0) - 1);
72 j = Math.Clamp(j, 0, divergence.GetLength(1) - 1);
73 double divVal = divergence[i, j];
74 infoText += $
"Divergenz: ∇·F(x, y): \n {Math.Round(divVal, 4)}\n\n";
79 int i = (int)((px.Value - xMin) / (xMax - xMin) * rotation.GetLength(0));
80 int j = (int)((py.Value - yMin) / (yMax - yMin) * rotation.GetLength(1));
81 i = Math.Clamp(i, 0, rotation.GetLength(0) - 1);
82 j = Math.Clamp(j, 0, rotation.GetLength(1) - 1);
83 double rotVal = rotation[i, j];
84 infoText += $
"Rotation: ∇×F(x, y): \n {Math.Round(rotVal, 4)}";
87 var infoLabel =
new System.Windows.Forms.Label();
88 infoLabel.Text = infoText;
89 infoLabel.ForeColor = System.Drawing.Color.White;
90 infoLabel.BackColor = System.Drawing.Color.FromArgb(33, 33, 33);
91 infoLabel.AutoSize =
true;
92 infoLabel.Location =
new Point(10, 20);
93 leftPanel.Controls.Add(infoLabel);
97 plt.FigureBackground.Color = Colors.Black;
98 plt.DataBackground.Color =
new ScottPlot.Color(33, 33, 33);
99 plt.Axes.Color(Colors.White);
100 plt.Axes.Left.Label.Text =
"y";
101 plt.Axes.Bottom.Label.Text =
"x";
104 var layout =
new TableLayoutPanel();
105 layout.Dock = DockStyle.Fill;
106 layout.ColumnCount = 2;
108 layout.ColumnStyles.Add(
new ColumnStyle(SizeType.Absolute, 200));
109 layout.ColumnStyles.Add(
new ColumnStyle(SizeType.Percent, 100));
110 layout.RowStyles.Add(
new RowStyle(SizeType.Percent, 100));
112 if (leftPanel !=
null)
113 layout.Controls.Add(leftPanel, 0, 0);
115 layout.ColumnStyles[0].Width = 0;
117 layout.Controls.Add(formsPlot, 1, 0);
118 this.Controls.Add(layout);