Exemplo n.º 1
0
        public static bool IsOnTheLine(this Point point, CustomLine line)
        {
            double distance = point.GetDistanceToLine(line);

            if (distance > line.StrokeThickness)
            {
                return(false);
            }

            //double line_X1 = line.X1;
            //double line_X2 = line.X2;

            //double line_Y1 = line.Y1;
            //double line_Y2 = line.Y2;
            return(true);
        }
Exemplo n.º 2
0
        public static Point GetProjectionPointOnLine(this Point point, CustomLine line)
        {
            var equation = line.Equation;

            // line                 = Ax + By + C = 0
            // perpendicular line   = -Bx + Ay + C1 = 0

            double A = equation.A, B = equation.B, C = equation.C;
            double D = -B, E = A, F = -D * point.X - E * point.Y;

            double det = A * E - B * D;
            double X   = (C * E - B * F) / det;
            double Y   = (A * F - C * D) / det;

            return(new Point(-X, -Y));
        }
Exemplo n.º 3
0
        public static Point GetPerpendicularPoint(this CustomLine line, Point point)
        {
            var A1 = line.Equation.A;
            var B1 = line.Equation.B;
            var C1 = line.Equation.C;
            var A2 = -B1;
            var B2 = A1;
            var C2 = -(A2 * point.X + B2 * point.Y);

            var X = B1 * C2 - B2 * C1;
            var Y = A2 * C1 - A1 * C2;

            var Z = A1 * B2 - A2 * B1;


            return(new Point(X / Z, -Y / Z));
        }
Exemplo n.º 4
0
        private void ChoosePoint_handler(CustomLine line, Point point)
        {
            if (line.IsSelected())
            {
                line.IsPressed_Point_1 = false;
                line.IsPressed_Point_2 = false;

                if (line.IsNearToPoint1(point))
                {
                    line.IsPressed_Point_1 = true;
                }
                else if (line.IsNearToPoint2(point))
                {
                    line.IsPressed_Point_2 = true;
                }

                lastMousePosition = point;
            }
        }
Exemplo n.º 5
0
        private CustomLine InitLine(double x1, double y1, double x2, double y2, double z1 = 0, double z2 = 0)
        {
            CustomLine line = new CustomLine(new SolidColorBrush((Color)ColorPicker.SelectedColor))
            {
                X1 = x1,
                Y1 = y1,
                Z1 = z1,
                X2 = x2,
                Y2 = y2,
                Z2 = z2,
                StrokeThickness = 5,
                originalPoint1  = new Point3D(int.MaxValue, int.MaxValue, int.MaxValue),
                originalPoint2  = new Point3D(int.MaxValue, int.MaxValue, int.MaxValue)
            };

            AddEventsOnLine(line);

            return(line);
        }
Exemplo n.º 6
0
        public static Tuple <Point, Point> GetBisectorPoint(CustomLine firstLine, CustomLine secondLine)
        {
            var A1 = firstLine.Equation.A;
            var B1 = firstLine.Equation.B;
            var C1 = firstLine.Equation.C;
            var A2 = secondLine.Equation.A;
            var B2 = secondLine.Equation.B;
            var C2 = secondLine.Equation.C;



            //var firstPossibleA = A1 * sqrt2 - A2 * sqrt1;
            //var secondPossibleA = A1 * sqrt2 + A2 * sqrt1;

            //var firstPossibleB = B1 * sqrt2 - B2 * sqrt1;
            //var secondPossibleB = B1 * sqrt2 + B2 * sqrt1;

            //var firstPossibleC = C1 * sqrt2 - C2 * sqrt1;
            //var secondPossibleC = C1 * sqrt2 + C2 * sqrt1;

            var intersection = GetIntersection(firstLine, secondLine);

            var length1 = Math.Sqrt(Math.Pow(intersection.X - firstLine.X1, 2) + Math.Pow(intersection.Y - firstLine.Y1, 2));
            var length2 = Math.Sqrt(Math.Pow(intersection.X - secondLine.X1, 2) + Math.Pow(intersection.Y - secondLine.Y1, 2));

            //var possiblePoint1 = new Point(0, -firstPossibleC / firstPossibleB);
            //var possiblePoint2 = new Point(-firstPossibleC / firstPossibleA, 0);
            //var possiblePoint3 = new Point(intersection.X, intersection.Y);

            //var x = rnd.Next(-2000, 2000);

            // y = -Bx -C / A

            //var possiblePoint4 = new Point(x, (-secondPossibleB* x - secondPossibleC) / secondPossibleA);
            //x = -c/a

            var lambda = length1 / length2;

            var x = (firstLine.X1 + lambda * secondLine.X1) / (1 + lambda);
            var y = (firstLine.Y1 + lambda * secondLine.Y1) / (1 + lambda);

            return(new Tuple <Point, Point>(new Point(intersection.X, intersection.Y), new Point(x, y)));
        }
