public void Line3D(DataSeries ds, Axes ax) { ax.XMin = -1f; ax.XMax = 1f; ax.YMin = -1f; ax.YMax = 1f; ax.ZMin = 0; ax.ZMax = 30; ax.XTick = 0.5f; ax.YTick = 0.5f; ax.ZTick = 5; ds.XDataMin = ax.XMin; ds.YDataMin = ax.YMin; ds.XSpacing = 0.3f; ds.YSpacing = 0.3f; ds.XNumber = Convert.ToInt16((ax.XMax - ax.XMin) / ds.XSpacing) + 1; ds.YNumber = Convert.ToInt16((ax.YMax - ax.YMin) / ds.YSpacing) + 1; ds.PointList.Clear(); for (int i = 0; i < 300; i++) { float t = 0.1f * i; float x = (float)Math.Exp(-t / 30) * (float)Math.Cos(t); float y = (float)Math.Exp(-t / 30) * (float)Math.Sin(t); float z = t; ds.AddPoint(new Point3(x, y, z, 1)); } }
public Chart3D() { InitializeComponent(); this.SetStyle(ControlStyles.ResizeRedraw, true); cs = new ChartStyle(this); cs2d = new ChartStyle2D(this); dc = new DrawChart(this); ds = new DataSeries(); ax = new Axes(this); va = new ViewAngle(this); gd = new Grid(this); cl = new ChartLabels(this); gd.GridStyle.LineColor = Color.LightGray; this.BackColor = Color.White; cm = new ColorMap(); dc.CMap = cm.Jet(); }
public void Exp4D(DataSeries ds, Axes ax) { ax.XMin = -2; ax.XMax = 2; ax.YMin = -2; ax.YMax = 2; ax.ZMin = -2; ax.ZMax = 2; ax.XTick = 1; ax.YTick = 1; ax.ZTick = 1; ds.XDataMin = ax.XMin; ds.YDataMin = ax.YMin; ds.ZZDataMin = ax.ZMin; ds.XSpacing = 0.1f; ds.YSpacing = 0.1f; ds.ZSpacing = 0.1f; ds.XNumber = Convert.ToInt16((ax.XMax - ax.XMin) / ds.XSpacing) + 1; ds.YNumber = Convert.ToInt16((ax.YMax - ax.YMin) / ds.YSpacing) + 1; ds.ZNumber = Convert.ToInt16((ax.ZMax - ax.ZMin) / ds.ZSpacing) + 1; Point4[, ,] pts = new Point4[ds.XNumber, ds.YNumber, ds.ZNumber]; for (int i = 0; i < ds.XNumber; i++) { for (int j = 0; j < ds.YNumber; j++) { for (int k = 0; k < ds.ZNumber; k++) { float x = ds.XDataMin + i * ds.XSpacing; float y = ds.YDataMin + j * ds.YSpacing; float z = ax.ZMin + k * ds.ZSpacing; float v = z * (float)Math.Exp(-x * x - y * y - z * z); pts[i, j, k] = new Point4(new Point3(x, y, z, 1), v); } } } ds.Point4Array = pts; }
public void SinROverR3D(DataSeries ds, Axes ax) { ax.XMin = -8; ax.XMax = 8; ax.YMin = -8; ax.YMax = 8; ax.ZMin = -0.5f; ax.ZMax = 1; ax.XTick = 4; ax.YTick = 4; ax.ZTick = 0.5f; ds.XDataMin = ax.XMin; ds.YDataMin = ax.YMin; ds.XSpacing = 0.5f; ds.YSpacing = 0.5f; ds.XNumber = Convert.ToInt16((ax.XMax - ax.XMin) / ds.XSpacing) + 1; ds.YNumber = Convert.ToInt16((ax.YMax - ax.YMin) / ds.YSpacing) + 1; Point3[,] pts = new Point3[ds.XNumber, ds.YNumber]; for (int i = 0; i < ds.XNumber; i++) { for (int j = 0; j < ds.YNumber; j++) { float x = ds.XDataMin + i * ds.XSpacing; float y = ds.YDataMin + j * ds.YSpacing; float r = (float)Math.Sqrt(x * x + y * y) + 0.000001f; float z = (float)Math.Sin(r) / r; pts[i, j] = new Point3(x, y, z, 1); } } ds.PointArray = pts; }
private void AddSlice(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; SolidBrush aBrush = new SolidBrush(Color.Black); Point4[, ,] pts = ds.Point4Array; PointF[] pta = new PointF[4]; Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); // Find the minumum and maximum v values: float vmin = ds.VDataMin(); float vmax = ds.VDataMax(); // Perform transformation on points: for (int i = 0; i < pts.GetLength(0); i++) { for (int j = 0; j < pts.GetLength(1); j++) { for (int k = 0; k < pts.GetLength(2); k++) { pts[i, j, k].point3.Transform(m, chart3d, ax, cs, cl); pts[i, j, k].point3.Z = pts[i, j, k].V; } } } // Select slice: if (XYZSlice == SliceEnum.XSlice) { if (SliceLocation < ax.XMin) SliceLocation = ax.XMin; if (SliceLocation > ax.XMax) SliceLocation = ax.XMax; int nfix = (int)((SliceLocation - ds.XDataMin) / ds.XSpacing) + 1; for (int j = 0; j < pts.GetLength(1) - 1; j++) { for (int k = 0; k < pts.GetLength(2) - 1; k++) { pta[0] = new PointF(pts[nfix, j, k].point3.X, pts[nfix, j, k].point3.Y); pta[1] = new PointF(pts[nfix, j + 1, k].point3.X, pts[nfix, j + 1, k].point3.Y); pta[2] = new PointF(pts[nfix, j + 1, k + 1].point3.X, pts[nfix, j + 1, k + 1].point3.Y); pta[3] = new PointF(pts[nfix, j, k + 1].point3.X, pts[nfix, j, k + 1].point3.Y); Color color = AddColor(cs, pts[nfix, j, k].point3, vmin, vmax, ax, va, cl); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); if (ds.LineStyle.IsVisible) { g.DrawPolygon(aPen, pta); } } } } else if (XYZSlice == SliceEnum.YSlice) { if (SliceLocation < ax.YMin) SliceLocation = ax.YMin; if (SliceLocation > ax.YMax) SliceLocation = ax.YMax; int nfix = (int)((SliceLocation - ds.YDataMin) / ds.YSpacing) + 1; for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int k = 0; k < pts.GetLength(2) - 1; k++) { pta[0] = new PointF(pts[i, nfix, k].point3.X, pts[i, nfix, k].point3.Y); pta[1] = new PointF(pts[i + 1, nfix, k].point3.X, pts[i + 1, nfix, k].point3.Y); pta[2] = new PointF(pts[i + 1, nfix, k + 1].point3.X, pts[i + 1, nfix, k + 1].point3.Y); pta[3] = new PointF(pts[i, nfix, k + 1].point3.X, pts[i, nfix, k + 1].point3.Y); Color color = AddColor(cs, pts[i, nfix, k].point3, vmin, vmax, ax, va, cl); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); if (ds.LineStyle.IsVisible) { g.DrawPolygon(aPen, pta); } } } } else if (XYZSlice == SliceEnum.ZSlice) { if (SliceLocation < ax.ZMin) SliceLocation = ax.ZMin; if (SliceLocation > ax.ZMax) SliceLocation = ax.ZMax; int nfix = (int)((SliceLocation - ds.ZZDataMin) / ds.ZSpacing) + 1; for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { pta[0] = new PointF(pts[i, j, nfix].point3.X, pts[i, j, nfix].point3.Y); pta[1] = new PointF(pts[i + 1, j, nfix].point3.X, pts[i + 1, j, nfix].point3.Y); pta[2] = new PointF(pts[i + 1, j + 1, nfix].point3.X, pts[i + 1, j + 1, nfix].point3.Y); pta[3] = new PointF(pts[i, j + 1, nfix].point3.X, pts[i, j + 1, nfix].point3.Y); Color color = AddColor(cs, pts[i, j, nfix].point3, vmin, vmax, ax, va, cl); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); if (ds.LineStyle.IsVisible) { g.DrawPolygon(aPen, pta); } } } } aPen.Dispose(); aBrush.Dispose(); }
private void AddMeshZ(Graphics g, DataSeries ds, ChartStyle cs, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; SolidBrush aBrush = new SolidBrush(Color.White); Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); PointF[] pta = new PointF[4]; Point3[,] pts = ds.PointArray; Point3[,] pts1 = new Point3[pts.GetLength(0), pts.GetLength(1)]; Color color; // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); for (int i = 0; i < pts.GetLength(0); i++) { for (int j = 0; j < pts.GetLength(1); j++) { // Make a deep copy the points array: pts1[i, j] = new Point3(pts[i, j].X, pts[i, j].Y, pts[i, j].Z, 1); // Perform transformations on points: pts[i, j].Transform(m, chart3d, ax, cs, cl); } } for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { int ii = i; if (va.Azimuth >= -180 && va.Azimuth < 0) { ii = pts.GetLength(0) - 2 - i; } pta[0] = new PointF(pts[ii, j].X, pts[ii, j].Y); pta[1] = new PointF(pts[ii, j + 1].X, pts[ii, j + 1].Y); pta[2] = new PointF(pts[ii + 1, j + 1].X, pts[ii + 1, j + 1].Y); pta[3] = new PointF(pts[ii + 1, j].X, pts[ii + 1, j].Y); g.FillPolygon(aBrush, pta); if (IsColorMap) { color = AddColor(cs, pts[ii, j], zmin, zmax, ax, va, cl); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawPolygon(aPen, pta); } } Point3[] pt3 = new Point3[4]; for (int i = 0; i < pts1.GetLength(0); i++) { int jj = pts1.GetLength(0) - 1; if (va.Elevation >= 0) { if (va.Azimuth >= -90 && va.Azimuth <= 90) jj = 0; } else if (va.Elevation < 0) { jj = 0; if (va.Azimuth >= -90 && va.Azimuth <= 90) jj = pts1.GetLength(0) - 1; } if (i < pts1.GetLength(0) - 1) { pt3[0] = new Point3(pts1[i, jj].X, pts1[i, jj].Y, pts1[i, jj].Z, 1); pt3[1] = new Point3(pts1[i + 1, jj].X, pts1[i + 1, jj].Y, pts1[i + 1, jj].Z, 1); pt3[2] = new Point3(pts1[i + 1, jj].X, pts1[i + 1, jj].Y, ax.ZMin, 1); pt3[3] = new Point3(pts1[i, jj].X, pts1[i, jj].Y, ax.ZMin, 1); for (int k = 0; k < 4; k++) pt3[k].Transform(m, chart3d, ax, cs, cl); pta[0] = new PointF(pt3[0].X, pt3[0].Y); pta[1] = new PointF(pt3[1].X, pt3[1].Y); pta[2] = new PointF(pt3[2].X, pt3[2].Y); pta[3] = new PointF(pt3[3].X, pt3[3].Y); g.FillPolygon(aBrush, pta); if (IsColorMap) { color = AddColor(cs, pt3[0], zmin, zmax, ax, va, cl); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawPolygon(aPen, pta); } } for (int j = 0; j < pts1.GetLength(1); j++) { int ii = 0; if (va.Elevation >= 0) { if (va.Azimuth >= 0 && va.Azimuth <= 180) ii = pts1.GetLength(1) - 1; } else if (va.Elevation < 0) { if (va.Azimuth >= -180 && va.Azimuth <= 0) ii = pts1.GetLength(1) - 1; } if (j < pts1.GetLength(1) - 1) { pt3[0] = new Point3(pts1[ii, j].X, pts1[ii, j].Y, pts1[ii, j].Z, 1); pt3[1] = new Point3(pts1[ii, j + 1].X, pts1[ii, j + 1].Y, pts1[ii, j + 1].Z, 1); pt3[2] = new Point3(pts1[ii, j + 1].X, pts1[ii, j + 1].Y, ax.ZMin, 1); pt3[3] = new Point3(pts1[ii, j].X, pts1[ii, j].Y, ax.ZMin, 1); for (int k = 0; k < 4; k++) pt3[k].Transform(m, chart3d, ax, cs, cl); pta[0] = new PointF(pt3[0].X, pt3[0].Y); pta[1] = new PointF(pt3[1].X, pt3[1].Y); pta[2] = new PointF(pt3[2].X, pt3[2].Y); pta[3] = new PointF(pt3[3].X, pt3[3].Y); g.FillPolygon(aBrush, pta); if (IsColorMap) { color = AddColor(cs, pt3[0], zmin, zmax, ax, va, cl); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawPolygon(aPen, pta); } } aPen.Dispose(); aBrush.Dispose(); }
private void AddMesh(Graphics g, DataSeries ds, ChartStyle cs, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; SolidBrush aBrush = new SolidBrush(Color.White); Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); PointF[] pta = new PointF[4]; Point3[,] pts = ds.PointArray; // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); // Perform transformations on points: for (int i = 0; i < pts.GetLength(0); i++) { for (int j = 0; j < pts.GetLength(1); j++) { pts[i, j].Transform(m, chart3d, ax, cs, cl); } } // Draw color mesh: for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { int ii = i; if (va.Azimuth >= -180 && va.Azimuth < 0) { ii = pts.GetLength(0) - 2 - i; } pta[0] = new PointF(pts[ii, j].X, pts[ii, j].Y); pta[1] = new PointF(pts[ii, j + 1].X, pts[ii, j + 1].Y); pta[2] = new PointF(pts[ii + 1, j + 1].X, pts[ii + 1, j + 1].Y); pta[3] = new PointF(pts[ii + 1, j].X, pts[ii + 1, j].Y); if (!IsHiddenLine) { g.FillPolygon(aBrush, pta); } if (IsColorMap) { Color color = AddColor(cs, pts[ii, j], zmin, zmax, ax, va, cl); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawPolygon(aPen, pta); } } aPen.Dispose(); aBrush.Dispose(); }
private void AddXYColor(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; SolidBrush aBrush = new SolidBrush(Color.White); PointF[] pta = new PointF[4]; Point3[,] pts = ds.PointArray; Matrix3 m = new Matrix3(); // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); // Draw surface on the XY plane: if (!IsInterp) { for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { pta[0] = cs2d.Point2D(new PointF(pts[i, j].X, pts[i, j].Y), ax); pta[1] = cs2d.Point2D(new PointF(pts[i, j + 1].X, pts[i, j + 1].Y), ax); pta[2] = cs2d.Point2D(new PointF(pts[i + 1, j + 1].X, pts[i + 1, j + 1].Y), ax); pta[3] = cs2d.Point2D(new PointF(pts[i + 1, j].X, pts[i + 1, j].Y), ax); Color color = AddColor(cs, pts[i, j], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); if (ds.LineStyle.IsVisible) { g.DrawPolygon(aPen, pta); } } } } // Draw refined surface: else if (IsInterp) { for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { Point3[] points = new Point3[4]; points[0] = pts[i, j]; points[1] = pts[i, j + 1]; points[2] = pts[i + 1, j + 1]; points[3] = pts[i + 1, j]; Interp(g, cs, cs2d, m, points, zmin, zmax, 2, ax, va, cl); pta[0] = cs2d.Point2D(new PointF(pts[i, j].X, pts[i, j].Y), ax); pta[1] = cs2d.Point2D(new PointF(pts[i, j + 1].X, pts[i, j + 1].Y), ax); pta[2] = cs2d.Point2D(new PointF(pts[i + 1, j + 1].X, pts[i + 1, j + 1].Y), ax); pta[3] = cs2d.Point2D(new PointF(pts[i + 1, j].X, pts[i + 1, j].Y), ax); if (ds.LineStyle.IsVisible) { g.DrawPolygon(aPen, pta); } } } } }
private void AddContour3D(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; Point3[] pta = new Point3[2]; Point3[,] pts = ds.PointArray; Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); float[] zlevels = new float[numberContours]; for (int i = 0; i < numberContours; i++) { zlevels[i] = zmin + i * (zmax - zmin) / (numberContours - 1); } int i0, i1, i2, j0, j1, j2; float zratio = 1; // Draw contour on the XY plane: for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { for (int k = 0; k < numberContours; k++) { if (IsColorMap && ChartType != ChartTypeEnum.FillContour && ChartType != ChartTypeEnum.SurfaceFillContour) { Color color = AddColor(cs, pts[i, j], zmin, zmax, ax, va, cl); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } // Left triangle: i0 = i; j0 = j; i1 = i; j1 = j + 1; i2 = i + 1; j2 = j + 1; if ((zlevels[k] >= pts[i0, j0].Z && zlevels[k] < pts[i1, j1].Z || zlevels[k] < pts[i0, j0].Z && zlevels[k] >= pts[i1, j1].Z) && (zlevels[k] >= pts[i1, j1].Z && zlevels[k] < pts[i2, j2].Z || zlevels[k] < pts[i1, j1].Z && zlevels[k] >= pts[i2, j2].Z)) { zratio = (zlevels[k] - pts[i0, j0].Z) / (pts[i1, j1].Z - pts[i0, j0].Z); pta[0] = new Point3(pts[i0, j0].X, (1 - zratio) * pts[i0, j0].Y + zratio * pts[i1, j1].Y, ax.ZMin, 1); zratio = (zlevels[k] - pts[i1, j1].Z) / (pts[i2, j2].Z - pts[i1, j1].Z); pta[1] = new Point3((1 - zratio) * pts[i1, j1].X + zratio * pts[i2, j2].X, pts[i1, j1].Y, ax.ZMin, 1); pta[0].Transform(m, chart3d, ax, cs, cl); pta[1].Transform(m, chart3d, ax, cs, cl); g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); } else if ((zlevels[k] >= pts[i0, j0].Z && zlevels[k] < pts[i2, j2].Z || zlevels[k] < pts[i0, j0].Z && zlevels[k] >= pts[i2, j2].Z) && (zlevels[k] >= pts[i1, j1].Z && zlevels[k] < pts[i2, j2].Z || zlevels[k] < pts[i1, j1].Z && zlevels[k] >= pts[i2, j2].Z)) { zratio = (zlevels[k] - pts[i0, j0].Z) / (pts[i2, j2].Z - pts[i0, j0].Z); pta[0] = new Point3((1 - zratio) * pts[i0, j0].X + zratio * pts[i2, j2].X, (1 - zratio) * pts[i0, j0].Y + zratio * pts[i2, j2].Y, ax.ZMin, 1); zratio = (zlevels[k] - pts[i1, j1].Z) / (pts[i2, j2].Z - pts[i1, j1].Z); pta[1] = new Point3((1 - zratio) * pts[i1, j1].X + zratio * pts[i2, j2].X, pts[i1, j1].Y, ax.ZMin, 1); pta[0].Transform(m, chart3d, ax, cs, cl); pta[1].Transform(m, chart3d, ax, cs, cl); g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); } else if ((zlevels[k] >= pts[i0, j0].Z && zlevels[k] < pts[i1, j1].Z || zlevels[k] < pts[i0, j0].Z && zlevels[k] >= pts[i1, j1].Z) && (zlevels[k] >= pts[i0, j0].Z && zlevels[k] < pts[i2, j2].Z || zlevels[k] < pts[i0, j0].Z && zlevels[k] >= pts[i2, j2].Z)) { zratio = (zlevels[k] - pts[i0, j0].Z) / (pts[i1, j1].Z - pts[i0, j0].Z); pta[0] = new Point3(pts[i0, j0].X, (1 - zratio) * pts[i0, j0].Y + zratio * pts[i1, j1].Y, ax.ZMin, 1); zratio = (zlevels[k] - pts[i0, j0].Z) / (pts[i2, j2].Z - pts[i0, j0].Z); pta[1] = new Point3(pts[i0, j0].X * (1 - zratio) + pts[i2, j2].X * zratio, pts[i0, j0].Y * (1 - zratio) + pts[i2, j2].Y * zratio, ax.ZMin, 1); pta[0].Transform(m, chart3d, ax, cs, cl); pta[1].Transform(m, chart3d, ax, cs, cl); g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); } // right triangle: i0 = i; j0 = j; i1 = i + 1; j1 = j; i2 = i + 1; j2 = j + 1; if ((zlevels[k] >= pts[i0, j0].Z && zlevels[k] < pts[i1, j1].Z || zlevels[k] < pts[i0, j0].Z && zlevels[k] >= pts[i1, j1].Z) && (zlevels[k] >= pts[i1, j1].Z && zlevels[k] < pts[i2, j2].Z || zlevels[k] < pts[i1, j1].Z && zlevels[k] >= pts[i2, j2].Z)) { zratio = (zlevels[k] - pts[i0, j0].Z) / (pts[i1, j1].Z - pts[i0, j0].Z); pta[0] = new Point3(pts[i0, j0].X * (1 - zratio) + pts[i1, j1].X * zratio, pts[i0, j0].Y, ax.ZMin, 1); zratio = (zlevels[k] - pts[i1, j1].Z) / (pts[i2, j2].Z - pts[i1, j1].Z); pta[1] = new Point3(pts[i1, j1].X, pts[i1, j1].Y * (1 - zratio) + pts[i2, j2].Y * zratio, ax.ZMin, 1); pta[0].Transform(m, chart3d, ax, cs, cl); pta[1].Transform(m, chart3d, ax, cs, cl); g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); } else if ((zlevels[k] >= pts[i0, j0].Z && zlevels[k] < pts[i2, j2].Z || zlevels[k] < pts[i0, j0].Z && zlevels[k] >= pts[i2, j2].Z) && (zlevels[k] >= pts[i1, j1].Z && zlevels[k] < pts[i2, j2].Z || zlevels[k] < pts[i1, j1].Z && zlevels[k] >= pts[i2, j2].Z)) { zratio = (zlevels[k] - pts[i0, j0].Z) / (pts[i2, j2].Z - pts[i0, j0].Z); pta[0] = new Point3(pts[i0, j0].X * (1 - zratio) + pts[i2, j2].X * zratio, pts[i0, j0].Y * (1 - zratio) + pts[i2, j2].Y * zratio, ax.ZMin, 1); zratio = (zlevels[k] - pts[i1, j1].Z) / (pts[i2, j2].Z - pts[i1, j1].Z); pta[1] = new Point3(pts[i1, j1].X, pts[i1, j1].Y * (1 - zratio) + pts[i2, j2].Y * zratio, ax.ZMin, 1); pta[0].Transform(m, chart3d, ax, cs, cl); pta[1].Transform(m, chart3d, ax, cs, cl); g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); } else if ((zlevels[k] >= pts[i0, j0].Z && zlevels[k] < pts[i1, j1].Z || zlevels[k] < pts[i0, j0].Z && zlevels[k] >= pts[i1, j1].Z) && (zlevels[k] >= pts[i0, j0].Z && zlevels[k] < pts[i2, j2].Z || zlevels[k] < pts[i0, j0].Z && zlevels[k] >= pts[i2, j2].Z)) { zratio = (zlevels[k] - pts[i0, j0].Z) / (pts[i1, j1].Z - pts[i0, j0].Z); pta[0] = new Point3(pts[i0, j0].X * (1 - zratio) + pts[i1, j1].X * zratio, pts[i0, j0].Y, ax.ZMin, 1); zratio = (zlevels[k] - pts[i0, j0].Z) / (pts[i2, j2].Z - pts[i0, j0].Z); pta[1] = new Point3(pts[i0, j0].X * (1 - zratio) + pts[i2, j2].X * zratio, pts[i0, j0].Y * (1 - zratio) + pts[i2, j2].Y * zratio, ax.ZMin, 1); pta[0].Transform(m, chart3d, ax, cs, cl); pta[1].Transform(m, chart3d, ax, cs, cl); g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); } } } } aPen.Dispose(); }
private void AddBar3D(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d, Axes ax, ViewAngle va, ChartLabels cl) { Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); PointF[] pt = new PointF[4]; Point3[,] pts = ds.PointArray; // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); // Check parameters: float xlength = ds.BarStyle.XLength; if (xlength <= 0) xlength = 0.1f * ds.XSpacing; else if (xlength > 0.5f) xlength = 0.5f * ds.XSpacing; else xlength = ds.BarStyle.XLength * ds.XSpacing; float ylength = ds.BarStyle.YLength; if (ylength <= 0) ylength = 0.1f * ds.YSpacing; else if (ylength > 0.5f) ylength = 0.5f * ds.YSpacing; else ylength = ds.BarStyle.YLength * ds.YSpacing; float zorigin = ds.BarStyle.ZOrigin; // Draw 3D bars: for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { int ii = i; int jj = j; if (va.Azimuth >= -180 && va.Azimuth < -90) { ii = pts.GetLength(0) - 2 - i; jj = j; } else if (va.Azimuth >= -90 && va.Azimuth < 0) { ii = pts.GetLength(0) - 2 - i; jj = pts.GetLength(1) - 2 - j; } else if (va.Azimuth >= 0 && va.Azimuth < 90) { ii = i; jj = pts.GetLength(1) - 2 - j; } else if (va.Azimuth >= 90 && va.Azimuth <= 180) { ii = i; jj = j; } DrawBar(g, ds, cs, m, pts[ii, jj], xlength, ylength, zorigin, zmax, zmin, ax, va, cl); } } }
public void AddColorBar(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d, Axes ax, ViewAngle va, ChartLabels cl) { if (cs.IsColorBar && IsColorMap) { Pen aPen = new Pen(Color.Black, 1); SolidBrush aBrush = new SolidBrush(cl.TickFontColor); StringFormat sFormat = new StringFormat(); sFormat.Alignment = StringAlignment.Near; SizeF size = g.MeasureString("A", cl.TickFont); int x, y, width, height; Point3[] pts = new Point3[64]; PointF[] pta = new PointF[4]; float zmin, zmax; if (ChartType == ChartTypeEnum.Slice) { zmin = ds.VDataMin(); zmax = ds.VDataMax(); } else { zmin = ds.ZDataMin(); zmax = ds.ZDataMax(); } float dz = (zmax - zmin) / 63; if (ChartType == ChartTypeEnum.Contour || ChartType == ChartTypeEnum.FillContour || ChartType == ChartTypeEnum.XYColor) { x = 5 * cs2d.ChartArea.Width / 6; y = cs2d.PlotArea.Y; width = cs2d.ChartArea.Width / 25; height = cs2d.PlotArea.Height; // Add color bar: for (int i = 0; i < 64; i++) { pts[i] = new Point3(x, y, zmin + i * dz, 1); } for (int i = 0; i < 63; i++) { Color color = AddColor(cs, pts[i], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); float y1 = y + height - (pts[i].Z - zmin) * height / (zmax - zmin); float y2 = y + height - (pts[i + 1].Z - zmin) * height / (zmax - zmin); pta[0] = new PointF(x, y2); pta[1] = new PointF(x + width, y2); pta[2] = new PointF(x + width, y1); pta[3] = new PointF(x, y1); g.FillPolygon(aBrush, pta); } g.DrawRectangle(aPen, x, y, width, height); // Add ticks and labels to the color bar: float ticklength = 0.1f * width; for (float z = zmin; z <= zmax; z = z + (zmax - zmin) / 6) { float yy = y + height - (z - zmin) * height / (zmax - zmin); g.DrawLine(aPen, x, yy, x + ticklength, yy); g.DrawLine(aPen, x + width, yy, x + width - ticklength, yy); g.DrawString((Math.Round(z, 2)).ToString(), cl.TickFont, Brushes.Black, new PointF(x + width + 5, yy - size.Height / 2), sFormat); } } else { x = 5 * cs2d.ChartArea.Width / 6; y = cs2d.ChartArea.Height / 10; width = cs2d.ChartArea.Width / 25; height = 8 * cs2d.ChartArea.Height / 10; // Add color bar: for (int i = 0; i < 64; i++) { pts[i] = new Point3(x, y, zmin + i * dz, 1); } for (int i = 0; i < 63; i++) { Color color = AddColor(cs, pts[i], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); float y1 = y + height - (pts[i].Z - zmin) * height / (zmax - zmin); float y2 = y + height - (pts[i + 1].Z - zmin) * height / (zmax - zmin); pta[0] = new PointF(x, y2); pta[1] = new PointF(x + width, y2); pta[2] = new PointF(x + width, y1); pta[3] = new PointF(x, y1); g.FillPolygon(aBrush, pta); } g.DrawRectangle(aPen, x, y, width, height); // Add ticks and labels to the color bar: float ticklength = 0.1f * width; for (float z = zmin; z <= zmax; z = z + (zmax - zmin) / 6) { float yy = y + height - (z - zmin) * height / (zmax - zmin); g.DrawLine(aPen, x, yy, x + ticklength, yy); g.DrawLine(aPen, x + width, yy, x + width - ticklength, yy); g.DrawString((Math.Round(z, 2)).ToString(), cl.TickFont, Brushes.Black, new PointF(x + width + 5, yy - size.Height / 2), sFormat); } } } }
public void AddChart(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d, Axes ax, ViewAngle va, ChartLabels cl) { switch (ChartType) { case ChartTypeEnum.Line: AddLine(g, ds, cs, ax, va, cl); break; case ChartTypeEnum.Mesh: AddMesh(g, ds, cs, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.MeshZ: AddMeshZ(g, ds, cs, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.Waterfall: AddWaterfall(g, ds, cs, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.Surface: AddSurface(g, ds, cs, cs2d, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.XYColor: AddXYColor(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.Contour: AddContour(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.FillContour: AddXYColor(g, ds, cs, cs2d, ax, va, cl); AddContour(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.MeshContour: AddContour3D(g, ds, cs, cs2d, ax, va, cl); AddMesh(g, ds, cs, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.SurfaceContour: AddContour3D(g, ds, cs, cs2d, ax, va, cl); AddSurface(g, ds, cs, cs2d, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.SurfaceFillContour: AddXYColor3D(g, ds, cs, cs2d, ax, va, cl); AddContour3D(g, ds, cs, cs2d, ax, va, cl); AddSurface(g, ds, cs, cs2d, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.Slice: AddSlice(g, ds, cs, cs2d, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.Bar3D: AddBar3D(g, ds, cs, cs2d, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; } }
private void DrawBar(Graphics g, DataSeries ds, ChartStyle cs, Matrix3 m, Point3 pt, float xlength, float ylength, float zorign, float zmax, float zmin, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; Color color = AddColor(cs, pt, zmin, zmax, ax, va, cl); SolidBrush aBrush = new SolidBrush(color); Point3[] pts = new Point3[8]; Point3[] pts1 = new Point3[8]; Point3[] pt3 = new Point3[4]; PointF[] pta = new PointF[4]; pts[0] = new Point3(pt.X - xlength, pt.Y - ylength, zorign, 1); pts[1] = new Point3(pt.X - xlength, pt.Y + ylength, zorign, 1); pts[2] = new Point3(pt.X + xlength, pt.Y + ylength, zorign, 1); pts[3] = new Point3(pt.X + xlength, pt.Y - ylength, zorign, 1); pts[4] = new Point3(pt.X + xlength, pt.Y - ylength, pt.Z, 1); pts[5] = new Point3(pt.X + xlength, pt.Y + ylength, pt.Z, 1); pts[6] = new Point3(pt.X - xlength, pt.Y + ylength, pt.Z, 1); pts[7] = new Point3(pt.X - xlength, pt.Y - ylength, pt.Z, 1); for (int i = 0; i < pts.Length; i++) { pts1[i] = new Point3(pts[i].X, pts[i].Y, pts[i].Z, 1); pts[i].Transform(m, chart3d, ax, cs, cl); } int[] nconfigs = new int[8]; if (ds.BarStyle.IsBarSingleColor) { pta[0] = new PointF(pts[4].X, pts[4].Y); pta[1] = new PointF(pts[5].X, pts[5].Y); pta[2] = new PointF(pts[6].X, pts[6].Y); pta[3] = new PointF(pts[7].X, pts[7].Y); g.FillPolygon(aBrush, pta); g.DrawPolygon(aPen, pta); pta[0] = new PointF(pts[0].X, pts[0].Y); pta[1] = new PointF(pts[1].X, pts[1].Y); pta[2] = new PointF(pts[2].X, pts[2].Y); pta[3] = new PointF(pts[3].X, pts[3].Y); g.FillPolygon(aBrush, pta); g.DrawPolygon(aPen, pta); if (va.Azimuth >= -180 && va.Azimuth < -90) { nconfigs = new int[8] { 1, 2, 5, 6, 1, 0, 7, 6 }; } else if (va.Azimuth >= -90 && va.Azimuth < 0) { nconfigs = new int[8] { 1, 0, 7, 6, 0, 3, 4, 7 }; } else if (va.Azimuth >= 0 && va.Azimuth < 90) { nconfigs = new int[8] { 0, 3, 4, 7, 2, 3, 4, 5 }; } else if (va.Azimuth >= 90 && va.Azimuth < 180) { nconfigs = new int[8] { 2, 3, 4, 5, 1, 2, 5, 6 }; } pta[0] = new PointF(pts[nconfigs[0]].X, pts[nconfigs[0]].Y); pta[1] = new PointF(pts[nconfigs[1]].X, pts[nconfigs[1]].Y); pta[2] = new PointF(pts[nconfigs[2]].X, pts[nconfigs[2]].Y); pta[3] = new PointF(pts[nconfigs[3]].X, pts[nconfigs[3]].Y); g.FillPolygon(aBrush, pta); g.DrawPolygon(aPen, pta); pta[0] = new PointF(pts[nconfigs[4]].X, pts[nconfigs[4]].Y); pta[1] = new PointF(pts[nconfigs[5]].X, pts[nconfigs[5]].Y); pta[2] = new PointF(pts[nconfigs[6]].X, pts[nconfigs[6]].Y); pta[3] = new PointF(pts[nconfigs[7]].X, pts[nconfigs[7]].Y); g.FillPolygon(aBrush, pta); g.DrawPolygon(aPen, pta); } else if (!ds.BarStyle.IsBarSingleColor && IsColorMap) { pta[0] = new PointF(pts[4].X, pts[4].Y); pta[1] = new PointF(pts[5].X, pts[5].Y); pta[2] = new PointF(pts[6].X, pts[6].Y); pta[3] = new PointF(pts[7].X, pts[7].Y); g.FillPolygon(aBrush, pta); g.DrawPolygon(aPen, pta); pta[0] = new PointF(pts[0].X, pts[0].Y); pta[1] = new PointF(pts[1].X, pts[1].Y); pta[2] = new PointF(pts[2].X, pts[2].Y); pta[3] = new PointF(pts[3].X, pts[3].Y); color = AddColor(cs, pts[0], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); g.DrawPolygon(aPen, pta); float dz = (zmax - zmin) / 63; if (pt.Z < zorign) dz = -dz; int nz = (int)((pt.Z - zorign) / dz) + 1; if (nz < 1) nz = 1; float z = zorign; if (va.Azimuth >= -180 && va.Azimuth < -90) { nconfigs = new int[4] { 1, 2, 1, 0 }; } else if (va.Azimuth >= -90 && va.Azimuth < 0) { nconfigs = new int[4] { 1, 0, 0, 3 }; } else if (va.Azimuth >= 0 && va.Azimuth < 90) { nconfigs = new int[4] { 0, 3, 2, 3 }; } else if (va.Azimuth >= 90 && va.Azimuth <= 180) { nconfigs = new int[4] { 2, 3, 1, 2 }; } for (int i = 0; i < nz; i++) { z = zorign + i * dz; pt3[0] = new Point3(pts1[nconfigs[0]].X, pts1[nconfigs[0]].Y, z, 1); pt3[1] = new Point3(pts1[nconfigs[1]].X, pts1[nconfigs[1]].Y, z, 1); pt3[2] = new Point3(pts1[nconfigs[1]].X, pts1[nconfigs[1]].Y, z + dz, 1); pt3[3] = new Point3(pts1[nconfigs[0]].X, pts1[nconfigs[0]].Y, z + dz, 1); for (int j = 0; j < pt3.Length; j++) { pt3[j].Transform(m, chart3d, ax, cs, cl); } pta[0] = new PointF(pt3[0].X, pt3[0].Y); pta[1] = new PointF(pt3[1].X, pt3[1].Y); pta[2] = new PointF(pt3[2].X, pt3[2].Y); pta[3] = new PointF(pt3[3].X, pt3[3].Y); color = AddColor(cs, pt3[0], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); } pt3[0] = new Point3(pts1[nconfigs[0]].X, pts1[nconfigs[0]].Y, zorign, 1); pt3[1] = new Point3(pts1[nconfigs[1]].X, pts1[nconfigs[1]].Y, zorign, 1); pt3[2] = new Point3(pts1[nconfigs[1]].X, pts1[nconfigs[1]].Y, pt.Z, 1); pt3[3] = new Point3(pts1[nconfigs[0]].X, pts1[nconfigs[0]].Y, pt.Z, 1); for (int j = 0; j < pt3.Length; j++) { pt3[j].Transform(m, chart3d, ax, cs, cl); } pta[0] = new PointF(pt3[0].X, pt3[0].Y); pta[1] = new PointF(pt3[1].X, pt3[1].Y); pta[2] = new PointF(pt3[2].X, pt3[2].Y); pta[3] = new PointF(pt3[3].X, pt3[3].Y); g.DrawPolygon(aPen, pta); for (int i = 0; i < nz; i++) { z = zorign + i * dz; pt3[0] = new Point3(pts1[nconfigs[2]].X, pts1[nconfigs[2]].Y, z, 1); pt3[1] = new Point3(pts1[nconfigs[3]].X, pts1[nconfigs[3]].Y, z, 1); pt3[2] = new Point3(pts1[nconfigs[3]].X, pts1[nconfigs[3]].Y, z + dz, 1); pt3[3] = new Point3(pts1[nconfigs[2]].X, pts1[nconfigs[2]].Y, z + dz, 1); for (int j = 0; j < pt3.Length; j++) { pt3[j].Transform(m, chart3d, ax, cs, cl); } pta[0] = new PointF(pt3[0].X, pt3[0].Y); pta[1] = new PointF(pt3[1].X, pt3[1].Y); pta[2] = new PointF(pt3[2].X, pt3[2].Y); pta[3] = new PointF(pt3[3].X, pt3[3].Y); color = AddColor(cs, pt3[0], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); } pt3[0] = new Point3(pts1[nconfigs[2]].X, pts1[nconfigs[2]].Y, zorign, 1); pt3[1] = new Point3(pts1[nconfigs[3]].X, pts1[nconfigs[3]].Y, zorign, 1); pt3[2] = new Point3(pts1[nconfigs[3]].X, pts1[nconfigs[3]].Y, pt.Z, 1); pt3[3] = new Point3(pts1[nconfigs[2]].X, pts1[nconfigs[2]].Y, pt.Z, 1); for (int j = 0; j < pt3.Length; j++) { pt3[j].Transform(m, chart3d, ax, cs, cl); } pta[0] = new PointF(pt3[0].X, pt3[0].Y); pta[1] = new PointF(pt3[1].X, pt3[1].Y); pta[2] = new PointF(pt3[2].X, pt3[2].Y); pta[3] = new PointF(pt3[3].X, pt3[3].Y); g.DrawPolygon(aPen, pta); } aPen.Dispose(); aBrush.Dispose(); }
private void AddXYColor3D(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; SolidBrush aBrush = new SolidBrush(Color.White); PointF[] pta = new PointF[4]; Point3[,] pts = ds.PointArray; Point3[,] pts1 = new Point3[pts.GetLength(0), pts.GetLength(1)]; Point3[,] pts2 = new Point3[pts.GetLength(0), pts.GetLength(1)]; Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); // Perform transformation on points: for (int i = 0; i < pts.GetLength(0); i++) { for (int j = 0; j < pts.GetLength(1); j++) { // Make a deep copy the points array: pts1[i, j] = new Point3(pts[i, j].X, pts[i, j].Y, ax.ZMin, 1); pts2[i, j] = new Point3(pts[i, j].X, pts[i, j].Y, ax.ZMin, 1); pts1[i, j].Transform(m, chart3d, ax, cs, cl); } } // Draw surface on the XY plane: if (!IsInterp) { for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { pta[0] = new PointF(pts1[i, j].X, pts1[i, j].Y); pta[1] = new PointF(pts1[i, j + 1].X, pts1[i, j + 1].Y); pta[2] = new PointF(pts1[i + 1, j + 1].X, pts1[i + 1, j + 1].Y); pta[3] = new PointF(pts1[i + 1, j].X, pts1[i + 1, j].Y); Color color = AddColor(cs, pts[i, j], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); if (ds.LineStyle.IsVisible) { //g.DrawPolygon(aPen, pta); } } } } // Draw refined surface: else if (IsInterp) { for (int i = 0; i < pts1.GetLength(0) - 1; i++) { for (int j = 0; j < pts1.GetLength(1) - 1; j++) { Point3[] points = new Point3[4]; points[0] = pts[i, j]; points[1] = pts[i, j + 1]; points[2] = pts[i + 1, j + 1]; points[3] = pts[i + 1, j]; Interp(g, cs, cs2d, m, points, zmin, zmax, 3, ax, va, cl); } } } }
private void AddLine(Graphics g, DataSeries ds, ChartStyle cs, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); Point3[] pts = new Point3[ds.PointList.Count]; // Find zmin and zmax values, then perform transformation on points: float zmin = 0; float zmax = 0; for (int i = 0; i < pts.Length; i++) { pts[i] = (Point3)ds.PointList[i]; zmin = Math.Min(zmin, pts[i].Z); zmax = Math.Max(zmax, pts[i].Z); pts[i].Transform(m, chart3d, ax, cs, cl); } // Draw line: if (ds.LineStyle.IsVisible == true) { for (int i = 1; i < pts.Length; i++) { if (IsColorMap) { Color color = AddColor(cs, pts[i], zmin, zmax, ax, va, cl); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawLine(aPen, pts[i - 1].X, pts[i - 1].Y, pts[i].X, pts[i].Y); } } aPen.Dispose(); }
public void Peak3D(DataSeries ds, Axes ax) { ax.XMin = -3; ax.XMax = 3; ax.YMin = -3; ax.YMax = 3; ax.ZMin = -8; ax.ZMax = 8; ax.XTick = 1; ax.YTick = 1; ax.ZTick = 4; ds.XDataMin = ax.XMin; ds.YDataMin = ax.YMin; ds.XSpacing = 0.3f; ds.YSpacing = 0.3f; ds.XNumber = Convert.ToInt16((ax.XMax - ax.XMin) / ds.XSpacing) + 1; ds.YNumber = Convert.ToInt16((ax.YMax - ax.YMin) / ds.YSpacing) + 1; Point3[,] pts = new Point3[ds.XNumber, ds.YNumber]; for (int i = 0; i < ds.XNumber; i++) { for (int j = 0; j < ds.YNumber; j++) { float x = ds.XDataMin + i * ds.XSpacing; float y = ds.YDataMin + j * ds.YSpacing; double zz = 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); float z = (float)zz; pts[i, j] = new Point3(x, y, z, 1); } } ds.PointArray = pts; }
private void AddWaterfall(Graphics g, DataSeries ds, ChartStyle cs, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; SolidBrush aBrush = new SolidBrush(Color.White); Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); Point3[,] pts = ds.PointArray; Point3[] pt3 = new Point3[pts.GetLength(0) + 2]; PointF[] pta = new PointF[pts.GetLength(0) + 2]; Color color; // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); for (int j = 0; j < pts.GetLength(1); j++) { int jj = j; if (va.Elevation >= 0) { if (va.Azimuth >= -90 && va.Azimuth < 90) { jj = pts.GetLength(1) - 1 - j; } } else if (va.Elevation < 0) { jj = pts.GetLength(1) - 1 - j; if (va.Azimuth >= -90 && va.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 Point3(pt3[i + 1].X, pt3[i + 1].Y, ax.ZMin, 1); } if (i == pts.GetLength(0) - 1) { pt3[pts.GetLength(0) + 1] = new Point3(pt3[i + 1].X, pt3[i + 1].Y, ax.ZMin, 1); } } for (int i = 0; i < pt3.Length; i++) { pt3[i].Transform(m, chart3d, ax, cs, cl); pta[i] = new PointF(pt3[i].X, pt3[i].Y); } g.FillPolygon(aBrush, pta); for (int i = 1; i < pt3.Length; i++) { if (IsColorMap) { color = AddColor(cs, pt3[i], zmin, zmax, ax, va, cl); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawLine(aPen, pta[i - 1], pta[i]); } } aPen.Dispose(); aBrush.Dispose(); }