Exemple #1
0
        private void FillPoint(CPoint p1, Color clr)
        {
            var np    = NPt(p1);
            var gr    = Graphics.FromImage(pictureBox.Image);
            var bgClr = RG.GetColorReversed(new CPoint(p1), CProjection.UpC1C2);
            var blend = RG.Blend(clr, bgClr);

            gr.TryDraw(g => g.FillEllipse(new SolidBrush(clr), np.X - 2, np.Y - 2, 4, 4));
            gr.TryDraw(g => g.DrawRectangle(new Pen(blend), np.X - 10, np.Y - 10, 20, 20));
        }
Exemple #2
0
        private void Redraw()
        {
            var bmp    = Recreate();
            var fr     = _stack.Peek();
            var r      = fr.Rectangle;
            var w      = pictureBox.Width;
            var h      = pictureBox.Height;
            var onepxw = r.Width / w;
            var onepxh = r.Height / h;

            for (var x = r.X; x <= r.X + r.Width; x += onepxw)
            {
                for (var y = r.Y; y <= r.Y + r.Height; y += onepxh)
                {
                    FillPixel(bmp, x, y);
                }
            }

            var gr = Graphics.FromImage(pictureBox.Image);

            DrawPoint(new CPoint(1, 0, 0), Config.White);
            DrawPoint(new CPoint(0, 0, 1), Config.Black);

            var sqrtN            = Math.Sqrt(RgSettings.N);
            var nAlphaMinus1     = Math.Pow(RgSettings.N, RgSettings.Alpha - 1);
            var nAlphaMinus3Div2 = Math.Pow(RgSettings.N, RgSettings.Alpha - 1.5);
            var nAlphaMinus1Div2 = Math.Pow(RgSettings.N, RgSettings.Alpha - 0.5);

            var rPlus  = (sqrtN - nAlphaMinus1) / (1 - sqrtN);
            var rMinus = (-sqrtN - nAlphaMinus1) / (1 + sqrtN);
            var gPlus  = RgSettings.N * ((1 - nAlphaMinus3Div2) / (1 - nAlphaMinus1Div2));
            var gMinus = RgSettings.N * ((1 + nAlphaMinus3Div2) / (1 + nAlphaMinus1Div2));

            var rgPlus  = new RGPoint(rPlus, gPlus);
            var rgMinus = new RGPoint(rMinus, gMinus);

            var cPlus  = rgPlus.CDirect;
            var cMinus = rgMinus.CDirect;

            DrawCross(cPlus, Config.White);
            DrawCross(cMinus, Config.Black);

            var sing = new CPoint(1, RgSettings.Lambda, RgSettings.Lambda2);

            DrawXCross(sing, Config.White);

            gr.Save();

            fr.Bitmap = new Bitmap(bmp);
            DrawPoint();
        }
Exemple #3
0
        private void DrawCross(CPoint p1, Color clr)
        {
            var np = NPt(p1);
            var gr = Graphics.FromImage(pictureBox.Image);
            var p  = new Pen(clr);

            gr.TryDraw(g => g.DrawEllipse(p, np.X - 6, np.Y - 6, 12, 12));
            var pt1 = new Point(np.X - 6, np.Y);
            var pt2 = new Point(np.X + 6, np.Y);
            var pt3 = new Point(np.X, np.Y - 6);
            var pt4 = new Point(np.X, np.Y + 6);

            gr.TryDraw(g => g.DrawLine(p, pt1, pt2));
            gr.TryDraw(g => g.DrawLine(p, pt3, pt4));
        }
        public CPoint ReverseIterated(CProjection projection)
        {
            var c0C2MinusC1           = C0 * C2 - C1 * C1;
            var c0MinusLambdaMinus1C1 = C0 - RgSettings.LambdaMinus1 * C1;
            var c1MinusLambdaMinus1C2 = C1 - RgSettings.LambdaMinus1 * C2;

            var c0 = c0MinusLambdaMinus1C1 * c0MinusLambdaMinus1C1 + RgSettings.NLambdaMinus2 * c0C2MinusC1;
            var c1 = RgSettings.LambdaMinus1 * c0MinusLambdaMinus1C1 * c1MinusLambdaMinus1C2 + RgSettings.NLambdaMinus2 * c0C2MinusC1;
            var c2 = RgSettings.LambdaMinus2 * c1MinusLambdaMinus1C2 * c1MinusLambdaMinus1C2 + RgSettings.NLambdaMinus2 * c0C2MinusC1;

            var res = new CPoint(c0, c1, c2);

            res.Project(projection);
            return(res);
        }
        public CPoint DirectIterated(CProjection projection)
        {
            var c1MinusC0     = C1 - C0;
            var c2MunusC1     = C2 - C1;
            var c0C2MinusC1Sq = C0 * C2 - C1 * C1;
            var n1            = RgSettings.OneDivN;

            var c0 = c1MinusC0 * c1MinusC0 + n1 * c0C2MinusC1Sq;
            var c1 = RgSettings.Lambda * (c1MinusC0 * c2MunusC1 + n1 * c0C2MinusC1Sq);
            var c2 = RgSettings.Lambda2 * (c2MunusC1 * c2MunusC1 + n1 * c0C2MinusC1Sq);

            var res = new CPoint(c0, c1, c2);

            res.Project(projection);
            return(res);
        }
        public CPoint ReverseTrackEndPoint(CPoint crit, CProjection projection, out int cnt)
        {
            var          pt  = this;
            const double max = double.MaxValue;
            var          d   = max;
            var          i   = 0;

            while (d > Config.Acc && i < Config.Count)
            {
                pt.IterateReverse();
                pt.Project(projection);
                d = pt.DistanceTo(crit);
                i++;
            }
            cnt = i;
            return(pt);
        }
        public IEnumerable <CPoint> DirectTrack(CPoint crit, CProjection projection)
        {
            var          pt  = this;
            const double max = double.MaxValue;
            var          d   = max;
            var          i   = 0;
            var          res = new List <CPoint>();

            while (d > Config.Acc && i < Config.Count)
            {
                res.Add(pt);
                pt = pt.DirectIterated(projection);
                d  = pt.DistanceTo(crit);
                i++;
            }
            return(res);
        }
Exemple #8
0
        private void PictureBoxMouseDoubleClick(object sender, MouseEventArgs e)
        {
            var fr    = _stack.Peek();
            var r     = fr.Rectangle;
            var pixWd = r.Width / pictureBox.Width;
            var pixHt = r.Height / pictureBox.Height;
            var newX  = r.X + e.X * pixWd;
            var newY  = r.Y + e.Y * pixHt;

            if (_pointSelecting)
            {
                var c1 = newX;
                var c2 = newY;
                var rd = c1 * c1 + c2 * c2;
                var c0 = 1 - rd;
                if (rd <= 1)
                {
                    c0 = Math.Sqrt(c0);
                    var cpt = new CPoint(c0, c1, c2);
                    _pointSelected = cpt;
                    PointNumber    = 0;
                    DrawPoint();
                }
                _pointSelecting = false;
                var tr = new TrackPoint(this, PointTrack.Count);
                tr.Show(this);
                track.Lines = PointTrack.Select(p => string.Format("{0} {1}", p, p.RG(CProjection.C1C2))).ToArray();
            }
            else
            {
                var newW    = 20 * pixWd;
                var newH    = 20 * pixHt;
                var newRect = new DRect {
                    X = newX, Y = newY, Width = newW, Height = newH
                };
                var newFr = new ProcessingFrame {
                    Rectangle = newRect
                };
                _stack.Push(newFr);
                Redraw();
            }
        }
Exemple #9
0
        private void FillPixel(Bitmap bmp, double x, double y)
        {
            var c1 = x;
            var c2 = y;
            var rd = c1 * c1 + c2 * c2;
            var c0 = 1 - rd;
            var pt = NPt(c1, c2);

            if (rd <= 1)
            {
                c0 = Math.Sqrt(c0);
                var cpt   = new CPoint(c0, c1, c2);
                var color = RG.GetColorReversed(cpt, CProjection.UpC1C2);
                SetPixel(bmp, pt.X, pt.Y, color);
            }
            else
            {
                SetPixel(bmp, pt.X, pt.Y, Config.White);
            }
        }
        public double DistanceTo(CPoint pt)
        {
            var c0S   = C0 - pt.C0;
            var c1S   = C1 - pt.C1;
            var c2S   = C2 - pt.C2;
            var d1    = c0S * c0S + c1S * c1S + c2S * c2S;
            var dist1 = Math.Sqrt(d1);

            var ptd = pt.Opposite;

            c0S = C0 - ptd.C0;
            c1S = C1 - ptd.C1;
            c2S = C2 - ptd.C2;
            var d2    = c0S * c0S + c1S * c1S + c2S * c2S;
            var dist2 = Math.Sqrt(d2);

            var dist = Math.Min(dist1, dist2);

            return(dist);
        }
Exemple #11
0
 private static IEnumerable <KeyValuePair <CPoint, RGPoint> > GetC0C1ArcPositive(double h1, double h2, double xacc, int sgn)
 {
     xacc = xacc / 100;
     for (var x = h1; x <= h2; x += xacc)
     {
         var c0 = x;
         var c1 = Math.Sqrt(1 - Math.Pow(c0, 2));
         var rd = c0 * c0 + c1 * c1;
         var c2 = 1 - rd;
         if (rd <= 1)
         {
             c2 = sgn * Math.Sqrt(c2);
             var cpt = new CPoint(c0, c1, c2);
             var rg  = cpt.RG(CProjection.C0C1);
             if (rg.G >= 0)
             {
                 yield return(new KeyValuePair <CPoint, RGPoint>(cpt, rg));
             }
         }
     }
 }
Exemple #12
0
 private static IEnumerable <KeyValuePair <CPoint, RGPoint> > GetC1C2ArcPositive(double h1, double h2, double yacc, int sgn)
 {
     yacc = yacc / 100;
     for (var y = h1; y <= h2; y += yacc)
     {
         var c2 = y;
         var c1 = Math.Sqrt(1 - Math.Pow(c2, 2));
         var rd = c1 * c1 + c2 * c2;
         var c0 = 1 - rd;
         if (rd <= 1)
         {
             c0 = sgn * Math.Sqrt(c0);
             var cpt = new CPoint(c0, c1, c2);
             var rg  = cpt.RG(CProjection.C1C2);
             if (rg.G >= 0)
             {
                 yield return(new KeyValuePair <CPoint, RGPoint>(cpt, rg));
             }
         }
     }
 }
Exemple #13
0
 private static IEnumerable <KeyValuePair <CPoint, RGPoint> > GetC0C1TrianglePositive(double h1, double h2, double xacc, double yacc, int sgn)
 {
     CorrectAcc(h1, h2, ref xacc, ref yacc);
     for (var x = h1; x <= h2; x += xacc)
     {
         for (var y = 0.0; y <= 1.0; y += yacc)
         {
             var c0 = x;
             var c1 = y;
             var rd = c0 * c0 + c1 * c1;
             var c2 = 1 - rd;
             if (rd <= 1)
             {
                 c2 = sgn * Math.Sqrt(c2);
                 var cpt = new CPoint(c0, c1, c2);
                 var rg  = cpt.RG(CProjection.C0C1);
                 if (rg.G >= 0)
                 {
                     yield return(new KeyValuePair <CPoint, RGPoint>(cpt, rg));
                 }
             }
         }
     }
 }
Exemple #14
0
 private static IEnumerable <KeyValuePair <CPoint, RGPoint> > GetC1C2TrianglePositive(double h1, double h2, double xacc, double yacc, int sgn)
 {
     CorrectAcc(h1, h2, ref xacc, ref yacc);
     for (var x = 0.0; x <= 1.0; x += xacc)
     {
         for (var y = h1; y <= h2; y += yacc)
         {
             var c1 = x;
             var c2 = y;
             var rd = c1 * c1 + c2 * c2;
             var c0 = 1 - rd;
             if (rd <= 1)
             {
                 c0 = sgn * Math.Sqrt(c0);
                 var cpt = new CPoint(c0, c1, c2);
                 var rg  = cpt.RG(CProjection.C1C2);
                 //if (rg.G >= 0)
                 //{
                 yield return(new KeyValuePair <CPoint, RGPoint>(cpt, rg));
                 //}
             }
         }
     }
 }
Exemple #15
0
        private static void DrawLineC0C2(double x, double y, double xsz, double ysz, double sz, Pen pen, CPoint cp1, CPoint cp2, Graphics gr, bool verify = true)
        {
            var i1 = Correct((cp1.C0 - x) / xsz, sz);
            var i2 = Correct((cp2.C0 - x) / xsz, sz);
            var j1 = Correct((cp1.C2 - y) / ysz, sz);
            var j2 = Correct((cp2.C2 - y) / ysz, sz);

            var di = Math.Abs(i2 - i1);
            var dj = Math.Abs(j2 - j1);
            var d  = Math.Sqrt(di * di + dj * dj);

            var check = sz / 3;

            if (d >= check && verify)
            {
                return;
            }

            lock (gr)
            {
                gr.DrawLine(pen, (float)i1, (float)j1, (float)i2, (float)j2);
            }
        }
