VectorVisualizer Version 1.2
by Kevin Seib and Pascal Glaeser
Loading...
Searching...
No Matches
VektorPlotForm2D.cs
Go to the documentation of this file.
1using System;
2using System.Drawing;
3using System.Windows.Forms;
4using ScottPlot;
5using ScottPlot.Plottables;
6using ScottPlot.WinForms;
7
9{
10 public partial class VektorPlotForm2D : Form
11 {
13 double[][,] vectorField, // [0]=Fx, [1]=Fy
14 double xMin, double xMax,
15 double yMin, double yMax,
16 double[,]? divergence = null,
17 double[,]? rotation = null,
18 double? px = null,
19 double? py = null)
20 {
21 InitializeComponent();
22
23 // Fenster Setup
24 this.Text = "Vektorfeld Visualisierung";
25 this.Size = new Size(900, 700);
26 this.BackColor = System.Drawing.Color.FromArgb(33, 33, 33);
27
28 // ScottPlot vorbereiten
29 var formsPlot = new FormsPlot();
30 formsPlot.Dock = DockStyle.Fill;
31 var plt = formsPlot.Plot;
32
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;
37
38 // Vektorfeld zeichnen
39 for (int i = 0; i < sizeX; i++)
40 {
41 for (int j = 0; j < sizeY; j++)
42 {
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];
47
48 if (double.IsFinite(fx) && double.IsFinite(fy))
49 {
50 var arrow = plt.Add.Arrow(x, y, x + fx * 0.2, y + fy * 0.2);
51
52 }
53 }
54 }
55
56 // Info-Panel vorbereiten (falls gewünscht)
57 Panel? leftPanel = null;
58 if ((divergence != null || rotation != null) && px.HasValue && py.HasValue)
59 {
60 leftPanel = new Panel();
61 leftPanel.Dock = DockStyle.Fill;
62 leftPanel.Width = 200;
63 leftPanel.BackColor = System.Drawing.Color.FromArgb(33, 33, 33);
64
65 string infoText = "";
66
67 if (divergence != null)
68 {
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";
75 }
76
77 if (rotation != null)
78 {
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)}";
85 }
86
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);
94 }
95
96 // Plot-Design
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";
102
103 // Layout
104 var layout = new TableLayoutPanel();
105 layout.Dock = DockStyle.Fill;
106 layout.ColumnCount = 2;
107 layout.RowCount = 1;
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));
111
112 if (leftPanel != null)
113 layout.Controls.Add(leftPanel, 0, 0);
114 else
115 layout.ColumnStyles[0].Width = 0;
116
117 layout.Controls.Add(formsPlot, 1, 0);
118 this.Controls.Add(layout);
119
120
121 formsPlot.Refresh();
122 }
123 }
124}
VektorPlotForm2D(double[][,] vectorField, double xMin, double xMax, double yMin, double yMax, double[,]? divergence=null, double[,]? rotation=null, double? px=null, double? py=null)