Example #1
0
        private protected override double GetDistance(Point P)
        {
            var    P1 = Point1.ToPoint(Chart);
            var    P2 = Point2.ToPoint(Chart);
            double A  = P1.DistanceTo(P2);
            double B  = P.DistanceTo(P2);
            double C  = P.DistanceTo(P1);

            double pp = (A + B + C) / 2;

            return((2 * Math.Sqrt(pp * (pp - A) * (pp - B) * (pp - C))) / A);
        }
Example #2
0
 private protected override void ChangeMethod(Vector?Changes)
 {
     if (Changes.HasValue)
     {
         NP1 = Point1.ToPoint(Chart) + Changes.Value;
         NP2 = Point2.ToPoint(Chart) + Changes.Value;
     }
     else
     {
         NP1 = Point1.ToPoint(Chart);
         NP2 = Point2.ToPoint(Chart);
     }
 }
Example #3
0
 private protected override List <Hook> CreateSubhooks()
 {
     return(new List <Hook>
     {
         new Hook
         (
             this,
             P => P.DistanceTo(Point1.ToPoint(Chart)),
             P => Point1.ToPoint(Chart),
             () => 14,
             V =>
         {
             if (V.HasValue)
             {
                 NP1 = Point1.ToPoint(Chart) + V.Value;
             }
             else
             {
                 NP1 = Point1.ToPoint(Chart);
             }
             NP2 = Point2.ToPoint(Chart);
         },
             DrawElement,
             DrawShadow,
             AcceptNewCoordinates
         ),
         new Hook
         (
             this,
             P => P.DistanceTo(Point2.ToPoint(Chart)),
             P => Point2.ToPoint(Chart),
             () => 14,
             V =>
         {
             if (V.HasValue)
             {
                 NP2 = Point2.ToPoint(Chart) + V.Value;
             }
             else
             {
                 NP2 = Point2.ToPoint(Chart);
             }
             NP1 = Point1.ToPoint(Chart);
         },
             DrawElement,
             DrawShadow,
             AcceptNewCoordinates
         )
     });
 }
Example #4
0
        private protected override Point GetHookPoint(Point P)
        {
            var    P1 = Point1.ToPoint(Chart);
            var    P2 = Point2.ToPoint(Chart);
            double A  = P1.DistanceTo(P2);
            double B  = P.DistanceTo(P2);
            double C  = P.DistanceTo(P1);
            double pp = (A + B + C) / 2;
            double h  = (2 * Math.Sqrt(pp * (pp - A) * (pp - B) * (pp - C))) / A;

            double z = Math.Sqrt(Math.Pow(C, 2) - Math.Pow(h, 2));

            P1.GetCoeffsAB(P2, out double a, out _);
            double x = z / Math.Sqrt(Math.Pow(a, 2) + 1);

            return(new Point(P1.X + x, P1.Y + a * x));
        }
Example #5
0
        private protected override void DrawShadow(DrawingVisual ElementsVisual, DrawingVisual PricesVisual, DrawingVisual TimesVisual)
        {
            var br = Dispatcher.Invoke(() => { return(Chart.ChartBackground); });

            var P1 = Point1.ToPoint(Chart);
            var P2 = Point2.ToPoint(Chart);

            P1.GetCoeffsAB(P2, out double A, out double B);

            var linpen = new Pen(br, this.LineThikness + 1); linpen.Freeze();
            var linps  = new List <Point>();

            if (LineIndent == 0)
            {
                linps.Add(new Point(0, B));
                linps.Add(new Point(Chart.ChWidth, A * Chart.ChWidth + B));
            }
            else
            {
                double z = 0, x = 0;
                double len = Math.Sqrt(Math.Pow(Chart.ChWidth, 2) + Math.Pow(B - A * Chart.ChWidth + B, 2));
                double dx1 = LineDash / Math.Sqrt(A + 1);
                double dx2 = LineIndent / Math.Sqrt(A + 1);

                while (z < len)
                {
                    linps.Add(new Point(x, A * x + B)); z += LineDash; x += dx1;
                    linps.Add(new Point(x, A * x + B)); z += LineIndent; x += dx2;
                }
            }

            Dispatcher.Invoke(() =>
            {
                using var dc = ElementsVisual.RenderOpen();

                for (int i = 0; i < linps.Count; i += 2)
                {
                    dc.DrawLine(linpen, linps[i], linps[i + 1]);
                }

                dc.DrawEllipse(Brushes.Black, null, P1, 10, 10);
                dc.DrawEllipse(Brushes.Black, null, P2, 10, 10);
            });
        }
Example #6
0
        public override Action <DrawingContext>[] PrepareToDrawing(Vector?vec, double PixelsPerDip, bool DrawOver = false)
        {
            Point P1, P2;

            if (vec.HasValue)
            {
                P1 = NP1;
                P2 = NP2;
            }
            else
            {
                P1 = Point1.ToPoint(Chart);
                P2 = Point2.ToPoint(Chart);
            }
            P1.GetCoeffsAB(P2, out double A, out double B);

            var linpen = new Pen(this.LineBrush, this.LineThikness + 1); linpen.Freeze();
            var linps  = new List <Point>();

            if (LineIndent == 0)
            {
                linps.Add(new Point(0, B));
                linps.Add(new Point(Chart.ChWidth, A * Chart.ChWidth + B));
            }
            else
            {
                double z = 0, x = 0;
                double len = Math.Sqrt(Math.Pow(Chart.ChWidth, 2) + Math.Pow(B - A * Chart.ChWidth + B, 2));
                double dx1 = LineDash / Math.Sqrt(A + 1);
                double dx2 = LineIndent / Math.Sqrt(A + 1);

                while (z < len)
                {
                    linps.Add(new Point(x, A * x + B)); z += LineDash; x += dx1;
                    linps.Add(new Point(x, A * x + B)); z += LineIndent; x += dx2;
                }
            }
            Action <DrawingContext> drawing;

            if (DrawOver)
            {
                drawing = dc =>
                {
                    for (int i = 0; i < linps.Count; i += 2)
                    {
                        dc.DrawLine(linpen, linps[i], linps[i + 1]);
                    }

                    dc.DrawEllipse(Brushes.Black, null, P1, 14, 14);
                    dc.DrawEllipse(Brushes.White, null, P1, 12, 12);
                    dc.DrawEllipse(Brushes.Black, null, P1, 10, 10);
                    dc.DrawEllipse(Brushes.Black, null, P2, 14, 14);
                    dc.DrawEllipse(Brushes.White, null, P2, 12, 12);
                    dc.DrawEllipse(Brushes.Black, null, P2, 10, 10);
                };
            }
            else
            {
                drawing = dc =>
                {
                    for (int i = 0; i < linps.Count; i += 2)
                    {
                        dc.DrawLine(linpen, linps[i], linps[i + 1]);
                    }
                };
            }
            return(new Action <DrawingContext>[]
            {
                drawing,
                null,
                null
            });
        }