Exemple #16
0
        private static void DrawXCrossC0C1(double x, double y, double xsz, double ysz, double sz, Color clr, CPoint cp1, Graphics gr, int radius = 3)
        {
            var i1 = Correct((cp1.C0 - x) / xsz, sz);
            var j1 = Correct((cp1.C1 - y) / ysz, sz);

            var pen = new Pen(clr);

            lock (gr)
            {
                var p1 = new Point((int)(i1 - radius), (int)(j1 - radius));
                var p2 = new Point((int)(i1 + radius), (int)(j1 + radius));
                var p3 = new Point((int)(i1 - radius), (int)(j1 - radius));
                var p4 = new Point((int)(i1 + radius), (int)(j1 - radius));
                gr.DrawEllipse(pen, (float)(i1 - radius), (float)(j1 - radius), 2 * radius, 2 * radius);
                gr.DrawLine(pen, p1, p2);
                gr.DrawLine(pen, p3, p4);
            }
        }
Exemple #17
0
        private static void DrawPointC0C1(double x, double y, double xsz, double ysz, double sz, Color clr, CPoint cp1, Graphics gr, int radius = 3)
        {
            var i1 = Correct((cp1.C0 - x) / xsz, sz);
            var j1 = Correct((cp1.C1 - y) / ysz, sz);

            var pen = new Pen(clr);

            lock (gr)
            {
                gr.DrawEllipse(pen, (float)(i1 - radius), (float)(j1 - radius), 2 * radius, 2 * radius);
            }
        }
Exemple #18
0
 public static void SetPixel(double x, double y, double xsz, double ysz, double sz, Color clr, CPoint cp1, Bitmap bmp, CProjection projection)
 {
     if (projection.HasFlag(CProjection.C0C1))
     {
         SetPixelC0C1(x, y, xsz, ysz, sz, clr, cp1, bmp);
     }
     else if (projection.HasFlag(CProjection.C1C2))
     {
         SetPixelC1C2(x, y, xsz, ysz, sz, clr, cp1, bmp);
     }
     else if (projection.HasFlag(CProjection.C0C2))
     {
         SetPixelC0C2(x, y, xsz, ysz, sz, clr, cp1, bmp);
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Exemple #19
0
 public static void DrawXCross(double x, double y, double xsz, double ysz, double sz, Color clr, CPoint cp1, Graphics gr, CProjection projection, int radius = 3)
 {
     if (projection.HasFlag(CProjection.C0C1))
     {
         DrawXCrossC0C1(x, y, xsz, ysz, sz, clr, cp1, gr, radius);
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Exemple #20
0
 public static void DrawLine(double x, double y, double xsz, double ysz, double sz, Pen pen, CPoint cp1, CPoint cp2, Graphics gr, CProjection projection, bool verify = true)
 {
     if (projection.HasFlag(CProjection.C0C1))
     {
         DrawLineC0C1(x, y, xsz, ysz, sz, pen, cp1, cp2, gr, verify);
     }
     else if (projection.HasFlag(CProjection.C1C2))
     {
         DrawLineC1C2(x, y, xsz, ysz, sz, pen, cp1, cp2, gr, verify);
     }
     else if (projection.HasFlag(CProjection.C0C2))
     {
         DrawLineC0C2(x, y, xsz, ysz, sz, pen, cp1, cp2, gr, verify);
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Exemple #21
0
        private static Color GetBgColor(CPoint pt, CProjection projection)
        {
            var rp = pt.RG(projection);

            return(rp.G < 0 ? Config.Green : Config.Blue);
        }
Exemple #22
0
        private static void FillPointC0C2(double x, double y, double xsz, double ysz, double sz, Color clr, CPoint cp1, Graphics gr, int radius = 3)
        {
            var i1 = Correct((cp1.C0 - x) / xsz, sz);
            var j1 = Correct((cp1.C0 - y) / ysz, sz);

            var brush = new SolidBrush(clr);

            lock (gr)
            {
                gr.FillEllipse(brush, (float)(i1 - radius), (float)(j1 - radius), 2 * radius, 2 * radius);
            }
        }
Exemple #23
0
 private Point NPt(CPoint p)
 {
     return(NPt(p.C1, p.C2));
 }
 private Point NPt(CPoint p)
 {
     return(NPt(p.C0, p.C1));
 }
Exemple #25
0
        private static void SetPixelC0C2(double x, double y, double xsz, double ysz, double sz, Color clr, CPoint cp1, Bitmap bmp)
        {
            var i1 = (int)Correct((cp1.C0 - x) / xsz, sz);
            var j1 = (int)Correct((cp1.C0 - y) / ysz, sz);

            SetPixel(i1, j1, bmp, clr);
        }
 public CPoint(CPoint src)
     : this(src.C0, src.C1, src.C2)
 {
 }