public static void Sinc3D(ChartStyle cs, DataSeriesSurface ds) { cs.Xmin = -8; cs.Xmax = 8; cs.Ymin = -8; cs.Ymax = 8; cs.Zmin = -0.5f; cs.Zmax = 1; cs.XTick = 4; cs.YTick = 4; cs.ZTick = 0.5f; ds.XLimitMin = cs.Xmin; ds.YLimitMin = cs.Ymin; ds.XSpacing = 0.5; ds.YSpacing = 0.5; ds.XNumber = Convert.ToInt16((cs.Xmax - cs.Xmin) / ds.XSpacing) + 1; ds.YNumber = Convert.ToInt16((cs.Ymax - cs.Ymin) / ds.YSpacing) + 1; Point3D[,] pts = new Point3D[ds.XNumber, ds.YNumber]; for (int i = 0; i < ds.XNumber; i++) { for (int j = 0; j < ds.YNumber; j++) { double x = ds.XLimitMin + i * ds.XSpacing; double y = ds.YLimitMin + j * ds.YSpacing; double r = Math.Sqrt(x * x + y * y) + 0.000001; double z = Math.Sin(r) / r; pts[i, j] = new Point3D(x, y, z); } } ds.PointArray = pts; }
public static void Peak3D(ChartStyle cs, DataSeriesSurface ds) { cs.Xmin = -3; cs.Xmax = 3; cs.Ymin = -3; cs.Ymax = 3; cs.Zmin = -8; cs.Zmax = 8; cs.XTick = 1; cs.YTick = 1; cs.ZTick = 4; ds.XLimitMin = cs.Xmin; ds.YLimitMin = cs.Ymin; ds.XSpacing = 0.2; ds.YSpacing = 0.2; ds.XNumber = Convert.ToInt16((cs.Xmax - cs.Xmin) / ds.XSpacing) + 1; ds.YNumber = Convert.ToInt16((cs.Ymax - cs.Ymin) / ds.YSpacing) + 1; Point3D[,] pts = new Point3D[ds.XNumber, ds.YNumber]; for (int i = 0; i < ds.XNumber; i++) { for (int j = 0; j < ds.YNumber; j++) { double x = ds.XLimitMin + i * ds.XSpacing; double y = ds.YLimitMin + j * ds.YSpacing; double z = 3 * Math.Pow((1 - x), 2) * Math.Exp(-x * x - (y + 1) * (y + 1)) - 10 * (0.2 * x - Math.Pow(x, 3) - Math.Pow(y, 5)) * Math.Exp(-x * x - y * y) - 1 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y); pts[i, j] = new Point3D(x, y, z); } } ds.PointArray = pts; }
public void AddSurfaceChart(ChartStyle cs, DataSeriesSurface ds) { switch (SurfaceChartType) { case SurfaceChartTypeEnum.Mesh: AddMesh(cs, ds); //AddColorBar(cs, ds); break; case SurfaceChartTypeEnum.MeshZ: AddMeshZ(cs, ds); break; case SurfaceChartTypeEnum.Waterfall: AddWaterfall(cs, ds); break; case SurfaceChartTypeEnum.Surface: AddSurface(cs, ds); break; } }
private void AddChart() { chartCanvas.Children.Clear(); cs = new ChartStyle(); cs.ChartCanvas = this.chartCanvas; cs.GridlinePattern = ChartStyle.GridlinePatternEnum.Solid; cs.Elevation = 30; cs.Azimuth = -37; cs.Title = "No Title"; cs.IsColorBar = true; cs.AddChartStyle(); ds = new DataSeriesSurface(); ds.LineColor = Brushes.Black; Utility.Peak3D(cs, ds); dsc = new DrawSurfaceChart(); dsc.SurfaceChartType = DrawSurfaceChart.SurfaceChartTypeEnum.Surface; dsc.IsColormap = true; dsc.IsHiddenLine = false; //dsc.IsInterp = true; //dsc.NumberInterp = 3; dsc.Colormap.ColormapBrushType = ColormapBrush.ColormapBrushEnum.Jet; dsc.AddSurfaceChart(cs, ds); }
public void AddColorBar(ChartStyle cs, DataSeriesSurface ds, double zmin, double zmax) { TextBlock tb; tb = new TextBlock(); tb.Text = "A"; tb.FontFamily = cs.TickFont; tb.FontSize = cs.TickFontSize; tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); Size tickSize = tb.DesiredSize; double x = 6 * cs.ChartCanvas.Width / 7; double y = cs.ChartCanvas.Height / 10; double width = cs.ChartCanvas.Width / 25; double height = 8 * cs.ChartCanvas.Height / 10; Point3D[] pts = new Point3D[64]; double dz = (zmax - zmin) / 63; // Create the color bar: Polygon plg; for (int i = 0; i < 64; i++) { pts[i] = new Point3D(x, y, zmin + i * dz); } for (int i = 0; i < 63; i++) { SolidColorBrush brush = GetBrush(pts[i].Z, zmin, zmax); double y1 = y + height - (pts[i].Z - zmin) * height / (zmax - zmin); double y2 = y + height - (pts[i + 1].Z - zmin) * height / (zmax - zmin); plg = new Polygon(); plg.Points.Add(new Point(x, y2)); plg.Points.Add(new Point(x + width, y2)); plg.Points.Add(new Point(x + width, y1)); plg.Points.Add(new Point(x, y1)); plg.Fill = brush; plg.Stroke = brush; cs.ChartCanvas.Children.Add(plg); } Rectangle rect = new Rectangle(); rect.Width = width + 2; rect.Height = height + 2; rect.Stroke = Brushes.Black; Canvas.SetLeft(rect, x - 1); Canvas.SetTop(rect, y - 1); cs.ChartCanvas.Children.Add(rect); // Add ticks and labels to the color bar: double tickLength = 0.15 * width; for (double z = zmin; z <= zmax; z = z + (zmax - zmin) / 6) { double yy = y + height - (z - zmin) * height / (zmax - zmin); AddTickLine(cs, new Point(x, yy), new Point(x + tickLength, yy)); AddTickLine(cs, new Point(x + width, yy), new Point(x + width - tickLength, yy)); tb = new TextBlock(); tb.Text = (Math.Round(z, 2)).ToString(); tb.FontFamily = cs.TickFont; tb.FontSize = cs.TickFontSize; cs.ChartCanvas.Children.Add(tb); Canvas.SetLeft(tb, x + width + 5); Canvas.SetTop(tb, yy - tickSize.Height / 2); } }
private void AddSurface(ChartStyle cs, DataSeriesSurface ds) { Matrix3D m = Utility.AzimuthElevation(cs.Elevation, cs.Azimuth); Polygon plg = new Polygon(); Point3D[,] pts = ds.PointArray; Point3D[,] pts1 = new Point3D[pts.GetLength(0), pts.GetLength(1)]; //double[,] zValues = new double[pts.GetLength(0), pts.GetLength(1)]; double zmin = ds.ZDataMin(); double zmax = ds.ZDataMax(); for (int i = 0; i < pts.GetLength(0); i++) { for (int j = 0; j < pts.GetLength(1); j++) { //zValues[i, j] = pts[i, j].Z; pts1[i, j] = pts[i, j]; pts[i, j] = cs.Normalize3D(m, pts[i, j]); } } // Draw surface chart: if (!IsInterp) { for (int i = 0; i < pts.GetLength(0) - 1; i++) { int ii = i; if (cs.Elevation >= 0) { ii = i; if (cs.Azimuth >= -180 && cs.Azimuth < 0) { ii = pts.GetLength(0) - 2 - i; } } else { ii = pts.GetLength(0) - 2 - i; if (cs.Azimuth >= -180 && cs.Azimuth < 0) { ii = i; } } for (int j = 0; j < pts.GetLength(1) - 1; j++) { int jj = j; if (cs.Elevation < 0) { jj = pts.GetLength(1) - 2 - j; } plg = new Polygon(); plg.Points.Add(new Point(pts[ii, jj].X, pts[ii, jj].Y)); plg.Points.Add(new Point(pts[ii, jj + 1].X, pts[ii, jj + 1].Y)); plg.Points.Add(new Point(pts[ii + 1, jj + 1].X, pts[ii + 1, jj + 1].Y)); plg.Points.Add(new Point(pts[ii + 1, jj].X, pts[ii + 1, jj].Y)); plg.StrokeThickness = ds.LineThickness; plg.Stroke = ds.LineColor; plg.Fill = GetBrush(pts1[ii, jj].Z, zmin, zmax); cs.ChartCanvas.Children.Add(plg); } } if (cs.IsColorBar && IsColormap) { AddColorBar(cs, ds, zmin, zmax); } } else if (IsInterp) { for (int i = 0; i < pts.GetLength(0) - 1; i++) { int ii = i; if (cs.Elevation >= 0) { ii = i; if (cs.Azimuth >= -180 && cs.Azimuth < 0) { ii = pts.GetLength(0) - 2 - i; } } else { ii = pts.GetLength(0) - 2 - i; if (cs.Azimuth >= -180 && cs.Azimuth < 0) { ii = i; } } for (int j = 0; j < pts.GetLength(1) - 1; j++) { int jj = j; if (cs.Elevation < 0) { jj = pts.GetLength(1) - 2 - j; } Point3D[] points = new Point3D[4]; points[0] = pts1[ii, j]; points[1] = pts1[ii, j + 1]; points[2] = pts1[ii + 1, j + 1]; points[3] = pts1[ii + 1, j]; Interp(cs, m, points, zmin, zmax); plg = new Polygon(); plg.Stroke = ds.LineColor; plg.Points.Add(new Point(pts[ii, j].X, pts[ii, j].Y)); plg.Points.Add(new Point(pts[ii, j + 1].X, pts[ii, j + 1].Y)); plg.Points.Add(new Point(pts[ii + 1, j + 1].X, pts[ii + 1, j + 1].Y)); plg.Points.Add(new Point(pts[ii + 1, j].X, pts[ii + 1, j].Y)); //cs.ChartCanvas.Children.Add(plg); } } } if (cs.IsColorBar && IsColormap) { AddColorBar(cs, ds, zmin, zmax); } }
private void AddWaterfall(ChartStyle cs, DataSeriesSurface ds) { Matrix3D m = Utility.AzimuthElevation(cs.Elevation, cs.Azimuth); Polygon plg = new Polygon(); Point3D[,] pts = ds.PointArray; Point3D[] pt3 = new Point3D[pts.GetLength(0) + 2]; double[] zValues = new double[pts.Length]; Point[] pta = new Point[pts.GetLength(0) + 2]; double zmin = ds.ZDataMin(); double zmax = ds.ZDataMax(); for (int j = 0; j < pts.GetLength(1); j++) { int jj = j; if (cs.Elevation >= 0) { if (cs.Azimuth >= -90 && cs.Azimuth < 90) { jj = pts.GetLength(1) - 1 - j; } } else if (cs.Elevation < 0) { jj = pts.GetLength(1) - 1 - j; if (cs.Azimuth >= -90 && cs.Azimuth < 90) { jj = j; } } for (int i = 0; i < pts.GetLength(0); i++) { pt3[i + 1] = pts[i, jj]; if (i == 0) { pt3[0] = new Point3D(pt3[i + 1].X, pt3[i + 1].Y, cs.Zmin); } if (i == pts.GetLength(0) - 1) { pt3[pts.GetLength(0) + 1] = new Point3D(pt3[i + 1].X, pt3[i + 1].Y, cs.Zmin); } } plg = new Polygon(); for (int i = 0; i < pt3.Length; i++) { zValues[i] = pt3[i].Z; pt3[i] = cs.Normalize3D(m, pt3[i]); pta[i] = new Point(pt3[i].X, pt3[i].Y); plg.Points.Add(new Point(pt3[i].X, pt3[i].Y)); } plg.Stroke = Brushes.Transparent; plg.StrokeThickness = ds.LineThickness; plg.Fill = Brushes.White; cs.ChartCanvas.Children.Add(plg); for (int i = 1; i < pt3.Length; i++) { Line line = new Line(); line.Stroke = Brushes.Black; line.StrokeThickness = ds.LineThickness; if (IsColormap) { if (i < pt3.Length - 1) { line.Stroke = GetBrush(zValues[i], zmin, zmax); } else { line.Stroke = GetBrush(zValues[i - 1], zmin, zmax); } } line.X1 = pta[i - 1].X; line.Y1 = pta[i - 1].Y; line.X2 = pta[i].X; line.Y2 = pta[i].Y; cs.ChartCanvas.Children.Add(line); } } if (cs.IsColorBar && IsColormap) { AddColorBar(cs, ds, zmin, zmax); } }
private void AddMeshZ(ChartStyle cs, DataSeriesSurface ds) { Matrix3D m = Utility.AzimuthElevation(cs.Elevation, cs.Azimuth); Polygon plg = new Polygon(); Point3D[,] pts = ds.PointArray; Point3D[,] pts1 = new Point3D[pts.GetLength(0), pts.GetLength(1)]; double[,] zValues = new double[pts.GetLength(0), pts.GetLength(1)]; double zmin = ds.ZDataMin(); double zmax = ds.ZDataMax(); for (int i = 0; i < pts.GetLength(0); i++) { for (int j = 0; j < pts.GetLength(1); j++) { zValues[i, j] = pts[i, j].Z; pts1[i, j] = new Point3D(pts[i, j].X, pts[i, j].Y, pts[i, j].Z); pts[i, j] = cs.Normalize3D(m, pts[i, j]); } } // Draw mesh using the z-order method: for (int i = 0; i < pts.GetLength(0) - 1; i++) { int ii = i; if (cs.Elevation >= 0) { ii = i; if (cs.Azimuth >= -180 && cs.Azimuth < 0) { ii = pts.GetLength(0) - 2 - i; } } else { ii = pts.GetLength(0) - 2 - i; if (cs.Azimuth >= -180 && cs.Azimuth < 0) { ii = i; } } for (int j = 0; j < pts.GetLength(1) - 1; j++) { int jj = j; if (cs.Elevation < 0) { jj = pts.GetLength(1) - 2 - j; } plg = new Polygon(); plg.Points.Add(new Point(pts[ii, jj].X, pts[ii, jj].Y)); plg.Points.Add(new Point(pts[ii, jj + 1].X, pts[ii, jj + 1].Y)); plg.Points.Add(new Point(pts[ii + 1, jj + 1].X, pts[ii + 1, jj + 1].Y)); plg.Points.Add(new Point(pts[ii + 1, jj].X, pts[ii + 1, jj].Y)); plg.Stroke = Brushes.Black; plg.StrokeThickness = ds.LineThickness; plg.Fill = Brushes.White; if (IsHiddenLine) { plg.Fill = Brushes.Transparent; } if (IsColormap) { plg.Stroke = GetBrush(zValues[ii, jj], zmin, zmax); } cs.ChartCanvas.Children.Add(plg); } } //Draw curtain lines: Point3D[] pta = new Point3D[4]; for (int i = 0; i < pts1.GetLength(0); i++) { int jj = pts1.GetLength(0) - 1; if (cs.Elevation >= 0) { if (cs.Azimuth >= -90 && cs.Azimuth <= 90) { jj = 0; } } else if (cs.Elevation < 0) { jj = 0; if (cs.Azimuth >= -90 && cs.Azimuth <= 90) { jj = pts1.GetLength(0) - 1; } } if (i < pts1.GetLength(0) - 1) { pta[0] = new Point3D(pts1[i, jj].X, pts1[i, jj].Y, pts1[i, jj].Z); pta[1] = new Point3D(pts1[i + 1, jj].X, pts1[i + 1, jj].Y, pts1[i + 1, jj].Z); pta[2] = new Point3D(pts1[i + 1, jj].X, pts1[i + 1, jj].Y, cs.Zmin); pta[3] = new Point3D(pts1[i, jj].X, pts1[i, jj].Y, cs.Zmin); for (int k = 0; k < 4; k++) { pta[k] = cs.Normalize3D(m, pta[k]); } plg = new Polygon(); plg.Stroke = Brushes.Black; plg.StrokeThickness = ds.LineThickness; plg.Fill = Brushes.White; plg.Points.Add(new Point(pta[0].X, pta[0].Y)); plg.Points.Add(new Point(pta[1].X, pta[1].Y)); plg.Points.Add(new Point(pta[2].X, pta[2].Y)); plg.Points.Add(new Point(pta[3].X, pta[3].Y)); if (IsHiddenLine) { plg.Fill = Brushes.Transparent; } if (IsColormap) { plg.Stroke = GetBrush(pts1[i, jj].Z, zmin, zmax); } cs.ChartCanvas.Children.Add(plg); } } for (int j = 0; j < pts1.GetLength(1); j++) { int ii = 0; if (cs.Elevation >= 0) { if (cs.Azimuth >= 0 && cs.Azimuth <= 180) { ii = pts1.GetLength(1) - 1; } } else if (cs.Elevation < 0) { if (cs.Azimuth >= -180 && cs.Azimuth <= 0) { ii = pts1.GetLength(1) - 1; } } if (j < pts1.GetLength(1) - 1) { pta[0] = new Point3D(pts1[ii, j].X, pts1[ii, j].Y, pts1[ii, j].Z); pta[1] = new Point3D(pts1[ii, j + 1].X, pts1[ii, j + 1].Y, pts1[ii, j + 1].Z); pta[2] = new Point3D(pts1[ii, j + 1].X, pts1[ii, j + 1].Y, cs.Zmin); pta[3] = new Point3D(pts1[ii, j].X, pts1[ii, j].Y, cs.Zmin); for (int k = 0; k < 4; k++) { pta[k] = cs.Normalize3D(m, pta[k]); } plg = new Polygon(); plg.Stroke = Brushes.Black; plg.StrokeThickness = ds.LineThickness; plg.Fill = Brushes.White; plg.Points.Add(new Point(pta[0].X, pta[0].Y)); plg.Points.Add(new Point(pta[1].X, pta[1].Y)); plg.Points.Add(new Point(pta[2].X, pta[2].Y)); plg.Points.Add(new Point(pta[3].X, pta[3].Y)); if (IsHiddenLine) { plg.Fill = Brushes.Transparent; } if (IsColormap) { plg.Stroke = GetBrush(pts1[ii, j].Z, zmin, zmax); } cs.ChartCanvas.Children.Add(plg); } } if (cs.IsColorBar && IsColormap) { AddColorBar(cs, ds, zmin, zmax); } }
private void AddMesh(ChartStyle cs, DataSeriesSurface ds) { Matrix3D m = Utility.AzimuthElevation(cs.Elevation, cs.Azimuth); Polygon plg = new Polygon(); Point3D[,] pts = ds.PointArray; double[,] zValues = new double[pts.GetLength(0), pts.GetLength(1)]; double zmin = ds.ZDataMin(); double zmax = ds.ZDataMax(); for (int i = 0; i < pts.GetLength(0); i++) { for (int j = 0; j < pts.GetLength(1); j++) { zValues[i, j] = pts[i, j].Z; pts[i, j] = cs.Normalize3D(m, pts[i, j]); } } // Draw mesh chart: for (int i = 0; i < pts.GetLength(0) - 1; i++) { int ii = i; if (cs.Elevation >= 0) { ii = i; if (cs.Azimuth >= -180 && cs.Azimuth < 0) { ii = pts.GetLength(0) - 2 - i; } } else { ii = pts.GetLength(0) - 2 - i; if (cs.Azimuth >= -180 && cs.Azimuth < 0) { ii = i; } } for (int j = 0; j < pts.GetLength(1) - 1; j++) { int jj = j; if (cs.Elevation < 0) { jj = pts.GetLength(1) - 2 - j; } plg = new Polygon(); plg.Points.Add(new Point(pts[ii, jj].X, pts[ii, jj].Y)); plg.Points.Add(new Point(pts[ii, jj + 1].X, pts[ii, jj + 1].Y)); plg.Points.Add(new Point(pts[ii + 1, jj + 1].X, pts[ii + 1, jj + 1].Y)); plg.Points.Add(new Point(pts[ii + 1, jj].X, pts[ii + 1, jj].Y)); plg.Stroke = Brushes.Black; plg.StrokeThickness = ds.LineThickness; plg.Fill = Brushes.White; if (IsHiddenLine) { plg.Fill = Brushes.Transparent; } if (IsColormap) { plg.Stroke = GetBrush(zValues[ii, jj], zmin, zmax); } cs.ChartCanvas.Children.Add(plg); } } if (cs.IsColorBar && IsColormap) { AddColorBar(cs, ds, zmin, zmax); } }