13 double[][,,] vectorField,
14 double xMin,
double xMax,
15 double yMin,
double yMax,
16 double zMin,
double zMax,
17 double[,,]? divergence =
null,
18 double[][,,]? curl =
null,
19 double? px =
null,
double? py =
null,
double? pz =
null)
21 InitializeComponent();
23 this.Text =
"3D-Vektorfeld Visualisierung";
24 this.Size =
new Size(900, 700);
25 this.BackColor = Color.FromArgb(33, 33, 33);
28 var host =
new ElementHost { Dock = DockStyle.Fill };
29 var viewPort =
new HelixViewport3D
31 Background =
new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(25, 25, 25)),
32 ZoomExtentsWhenLoaded =
true
34 host.Child = viewPort;
36 var fillColor =
new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(160, 160, 160));
38 var gridXY =
new GridLinesVisual3D
44 Center =
new Point3D(0, 0, 0),
45 Normal =
new Vector3D(0, 0, 1),
48 viewPort.Children.Add(gridXY);
51 var gridXZ =
new GridLinesVisual3D
57 Center =
new Point3D(0, 0, 0),
58 Normal =
new Vector3D(0, 1, 0),
61 viewPort.Children.Add(gridXZ);
64 var gridYZ =
new GridLinesVisual3D
70 Center =
new Point3D(0, 0, 0),
71 Normal =
new Vector3D(1, 0, 0),
74 viewPort.Children.Add(gridYZ);
76 var labelX =
new BillboardTextVisual3D
79 Position =
new Point3D(5.5, 0, 0),
80 Foreground = System.Windows.Media.Brushes.White,
81 Background = System.Windows.Media.Brushes.Transparent
83 viewPort.Children.Add(labelX);
86 var labelY =
new BillboardTextVisual3D
89 Position =
new Point3D(0, 5.5, 0),
90 Foreground = System.Windows.Media.Brushes.White,
91 Background = System.Windows.Media.Brushes.Transparent
93 viewPort.Children.Add(labelY);
96 var labelZ =
new BillboardTextVisual3D
99 Position =
new Point3D(0, 0, 5.5),
100 Foreground = System.Windows.Media.Brushes.White,
101 Background = System.Windows.Media.Brushes.Transparent
103 viewPort.Children.Add(labelZ);
105 viewPort.Children.Add(
new DefaultLights());
107 int sizeX = vectorField[0].GetLength(0);
108 int sizeY = vectorField[0].GetLength(1);
109 int sizeZ = vectorField[0].GetLength(2);
111 double stepX = (xMax - xMin) / sizeX;
112 double stepY = (yMax - yMin) / sizeY;
113 double stepZ = (zMax - zMin) / sizeZ;
116 for (
int i = 0; i < sizeX; i++)
118 for (
int j = 0; j < sizeY; j++)
120 for (
int k = 0; k < sizeZ; k++)
122 double x = xMin + i * stepX;
123 double y = yMin + j * stepY;
124 double z = zMin + k * stepZ;
126 double fx = vectorField[0][i, j, k];
127 double fy = vectorField[1][i, j, k];
128 double fz = vectorField[2][i, j, k];
130 if (
double.IsFinite(fx) &&
double.IsFinite(fy) &&
double.IsFinite(fz))
132 var arrow =
new ArrowVisual3D
134 Point1 =
new Point3D(x, y, z),
135 Point2 =
new Point3D(x + fx * 0.2, y + fy * 0.2, z + fz * 0.2),
137 Fill = System.Windows.Media.Brushes.White
139 viewPort.Children.Add(arrow);
146 Panel? leftPanel =
null;
148 if ((divergence !=
null || curl !=
null) && px.HasValue && py.HasValue && pz.HasValue)
150 string infoText =
"";
152 int i = (int)((px.Value - xMin) / (xMax - xMin) * sizeX);
153 int j = (int)((py.Value - yMin) / (yMax - yMin) * sizeY);
154 int k = (int)((pz.Value - zMin) / (zMax - zMin) * sizeZ);
156 i = Math.Clamp(i, 0, sizeX - 1);
157 j = Math.Clamp(j, 0, sizeY - 1);
158 k = Math.Clamp(k, 0, sizeZ - 1);
160 if (divergence !=
null)
162 double divVal = divergence[i, j, k];
163 infoText += $
"Divergenz: ∇·F(x, y, z):\n {Math.Round(divVal, 4)}\n\n";
168 double cx = curl[0][i, j, k];
169 double cy = curl[1][i, j, k];
170 double cz = curl[2][i, j, k];
171 infoText += $
"Rotation:∇×F:\n ({Math.Round(cx, 4)}, {Math.Round(cy, 4)}, {Math.Round(cz, 4)})";
174 var label =
new Label
177 ForeColor = Color.White,
179 Location =
new Point(10, 20),
180 BackColor = Color.FromArgb(33, 33, 33)
183 leftPanel =
new Panel
186 Dock = DockStyle.Fill,
187 BackColor = Color.FromArgb(33, 33, 33)
189 leftPanel.Controls.Add(label);
193 if ((divergence !=
null || curl !=
null) && px.HasValue && py.HasValue && pz.HasValue)
195 string infoText =
"";
197 int i = (int)((px.Value - xMin) / (xMax - xMin) * sizeX);
198 int j = (int)((py.Value - yMin) / (yMax - yMin) * sizeY);
199 int k = (int)((pz.Value - zMin) / (zMax - zMin) * sizeZ);
201 i = Math.Clamp(i, 0, sizeX - 1);
202 j = Math.Clamp(j, 0, sizeY - 1);
203 k = Math.Clamp(k, 0, sizeZ - 1);
205 if (divergence !=
null)
207 double divVal = divergence[i, j, k];
208 infoText += $
"Divergenz:\n∇·F(x, y, z) = {Math.Round(divVal, 4)}\n\n";
213 double cx = curl[0][i, j, k];
214 double cy = curl[1][i, j, k];
215 double cz = curl[2][i, j, k];
216 infoText += $
"Rotation:\n∇×F = ({Math.Round(cx, 4)}, {Math.Round(cy, 4)}, {Math.Round(cz, 4)})";
219 var label =
new Label
222 ForeColor = Color.White,
224 Location =
new Point(10, 20),
225 BackColor = Color.FromArgb(33, 33, 33)
227 leftPanel.Controls.Add(label);
231 var layout =
new TableLayoutPanel
233 Dock = DockStyle.Fill,
238 if (leftPanel !=
null)
240 layout.ColumnStyles.Add(
new ColumnStyle(SizeType.Absolute, 220));
241 layout.ColumnStyles.Add(
new ColumnStyle(SizeType.Percent, 100));
242 layout.Controls.Add(leftPanel, 0, 0);
243 layout.Controls.Add(host, 1, 0);
247 layout.ColumnCount = 1;
248 layout.ColumnStyles.Add(
new ColumnStyle(SizeType.Percent, 100));
249 layout.Controls.Add(host, 0, 0);
252 this.Controls.Add(layout);