/// <summary> /// コンストラクター /// </summary> /// <param name="a">A</param> /// <param name="b">B</param> public DoubleLine(DoublePoint2D a, DoublePoint2D b) { Initialize(); A.X = a.X; A.Y = a.Y; B.X = b.X; B.Y = b.Y; }
private DoublePoint3D CanvasToViewport(DoublePoint2D canvasPoint, double distance) { var viewPortSize = new DoublePoint2D(distance, distance); canvasPoint.X -= Source.Width / 2; canvasPoint.Y -= Source.Height / 2; canvasPoint.Y = -canvasPoint.Y; return(new DoublePoint3D(canvasPoint.X * viewPortSize.X / Source.Width, canvasPoint.Y * viewPortSize.Y / Source.Height, distance)); //What'a hell? }
/// <summary> /// Initializes a new instance of the CoordinateCircle class. /// </summary> /// <param name="circle">The circle.</param> public CoordinateCircle(CoordinateCircleF circle) { if (circle == null) { circle = new(); } center = circle.Center; radius = circle.Radius; }
/// <summary> /// Initializes a new instance of the LineSegment class. /// </summary> /// <param name="line">The line segment.</param> public LineSegment(LineSegmentF line) { if (line == null) { line = new(); } start = line.Start; end = line.End; }
private DoublePoint2D To2D(DoublePoint3D point) { var result = new DoublePoint2D(); var xAngle = Math.PI / 6; var zAngle = Math.PI / 6; result.X = Math.Cos(xAngle) * point.X - Math.Cos(zAngle) * point.Z; result.Y = point.Y - Math.Sin(xAngle) * point.X - Math.Sin(zAngle) * point.Z; return(result); }
private DoublePoint2D DeBoor(double t, Point2D[] splainControlPoints, double[] knots, int splainDegree) { DoublePoint2D V = new DoublePoint2D(); for (int i = 0; i < splainControlPoints.Length; i++) { double scale = basisFunc(knots, i, splainDegree, t); V.X += splainControlPoints[i].X * scale; V.Y += splainControlPoints[i].Y * scale; } return(V); }
public Hexahedron(DoublePoint3D[] points, DoublePoint2D rotation, ColorRGB color, int specular, float transparency, float reflective) : base(color, specular, transparency, reflective) { if (Points.Length != 8) { throw new ArgumentException( $"{nameof(points)} has wrong number of points! Expected 8 point, actually {points.Length}"); } points.CopyTo(Points, 0); Rotation = rotation; }
/// <summary> /// Возвращает точку пересечения двух отрезков /// </summary> /// <param name="a">Начало отрезка окна</param> /// <param name="b">Конец отрезка окна</param> /// <param name="c">Начало отрезка фигуры</param> /// <param name="d">Конец отрезка фигуры</param> /// <returns></returns> private PointInfo CrossingPoint(DoublePoint2D a, DoublePoint2D b, DoublePoint2D c, DoublePoint2D d) { DoublePoint2D crossing = new DoublePoint2D(); var z1 = VectorMult(d - c, a - c); var z2 = VectorMult(d - c, b - c); sbyte relation; crossing.X = a.X + (b - a).X * Math.Abs(z1) / Math.Abs(z2 - z1); crossing.Y = a.Y + (b - a).Y * Math.Abs(z1) / Math.Abs(z2 - z1); //Определяем, входящая или выходящая точка relation = (VectorMult(b - a, a - c) > 0) ? (sbyte)1 : (sbyte)-1; return(new PointInfo(crossing, relation)); }
private void RenderScene(DoublePoint3D position, DoublePoint2D rotation) { const double distance = 1; const byte recursionDepth = 3; var interval = new double[] { 0.0001, Inf }; var cameraPosition = position; //new DoublePoint3D(0, 0, 0);// (0, 5, 2); var cameraAngle = rotation; //new DoublePoint2D(0, 0);// (Math.PI / 2, Math.PI); for (var x = 0; x < Source.Width; x++) { for (var y = 0; y < Source.Height; y++) { DoublePoint3D viewPortPoint = CanvasToViewport(new DoublePoint2D(x, y), distance).RotateX(cameraAngle.X).RotateY(cameraAngle.Y); ColorRGB color = TraceRay(cameraPosition, viewPortPoint, interval, recursionDepth); Source.SetPixel(x, y, Color.FromArgb(color.R, color.G, color.B)); } } }
/// <summary> /// Возвращает значение, определяющее пересекаются ли 2 отрезка /// </summary> /// <param name="a">Начало 1 отрезка</param> /// <param name="b">Конец 1 отрезка</param> /// <param name="c">Начало 2 отрезка</param> /// <param name="d">Конец 2 отрезка</param> /// <returns>Пересекаются ли 2 отрезка?</returns> private bool IsCrossing(DoublePoint2D a, DoublePoint2D b, DoublePoint2D c, DoublePoint2D d) { var z1 = VectorMult(b - a, c - a); var z2 = VectorMult(b - a, d - a); if ((z1 == 0) || (z2 == 0) || (Math.Sign(z1) == Math.Sign(z2))) { return(false); } z1 = VectorMult(d - c, a - c); z2 = VectorMult(d - c, b - c); if ((z1 == 0) || (z2 == 0) || (Math.Sign(z1) == Math.Sign(z2))) { return(false); } return(true); }
private void DetailedRecreatedBSplainOnSecretDocuments(Point2D[] splainControlPoints, int splainPow) { //Заполняем массив угловых точек (равномерно от 0 до 1) float[] U = new float[splainControlPoints.Length + splainPow + 2]; /*for (int i = 0; i < U.Length - 1; i++) * U[i] = (float)i / (float)(U.Length - 1); * U[U.Length - 1] = 1; //Чтоб последний элемент всегда = 1*/ for (int i = 0; i < splainPow; i++) { U[i] = 0; U[U.Length - 1 - i] = 1; } for (int i = 0; i < (U.Length - 2 * splainPow); i++) { U[i + splainPow] = (float)(i + 1) / (float)(U.Length - 2 * splainPow + 1); } //Высчитываем коэффициенты при контрольных точках //double[] N = new double[splainControlPoints.Length * splainPow + splainPow]; //for (int i = 0; i < N.Length; i++) //Будет рекурсия, чтоб не высчитывать повторно запиливаем нерасчитанные в минус (формулы без рекурсии мне влом выводить (это ОЧЕНЬ времязатратно)) // N[i] = -1; float d = 1000f; DoublePoint2D[] C = new DoublePoint2D[(int)d]; for (int i = 0; i < C.Length; i++) { C[i] = splainControlPoints[0] * N(0, splainPow, i / d, U) + splainControlPoints[1] * N(1, splainPow, i / d, U) + splainControlPoints[1] * N(2, splainPow, i / d, U) + splainControlPoints[1] * N(3, splainPow, i / d, U) + splainControlPoints[1] * N(4, splainPow, i / d, U) + splainControlPoints[1] * N(5, splainPow, i / d, U) + splainControlPoints[1] * N(6, splainPow, i / d, U) + splainControlPoints[1] * N(7, splainPow, i / d, U); } PointF[] points = new PointF[C.Length]; for (int i = 0; i < points.Length; i++) { points[i] = C[i].ToPointF(); } Drawer.DrawCurve(Source, points); }
private void DrawLab(DoublePoint3D[] areaPoints, double xRotateDegree, double yRotateDegree) { Drawer.DrawLine(Source, new DoublePoint2D(0, 300), new DoublePoint2D(0, 0), Color.Gray); Drawer.DrawLine(Source, new DoublePoint2D(0, 0), new DoublePoint2D(Math.Cos(Math.PI / 6) * 300, -Math.Sin(Math.PI / 6) * 300), Color.Gray); Drawer.DrawLine(Source, new DoublePoint2D(0, 0), new DoublePoint2D(-Math.Cos(Math.PI / 6) * 300, -Math.Sin(Math.PI / 6) * 300), Color.Gray); var realPoints = new DoublePoint2D[areaPoints.Length]; xRotateDegree = xRotateDegree / 360 * 2 * Math.PI; yRotateDegree = yRotateDegree / 360 * 2 * Math.PI; for (var i = 0; i < areaPoints.Length; i++) { realPoints[i] = To2D(areaPoints[i].RotateX(xRotateDegree).RotateY(yRotateDegree)); } for (var i = 0; i < areaPoints.Length; i++) { Drawer.DrawLine(Source, realPoints[i], realPoints[(i + 1) % areaPoints.Length], Color.Black); } }
public void calculatePath(Point2D[] splainControlPoints, int splainDegree) { double[] knots = new double[splainDegree + splainControlPoints.Length + 1]; double d = 1.0 / (1 + knots.Length - 2 * splainDegree); /*int i; * for (i = splainDegree; i < knots.Length - splainDegree; i++) * knots[i] = (i + 1 - splainDegree) * d; * for (; i < knots.Length; i++) * knots[i] = 1;*/ for (int i = 0; i < splainDegree; i++) { knots[i] = 0; knots[knots.Length - i - 1] = 1; } knots[knots.Length - splainDegree - 1] = 1; for (int i = 1; i < (knots.Length - 2 * splainDegree - 1); i++) { knots[i + splainDegree] = (i + 1) / (knots.Length - 2 * splainDegree + 1.0); } DoublePoint2D v = new DoublePoint2D(); double delta = 1 / 100.0; for (double t = 0; t < 1; t += delta) { DoublePoint2D p = DeBoor(t, splainControlPoints, knots, splainDegree); if ((v.X != 0) && (v.Y != 0) && (p.X != 0) && (p.Y != 0)) { Drawer.DrawLine(Source, new Vector2D((int)v.X, (int)v.Y, (int)p.X, (int)p.Y)); } v = p; } }
public PointInfo(DoublePoint2D point) { Point = point; Relation = 0; }
/// <summary> /// Initializes a new instance of the LineSegment class. /// </summary> /// <param name="start">The start point.</param> /// <param name="end">The end point.</param> public LineSegment(DoublePoint2D start, DoublePoint2D end) { this.start = start ?? new(); this.end = end ?? new(); }
/// <summary> /// Initializes a new instance of the LineSegment class. /// </summary> /// <param name="x1">X of the start point.</param> /// <param name="y1">Y of the start point.</param> /// <param name="x2">X of the end point.</param> /// <param name="y2">Y of the end point.</param> public LineSegment(double x1, double y1, double x2, double y2) { start = new(x1, y1); end = new(x2, y2); }
/// <summary> /// Initializes a new instance of the LineSegment class. /// </summary> public LineSegment() { start = new(); end = new(); }
/// <summary> /// 初期化 /// </summary> private void Initialize() { A = new DoublePoint2D(); B = new DoublePoint2D(); }
/// <summary> /// Initializes a new instance of the CoordinateCircle class. /// </summary> /// <param name="center">The center point.</param> /// <param name="r">The radius.</param> public CoordinateCircle(DoublePoint2D center, double r) { this.center = center ?? new(); radius = double.IsNaN(r) ? 0 : Math.Abs(r); }
/// <summary> /// Initializes a new instance of the CoordinateCircle class. /// </summary> /// <param name="x">The x of center point.</param> /// <param name="y">The y of center point.</param> /// <param name="r">The radius.</param> public CoordinateCircle(double x, double y, double r) { center = new(x, y); radius = double.IsNaN(r) ? 0 : Math.Abs(r); }
/// <summary> /// Initializes a new instance of the CoordinateCircle class. /// </summary> public CoordinateCircle() { center = new(); radius = 0; }
public DoublePoint3D(DoublePoint2D xy, double z) { X = xy.X; Y = xy.Y; Z = z; }
public PointInfo(DoublePoint2D point, sbyte relation) { Point = point; Relation = relation; }
/// <summary> /// Возвращает векторное произведение /// </summary> /// <param name="a">1-ый вектор</param> /// <param name="b">2-ой вектор</param> /// <returns>Векторное произведение</returns> private int VectorMult(DoublePoint2D a, DoublePoint2D b) { return((int)(a.X * b.Y - a.Y * b.X)); }