Exemplo n.º 7
0
        private void SelectLine_Handler(CustomLine line, MouseButtonEventArgs ea)
        {
            var parent = line.GetParent();

            if (ea.ClickCount == 3)
            {
                if (parent == null)
                {
                    DivideLine_Click(line, ea);
                }
            }
            else if (ea.ClickCount == 2)
            {
                additionLinesWindow?.Reset();

                if (parent != null)
                {
                    while (parent.GetParent() != null)
                    {
                        parent = parent.GetParent();
                    }
                }
                else
                {
                    parent = line;
                }

                if (parent.IsSelected())
                {
                    parent.UnSelect();
                    selectedObjects.Remove(parent);
                    morphWindow?.RemoveObject(parent);
                }
                else
                {
                    parent.Select();
                    selectedObjects.Add(parent);
                    morphWindow?.AddObject(parent);
                }
            }
        }
Exemplo n.º 8
0
        public static bool CheckBisector(CustomLine firstLine, CustomLine secondLine)
        {
            var matrix = new Matrix3D(firstLine.X1 - firstLine.X2, firstLine.Y1 - firstLine.Y2, firstLine.Z1 - firstLine.Z2, 0,
                                      secondLine.X1 - secondLine.X2, secondLine.Y1 - secondLine.Y2, secondLine.Z1 - secondLine.Z2, 0,
                                      firstLine.X1 - secondLine.X1, firstLine.Y1 - secondLine.Y1, firstLine.Z1 - secondLine.Z1, 0,
                                      0, 0, 0, 1);

            if (matrix.Determinant != 0)
            {
                return(false);
            }
            ;

            var ok     = true;
            var first  = (firstLine.X1 - firstLine.X2) * (secondLine.Y1 - secondLine.Y2) * (secondLine.Z1 - secondLine.Z2);
            var second = (secondLine.X1 - secondLine.X2) * (firstLine.Y1 - firstLine.Y2) * (secondLine.Z1 - secondLine.Z2);

            ok    &= first == second;
            second = (secondLine.X1 - secondLine.X2) * (secondLine.Y1 - secondLine.Y2) * (firstLine.Z1 - firstLine.Z2);
            ok    &= first == second;

            return(ok);
        }
Exemplo n.º 9
0
        private void DivideLine_Click(CustomLine line, MouseButtonEventArgs e)
        {
            //wont work due to Z cord;
            return;

            if (selectedObjects.Count != 1)
            {
                return;
            }

            var selectedLine = selectedObjects.FirstOrDefault();

            if (!(selectedLine is IMyObject))
            {
                return;
            }

            var position = e.GetPosition(Canvas);

            position.Offset(-CordCenter.X, -CordCenter.Y);
            var x = position.X;
            var y = position.Y;

            var newLine = InitLine(x, y, line.X2, line.Y2);

            line.X2 = x;
            line.Y2 = y;

            if (selectedLine != null)
            {
                selectedLine.UnSelect();
                selectedObjects.Remove(selectedLine);
            }
            line.Select();
            selectedObjects.Add(line);
            Canvas.Children.Add(newLine);
        }
