Пример #1
0
        public static void MouseMovement(List <Point> vertices, Point mousePos, Graphics graphics, Pen pen)
        {
            MousePos = mousePos;
            var penForTemLine = new Pen(Color.DarkGray, pen.Width);

            if (vertices.Count > 0)
            {
                _distanceToFirstPoint = CalculationUtil.GetDistance(vertices[0], MousePos);
            }
        }
Пример #2
0
        /// <summary>
        /// Returns a point that equals a point in a given list,
        /// if the points distance to the point in the list is smaller
        /// than the given tolerated ratio.
        /// </summary>
        private static int ChooseVertex(List <Point> vertices, int toleratedRatio)
        {
            int indexOfChosenPoint = vertices.Count;

            foreach (var vertex in vertices)
            {
                if (CalculationUtil.GetDistance(MousePos, vertex) < toleratedRatio)
                {
                    indexOfChosenPoint = vertices.IndexOf(vertex);
                }
            }
            return(indexOfChosenPoint);
        }
Пример #3
0
        /// <summary>
        /// This function determines wether to given lines interesect
        ///  by checking if there is a intersection point, assuming the lines are infinite.
        ///  If there is one the function checks if both lines (finite) contain this intersection point.
        /// </summary>
        public static bool Intersect(Line line1, Line line2)
        {
            Point  IntersectionPoint;
            double thisA = line1.AllPointsOfElement[1].Y - line1.AllPointsOfElement[0].Y;
            double thisB = line1.AllPointsOfElement[0].X - line1.AllPointsOfElement[1].X;
            double thisC = line1.AllPointsOfElement[0].X * thisA + line1.AllPointsOfElement[0].Y * thisB;
            double thatA = line2.AllPointsOfElement[1].Y - line2.AllPointsOfElement[0].Y;
            double thatB = line2.AllPointsOfElement[0].X - line2.AllPointsOfElement[1].X;
            double thatC = line2.AllPointsOfElement[0].X * thatA + line2.AllPointsOfElement[0].Y * thatB;
            double det   = thisA * thatB - thatA * thisB;

            if (det == 0)
            {
                return(false);
            }
            else
            {
                double xNew = (thatB * thisC - thisB * thatC) / det;
                double yNew = (thisA * thatC - thatA * thisC) / det;
                IntersectionPoint = new Point(Convert.ToInt32(xNew), Convert.ToInt32(yNew));
            }

            double LineLength1      = CalculationUtil.GetDistance(line1.AllPointsOfElement[0], line1.AllPointsOfElement[1]);
            double LineLenght2      = CalculationUtil.GetDistance(line2.AllPointsOfElement[0], line2.AllPointsOfElement[1]);
            double proofLineLength1 = CalculationUtil.GetDistance(line1.AllPointsOfElement[0], IntersectionPoint);
            double proofLineLength2 = CalculationUtil.GetDistance(line1.AllPointsOfElement[1], IntersectionPoint);
            double proofLineLength3 = CalculationUtil.GetDistance(line2.AllPointsOfElement[0], IntersectionPoint);
            double proofLineLength4 = CalculationUtil.GetDistance(line2.AllPointsOfElement[1], IntersectionPoint);

            if ((proofLineLength1 < LineLength1 && proofLineLength2 < LineLength1) && (proofLineLength3 < LineLenght2 && proofLineLength4 < LineLenght2))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }