private void Draw(ref ShapePoint inter)
        {
            inter.Type = ShapePoint.ShapeType.Intersection;
            Intersections.Add(inter);

            /*var d = new Ellipse
             * {
             *  Width = 5,
             *  Height = 5,
             *  Fill = Brushes.Black
             * };
             * Canvas.SetTop(d, inter.Y);
             * Canvas.SetLeft(d, inter.X);
             * DrawCanvas.Children.Add(d);*/
        }
        private bool FindIntersection(ShapePoint start1, ShapePoint end1, ShapePoint start2, ShapePoint end2, out ShapePoint inter)
        {
            var A1  = end1.Y - start1.Y;
            var B1  = start1.X - end1.X;
            var A2  = end2.Y - start2.Y;
            var B2  = start2.X - end2.X;
            var C1  = A1 * start1.X + B1 * start1.Y;
            var C2  = A2 * start2.X + B2 * start2.Y;
            var det = A1 * B2 - A2 * B1;

            if (Math.Abs(det) < 0.001)
            {
                inter = new ShapePoint(0, 0);
                return(false);
            }
            var x = (B2 * C1 - B1 * C2) / det;
            var y = (A1 * C2 - A2 * C1) / det;

            /*if(Shape1.Count==3)
             * {
             *  inter = new ShapePoint(x, y) { Type = ShapePoint.ShapeType.Intersection };
             *  return true;
             * }*/
            var xMin  = Math.Min(start2.X, end2.X);
            var xMax  = Math.Max(start2.X, end2.X);
            var yMin  = Math.Min(start2.Y, end2.Y);
            var yMax  = Math.Max(start2.Y, end2.Y);
            var xMin2 = Math.Min(start1.X, end1.X);
            var xMax2 = Math.Max(start1.X, end1.X);
            var yMin2 = Math.Min(start1.Y, end1.Y);
            var yMax2 = Math.Max(start1.Y, end1.Y);


            if (xMin <= x && x <= xMax &&
                yMin <= y && y <= yMax &&
                xMin2 <= x && x <= xMax2 &&
                yMin2 <= y && y <= yMax2)   //true)
            {
                inter = new ShapePoint(x, y)
                {
                    Type = ShapePoint.ShapeType.Intersection
                };
                return(true);
            }
            inter = new ShapePoint(0, 0);
            return(false);
        }
Esempio n. 3
0
 private static double DistanceSquared(ShapePoint p1, ShapePoint p2)
 {
     return((p2.X - p1.X) * (p2.X - p1.X) + (p2.Y - p1.Y) * (p2.Y - p1.Y));
 }