Exemplo n.º 10
0
 private string GetStringOnLine(string offset, CustomLine line)
 {
     return($"{offset}({line.X1:00.00};{line.Y1:00.00};{line.Z1:00.00}) " +
            $"({line.X2:00.00};{line.Y2:00.00};{line.Z2:00.00})\n" +
            $"{offset}  {line.Equation}\n");
 }
Exemplo n.º 11
0
        private void AddEventsOnLine(CustomLine line)
        {
            line.MouseLeftButtonDown += delegate(object s, MouseButtonEventArgs ea)
            {
                var point = ea.GetPosition(Canvas);
                point.Offset(-CordCenter.X, -CordCenter.Y);

                if (line.GetParent() == null)
                {
                    ChoosePoint_handler(line, point);
                }
                SelectLine_Handler(line, ea);
            };

            line.MouseLeftButtonUp += delegate(object s, MouseButtonEventArgs ea)
            {
                line.IsPressed_Point_1 = false;
                line.IsPressed_Point_2 = false;
            };

            line.PreviewMouseRightButtonDown += delegate(object s, MouseButtonEventArgs ea)
            {
                var point = ea.GetPosition(Canvas);
                point.Offset(-CordCenter.X, -CordCenter.Y);
                if (line.GetParent() == null)
                {
                    ChoosePoint_handler(line, point);
                }
                SetPointsInfo(point, line);
            };

            line.PreviewMouseRightButtonUp += delegate(object s, MouseButtonEventArgs ea)
            {
                var point = ea.GetPosition(Canvas);
                point.Offset(CordCenter.X, CordCenter.Y);
            };

            line.MouseEnter += delegate(object s, MouseEventArgs ea)
            {
                if (line.IsSelected())
                {
                    Cursor = Cursors.Hand;
                }
                //line.IsNotEntered = true;
                //if (ea.LeftButton == MouseButtonState.Pressed && !(line.IsPressed_Point_1 || line.IsPressed_Point_2))
                //{
                //    line.IsNotEntered = false;
                //}
            };
            line.MouseMove += delegate(object s, MouseEventArgs ea)
            {
                if (ea.LeftButton != MouseButtonState.Pressed)
                {
                    line.IsPressed_Point_1 = false;
                    line.IsPressed_Point_2 = false;
                }

                onLine = line;
                SetPointsInfo(ea.GetPosition(Canvas), line);
                var position = ea.GetPosition(Canvas);
                position.Offset(-CordCenter.X, -CordCenter.Y);
                if (line.IsSelected())
                {
                    if (line.IsNearToPoint1(position) || line.IsNearToPoint2(position))
                    {
                        Cursor = Cursors.SizeAll;
                    }
                    else
                    {
                        Cursor = Cursors.Hand;
                    }
                }
            };
            line.MouseLeave += delegate(object s, MouseEventArgs ea)
            {
                onLine = null;
                Cursor = Cursors.Arrow;
            };
            line.MouseUp += delegate(object s, MouseButtonEventArgs ea)
            {
                Cursor = Cursors.Arrow;
            };
        }
Exemplo n.º 12
0
 public static double GetDistanceToLine(this Point point, CustomLine line)
 {
     return(Math.Abs(((line.X2 - line.X1) * (point.Y - line.Y1) - (line.Y2 - line.Y1) * (point.X - line.X1)) / Math.Sqrt(Math.Pow(line.X2 - line.X1, 2) + Math.Pow(line.Y2 - line.Y1, 2))));
 }
Exemplo n.º 13
0
 public static Point GetMedianPoint(this CustomLine line)
 {
     return(new Point((line.X1 + line.X2) / 2, (line.Y1 + line.Y2) / 2));
 }