예제 #1
0
        public static void GetIntersections(
            Circle2D circle,
            Arc2D arc,
            double precision,
            out Point2D[] intersections,
            out bool overlap)
        {
            intersections = (Point2D[])null;
            overlap       = false;
            Vector2D vector2D1 = arc.center - circle.Center;
            double   length    = vector2D1.GetLength();

            if (System.Math.Abs(length) <= precision)
            {
                if (!MathUtil.AreApproxEqual(circle.Radius, arc.radius, precision))
                {
                    return;
                }
                overlap = true;
            }
            else
            {
                Vector2D vector2D2 = vector2D1 / length;
                double   num1      = length;
                double   num2      = num1 * num1;
                double   num3      = circle.Radius * circle.Radius;
                double   num4      = arc.radius * arc.radius;
                double   num5      = num2 - num4 + num3;
                double   d         = (4.0 * num2 * num3 - num5 * num5) / (4.0 * num2);
                if (d < -precision)
                {
                    return;
                }
                double num6 = num5 / (2.0 * num1);
                if (d <= precision)
                {
                    Point2D point = circle.Center + num6 * vector2D2;
                    if (!arc.ContainsAngleProjection(point))
                    {
                        return;
                    }
                    intersections = new Point2D[1] {
                        point
                    };
                }
                else
                {
                    double a = System.Math.Sqrt(d);
                    if (MathUtil.AreApproxEqual(a, 0.0, precision))
                    {
                        Point2D point = circle.Center + num6 * vector2D2;
                        if (!arc.ContainsAngleProjection(point))
                        {
                            return;
                        }
                        intersections = new Point2D[1] {
                            point
                        };
                    }
                    else
                    {
                        Vector2D       vector2D3   = new Vector2D(vector2D2.Y, -vector2D2.X);
                        List <Point2D> point2DList = new List <Point2D>(2);
                        Point2D        point1      = circle.Center + num6 * vector2D2 + a * vector2D3;
                        if (arc.ContainsAngleProjection(point1))
                        {
                            point2DList.Add(point1);
                        }
                        Point2D point2 = circle.Center + num6 * vector2D2 - a * vector2D3;
                        if (arc.ContainsAngleProjection(point2))
                        {
                            point2DList.Add(point2);
                        }
                        if (point2DList.Count <= 0)
                        {
                            return;
                        }
                        intersections = point2DList.ToArray();
                    }
                }
            }
        }
예제 #2
0
        public static bool GetIntersections(
            Arc2D arc1,
            Arc2D arc2,
            double precision,
            out Point2D[] intersections,
            out Arc2D[] overlappingArcs)
        {
            intersections   = (Point2D[])null;
            overlappingArcs = (Arc2D[])null;
            Vector2D vector2D1 = arc2.center - arc1.center;
            double   length    = vector2D1.GetLength();

            if (System.Math.Abs(length) <= precision)
            {
                if (MathUtil.AreApproxEqual(arc1.radius, arc2.radius, precision))
                {
                    Arc2D.smethod_0(arc1, arc2, precision, out overlappingArcs);
                }
            }
            else
            {
                Vector2D vector2D2 = vector2D1 / length;
                double   num1      = length;
                double   num2      = num1 * num1;
                double   num3      = arc1.radius * arc1.radius;
                double   num4      = arc2.radius * arc2.radius;
                double   num5      = num2 - num4 + num3;
                double   d         = (4.0 * num2 * num3 - num5 * num5) / (4.0 * num2);
                if (d >= -precision)
                {
                    double num6 = num5 / (2.0 * num1);
                    if (d <= precision)
                    {
                        Point2D point = arc1.center + num6 * vector2D2;
                        if (arc1.ContainsAngleProjection(point) && arc2.ContainsAngleProjection(point))
                        {
                            intersections = new Point2D[1] {
                                point
                            }
                        }
                        ;
                    }
                    else
                    {
                        double a = System.Math.Sqrt(d);
                        if (MathUtil.AreApproxEqual(a, 0.0, precision))
                        {
                            Point2D point = arc1.center + num6 * vector2D2;
                            if (arc1.ContainsAngleProjection(point) && arc2.ContainsAngleProjection(point))
                            {
                                intersections = new Point2D[1] {
                                    point
                                }
                            }
                            ;
                        }
                        else
                        {
                            Vector2D       vector2D3   = new Vector2D(vector2D2.Y, -vector2D2.X);
                            List <Point2D> point2DList = new List <Point2D>(2);
                            Point2D        point1      = arc1.center + num6 * vector2D2 + a * vector2D3;
                            if (arc1.ContainsAngleProjection(point1) && arc2.ContainsAngleProjection(point1))
                            {
                                point2DList.Add(point1);
                            }
                            Point2D point2 = arc1.center + num6 * vector2D2 - a * vector2D3;
                            if (arc1.ContainsAngleProjection(point2) && arc2.ContainsAngleProjection(point2))
                            {
                                point2DList.Add(point2);
                            }
                            if (point2DList.Count > 0)
                            {
                                intersections = point2DList.ToArray();
                            }
                        }
                    }
                }
            }
            if (intersections == null)
            {
                return(overlappingArcs != null);
            }
            return(true);
        }