VectorVisualizer Version 1.2
by Kevin Seib and Pascal Glaeser
Loading...
Searching...
No Matches
ScalarField3DView.xaml.cs
Go to the documentation of this file.
1using System;
2using System.Windows.Media;
3using System.Windows.Media.Media3D;
4using HelixToolkit.Wpf;
5
7{
8 public partial class ScalarField3DView : System.Windows.Controls.UserControl
9 {
11 {
12 InitializeComponent();
13 }
14
15 public void PlotSurfaceLevel(
16 Func<double, double, double, double> scalarField3D,
17 double xMin, double xMax,
18 double yMin, double yMax,
19 double zFixed, int resolution,
20 double? px = null, double? py = null, double? pz = null,
21 double[] gradient = null)
22 {
23 ViewPort.Children.Clear();
24 ViewPort.Children.Add(new DefaultLights());
25
26 double dx = (xMax - xMin) / resolution;
27 double dy = (yMax - yMin) / resolution;
28 var meshBuilder = new MeshBuilder(false, false);
29
30 for (int i = 0; i < resolution; i++)
31 {
32 for (int j = 0; j < resolution; j++)
33 {
34 double x0 = xMin + i * dx;
35 double x1 = x0 + dx;
36 double y0 = yMin + j * dy;
37 double y1 = y0 + dy;
38
39 double z00 = scalarField3D(x0, y0, zFixed);
40 double z10 = scalarField3D(x1, y0, zFixed);
41 double z11 = scalarField3D(x1, y1, zFixed);
42 double z01 = scalarField3D(x0, y1, zFixed);
43
44 meshBuilder.AddQuad(
45 new Point3D(x0, y0, z00),
46 new Point3D(x1, y0, z10),
47 new Point3D(x1, y1, z11),
48 new Point3D(x0, y1, z01)
49 );
50 }
51 }
52
53 var mesh = meshBuilder.ToMesh();
54 var material = MaterialHelper.CreateMaterial(Colors.Cyan);
55 var geom = new GeometryModel3D { Geometry = mesh, Material = material, BackMaterial = material };
56 ViewPort.Children.Add(new ModelVisual3D { Content = geom });
57
58 // Marker anzeigen, wenn übergeben
59 if (px.HasValue && py.HasValue && pz.HasValue)
60 {
61 var sphere = new SphereVisual3D
62 {
63 Center = new Point3D(px.Value, py.Value, pz.Value),
64 Radius = (xMax - xMin) * 0.02,
65 Fill = Brushes.Red
66 };
67 ViewPort.Children.Add(sphere);
68 }
69 // XY-Ebene (Z = konstant)
70 var gridXY = new GridLinesVisual3D
71 {
72 Width = 10,
73 Length = 10,
74 MinorDistance = 1,
75 Thickness = 0.01,
76 Center = new Point3D(0, 0, 0),
77 Normal = new Vector3D(0, 0, 1), // Z-Richtung → XY-Ebene
78 Fill = Brushes.Gray
79 };
80 ViewPort.Children.Add(gridXY);
81
82 // XZ-Ebene (Y = konstant)
83 var gridXZ = new GridLinesVisual3D
84 {
85 Width = 10,
86 Length = 10,
87 MinorDistance = 1,
88 Thickness = 0.01,
89 Center = new Point3D(0, 0, 0),
90 Normal = new Vector3D(0, 1, 0), // Y-Richtung → XZ-Ebene
91 Fill = Brushes.DimGray
92 };
93 ViewPort.Children.Add(gridXZ);
94
95 // YZ-Ebene (X = konstant)
96 var gridYZ = new GridLinesVisual3D
97 {
98 Width = 10,
99 Length = 10,
100 MinorDistance = 1,
101 Thickness = 0.01,
102 Center = new Point3D(0, 0, 0),
103 Normal = new Vector3D(1, 0, 0), // X-Richtung → YZ-Ebene
104 Fill = Brushes.DarkGray
105 };
106 ViewPort.Children.Add(gridYZ);
107
108
109 }
110 }
111}
void PlotSurfaceLevel(Func< double, double, double, double > scalarField3D, double xMin, double xMax, double yMin, double yMax, double zFixed, int resolution, double? px=null, double? py=null, double? pz=null, double[] gradient=null)