public Space3D Copy() { Space3D f = new Space3D(); for (int i = 0; i < this.Count; i++) { f.Add(this[i].Copy()); } return(f); }
public Canvas Draw(int width, int height, float angleX, float angleY, float angleZ, Point3D camera) { if (this.faces.Count == 0) { return(null); } Space3D faces = this.Copy(); Canvas c = new Canvas(); c.Open(width, height); c.DrawBar(Brushes.White, 0, 0, c.Width, c.Height); faces.Project((int)(angleX * 10f), (int)(angleY * 10f), (int)(angleZ * 10f), camera); faces.SortDepth(); Limits2D lim = faces.Limits; double d = (double)(c.Width - 10) / (double)(lim.MaxX - lim.MinX); double scale = (double)(c.Height - 10) / (double)(lim.MaxY - lim.MinY); if (scale > d) { scale = d; } List <TopMarks> top = new List <TopMarks>(); for (int i = 0; i < faces.Count; i++) { Face3D f = faces[i]; Color clr = Color.Black; if ((f.Tag & 0xff000000) == 0x7f000000) { clr = Color.FromArgb((int)(f.Tag >> 16) & 0xff, (int)(f.Tag >> 8) & 0xff, (int)f.Tag & 0xff); } else { clr = this.GetColor(f.Tag); } int x; int y; if (f.Count > 1) { if (f.Shadow != 0) { clr = ColorUtils.DarkColor(clr, f.Shadow); } x = (int)((double)(f.Points[0].X - lim.MinX) * scale); y = (int)((double)(f.Points[0].Y - lim.MinY) * scale); Point[] plst = null; if (f.Count > 2) { plst = new Point[f.Count]; plst[0] = new Point(x, y); } for (int j = 1; j < f.Count; j++) { int x0 = (int)((double)(f.Points[j].X - lim.MinX) * scale); int y0 = (int)((double)(f.Points[j].Y - lim.MinY) * scale); if (f.Count == 2) { c.DrawLine(new Pen(clr), x, y, x0, y0); break; } else { plst[j] = new Point(x0, y0); } } if (plst != null) { c.FillPolygon(new SolidBrush(clr), plst); } } else { x = (int)((double)(f.Points[0].X - lim.MinX) * scale); y = (int)((double)(f.Points[0].Y - lim.MinY) * scale); Pen pen = null; if (((clr.R + clr.G + clr.B) / 3) > 0x7f) { pen = Pens.Black; } else { pen = Pens.White; } switch (f.Shadow) { case -1: c.TriangleMark(new SolidBrush(clr), pen, x, y, Space3D.ColorSignSize); break; case -2: c.RectangleMark(new SolidBrush(clr), pen, x, y, Space3D.ColorSignSize); break; case -3: c.PointMark(new SolidBrush(clr), x, y); break; case -101: top.Add(new TopMarks(clr, x, y, -1)); break; case -102: top.Add(new TopMarks(clr, x, y, -2)); break; case -103: top.Add(new TopMarks(clr, x, y, -3)); break; default: c.CircleMark(new SolidBrush(clr), pen, x, y, Space3D.ColorSignSize >> 1); break; } } } for (int i = 0; i < top.Count; i++) { TopMarks t = top[i]; Color clr = t.Color; Pen pen = null; if (((clr.R + clr.G + clr.B) / 3) > 0x7f) { pen = Pens.Black; } else { pen = Pens.White; } int x = t.X; int y = t.Y; switch (t.Shadow) { case -1: c.TriangleMark(new SolidBrush(clr), pen, x, y, Space3D.ColorSignSize); break; case -2: c.RectangleMark(new SolidBrush(clr), pen, x, y, Space3D.ColorSignSize); break; case -3: c.PointMark(new SolidBrush(clr), x, y); break; } } return(c); }
/// <summary> /// All measurement in mm and in 1/10 degree. Degrees are in range 0 .. 3600. /// </summary> /// <returns></returns> public int Sector(int tag, double centerX, double centerY, double innerR, double outerR, int startAngle, int endAngle, int stepAngle, double gap, double depth) { if ((startAngle < 0) || (startAngle > 3600)) { return(-1); } if ((endAngle < 0) || (endAngle > 3600)) { return(-1); } if (innerR >= outerR) { return(-1); } int count = 0; double x0; double y0; double x1; double y1; int angle = startAngle; Space3D.GetSectorPoint(centerX, centerY, innerR, angle, gap, out x0, out y0); Space3D.GetSectorPoint(centerX, centerY, outerR, angle, gap, out x1, out y1); Face3D f; if (depth > 0) { f = new Rectangle3D( new Point3D(x0, y0, 0f), new Point3D(x1, y1, 0f), new Point3D(x1, y1, depth), new Point3D(x0, y0, depth)); f.Tag = tag; f.Shadow = 20; this.Add(f); ++count; } while (true) { if (angle >= endAngle) { break; } angle += stepAngle; if (angle > endAngle) { angle = endAngle; } double x2; double y2; double x3; double y3; double g = 0; if (angle >= endAngle) { g = -gap; } Space3D.GetSectorPoint(centerX, centerY, innerR, angle, g, out x2, out y2); Space3D.GetSectorPoint(centerX, centerY, outerR, angle, g, out x3, out y3); f = new Rectangle3D( new Point3D(x0, y0, 0f), new Point3D(x1, y1, 0f), new Point3D(x3, y3, 0f), new Point3D(x2, y2, 0f)); f.Tag = tag; this.Add(f); ++count; if (depth > 0) { f = new Rectangle3D( new Point3D(x0, y0, 0f), new Point3D(x2, y2, 0f), new Point3D(x2, y2, depth), new Point3D(x0, y0, depth)); f.Tag = tag; f.Shadow = this.GetShadow(angle, 30); this.Add(f); ++count; f = new Rectangle3D( new Point3D(x1, y1, 0f), new Point3D(x3, y3, 0f), new Point3D(x3, y3, depth), new Point3D(x1, y1, depth)); f.Tag = tag; f.Shadow = this.GetShadow(angle, 30); this.Add(f); ++count; } if (angle < endAngle) { Space3D.GetSectorPoint(centerX, centerY, innerR, angle - 10, 0f, out x0, out y0); Space3D.GetSectorPoint(centerX, centerY, outerR, angle - 10, 0f, out x1, out y1); } else { x0 = x2; y0 = y2; x1 = x3; y1 = y3; } } if (depth > 0) { f = new Rectangle3D( new Point3D(x0, y0, 0f), new Point3D(x1, y1, 0f), new Point3D(x1, y1, depth), new Point3D(x0, y0, depth)); f.Tag = tag; f.Shadow = 20; this.Add(f); ++count; } return(count); }