public static Plot3D operator +(PPoint3D a, PPoint3D b) { Plot3D plot3D = new Plot3D(); PPoint3D p1 = a; plot3D.AddPoint(p1); PPoint3D p2 = b; plot3D.AddPoint(p2); return(plot3D); }
public static Plot3D operator *(Plot3D a, ITransformation3D b) { var l = a._points.ConvertAll(el => new PPoint3D(el.X, el.Y, el.Z, el.Color, el.Visible)); Parallel.For(0, a._points.Count, i => { PPoint3D point = a._points[i]; b.Transform(ref point, l); a._points[i] = point; }); return(a); }
private float ColorLight(PPoint3D pPoint3D, DistComparer comparer, PPoint3D light) { PPoint3D ppoint3D1 = new PPoint3D(pPoint3D.X - comparer.CamX, pPoint3D.Y - comparer.CamY, pPoint3D.Z - comparer.CamZ); PPoint3D ppoint3D2 = new PPoint3D(pPoint3D.X - light.X, pPoint3D.Y - light.Y, pPoint3D.Z - light.Z); return ((float) (((ppoint3D1.X * (double)ppoint3D2.X + ppoint3D1.Y * (double)ppoint3D2.Y + ppoint3D1.Z * (double)ppoint3D2.Z) / Math.Sqrt(ppoint3D1.SquareLen() * (double)ppoint3D2.SquareLen()) + 1.0) / 2.0)); }
public void AddPoint(PPoint3D p) { if (p.Z > (double)MaxZ) { MaxZ = p.Z; } if (p.Z < (double)MinZ) { MinZ = p.Z; } _points.Add(p); }
public static Plot3D operator /(Plot3D a, ITransformation3D b) { var l = a._points.ConvertAll(el => new PPoint3D(el.X, el.Y, el.Z, el.Color, el.Visible)); Parallel.For(0, a._points.Count, i => { PPoint3D point = a._points[i]; INvertibleTransformation3D transformation3D = b as INvertibleTransformation3D; if (transformation3D == null) { throw new InvalidCastException("Transformation not invertible!"); } transformation3D.Invert(ref point, l); a._points[i] = point; }); return(a); }
public static Plot3D Line3D(float dx, PPoint3D a, PPoint3D b, Color color) { Plot3D plot3D = new Plot3D(); var num1 = a.X - b.X; var num2 = a.Y - b.Y; var num3 = a.Z - b.Z; var num4 = (float)Math.Sqrt(num1 * (double)num1 + num2 * (double)num2 + num3 * (double)num3); var num5 = num1 / num4; var num6 = num2 / num4; var num7 = num3 / num4; var num8 = 0.0f; while (num8 <= (double)num4) { plot3D.AddPoint(new PPoint3D(num8 * num5 + b.X, num8 * num6 + b.Y, num8 * num7 + b.Z, color)); num8 += dx; } return(plot3D); }
public Bitmap ToBitMap(int w, int h, Rectangle3D view, PPoint3D light) { var num1 = view.X; var num2 = view.X + view.Width; var num3 = view.Y; var num4 = view.Y + view.Height; DistComparer comparer = new DistComparer { CamX = (float)(num1 - 0.0500000007450581 * (num2 - (double)num1)), CamY = (float)(num3 - 0.0500000007450581 * (num4 - (double)num3)), CamZ = (float)(MaxZ * 1.04999995231628) }; _points.Sort(comparer); var ppoint2DList = new List <PPoint2D>(); foreach (PPoint3D point in _points) { PPoint2D ppoint2D1 = new PPoint2D((float)(0.5 * (point.X - (double)point.Y)), 0.5f * point.Y + point.Z, point.Color); var num5 = point.Visible ? 1 : 0; ppoint2D1.Visible = num5 != 0; PPoint2D ppoint2D2 = ppoint2D1; ppoint2DList.Add(ppoint2D2); } Bitmap bitmap = new Bitmap(w, h, PixelFormat.Format24bppRgb); Graphics graphics = Graphics.FromImage(bitmap); if (Math.Abs(num2 - num1) + (double)Math.Abs(num4 - num3) < 5.60519385729927E-44) { graphics.Clear(Color.Black); } else { graphics.Clear(Color.White); var num5 = (float)(w * 0.899999976158142 / (num2 - (double)num1)); var num6 = (float)(h * 0.899999976158142 / (num4 - (double)num3)); var num7 = MaxZ - MinZ; var num8 = Size * 0.5f; var num9 = w * 0.025f; var num10 = h * 0.025f; var num11 = 1f / num9; var num12 = 1f / num10; var num13 = (float)((num12 + (double)num11) * 0.100000001490116); var num14 = num9 - num8; var num15 = num10 - num8; for (var index = 0; index < ppoint2DList.Count; ++index) { PPoint2D ppoint2D = ppoint2DList[index]; if (ppoint2D.Visible) { var d = ColorLight(_points[index], comparer, light); var x = (ppoint2D.X - num1) * num5 + num14; var y = (num4 - ppoint2D.Y) * num6 + num15; if (Math.Abs(LinesH) > 4.20389539297445E-45 && Extensions.Mod(_points[index].X, LinesH) < num11 || Math.Abs(LinesV) > 4.20389539297445E-45 && Extensions.Mod(_points[index].Y, LinesV) < num12 || Math.Abs(LinesL) > 4.20389539297445E-45 && Extensions.Mod(_points[index].Z, LinesL) < num13) { graphics.FillEllipse(Brushes.Black, x, y, Size, Size); } else if (ppoint2D.Color == Color.Empty) { graphics.FillEllipse( new SolidBrush( ColorMultiply( Extensions.HsvToRgb(360.0 * (_points[index].Z - (double)MinZ) / num7, 1.0, 1.0), d)), x, y, Size, Size); } else { graphics.FillEllipse(new SolidBrush(ColorMultiply(ppoint2D.Color, d)), x, y, Size, Size); } } } } return(bitmap); }