示例#1
0
        public static clsLine LinePointToTangent(clsPoint p1, clsCircle c1)
        {
            double   a  = 0;
            double   b  = 0;
            double   r  = 0;
            double   d  = 0;
            clsLine  l1 = new clsLine();
            clsPoint p2 = new clsPoint();

            r = c1.Radius;
            d = p1.Dist(c1.Centre);
            if (d < r)
            {
                return(null);
            }
            a  = Asin(r / d);
            l1 = new clsLine(p1, c1.Centre);
            b  = l1.Angle;

            p2 = c1.Point(PI / 2 + a + b);
            return(new clsLine(p1, p2));
        }
示例#2
0
        public clsPoint Intersect(clsCircle c1, bool firstSolution)
        {
            double  a  = 0;
            clsLine l1 = default(clsLine);

            if (mdlGeometry.Dist(Centre, c1.Centre) > Radius + c1.Radius)
            {
                return(null);
            }
            if (mdlGeometry.Dist(Centre, c1.Centre) < Abs(Radius - c1.Radius))
            {
                return(null);
            }
            l1 = new clsLine(Centre.Copy(), c1.Centre.Copy());
            a  = Acos((Radius * Radius + l1.Length * l1.Length - c1.Radius * c1.Radius) / (2 * Radius * l1.Length));
            //Cosine rule
            if (firstSolution == false)
            {
                a = -a;
            }
            l1.Rotate(a);
            l1.Length = Radius;
            return(l1.P2);
        }
示例#3
0
        public static clsLine LineTangentToArcs(clsCircle c1, clsCircle c2, int n = -1)
        {
            clsArc myArc1 = new clsArc();
            clsArc myArc2 = new clsArc();

            //n is the solution number, from 1 to 4 (see document SolutionsToTangencies.doc)
            //1 = Plus - Minus
            //2 = Plus - Plus
            //3 = Minus - Minus
            //4 = Minus - Plus
            //In this case, you must pass in an arc
            if (n == -1)
            {
                myArc1 = (clsArc)c1;
                myArc2 = (clsArc)c2;
                if (myArc1.Direction == 1 & myArc2.Direction == -1)
                {
                    n = 1;
                }
                if (myArc1.Direction == 1 & myArc2.Direction == 1)
                {
                    n = 2;
                }
                if (myArc1.Direction == -1 & myArc2.Direction == -1)
                {
                    n = 3;
                }
                if (myArc1.Direction == -1 & myArc2.Direction == 1)
                {
                    n = 4;
                }
            }

            double   x1    = 0;
            double   y1    = 0;
            double   x2    = 0;
            double   y2    = 0;
            double   r1    = 0;
            double   r2    = 0;
            double   d     = 0;
            double   theta = 0;
            double   alpha = 0;
            double   a     = 0;
            clsPoint p1    = new clsPoint();
            clsPoint p2    = new clsPoint();

            x1 = c1.Centre.X;
            y1 = c1.Centre.Y;
            x2 = c2.Centre.X;
            y2 = c2.Centre.Y;
            r1 = c1.Radius;
            r2 = c2.Radius;

            d     = Sqrt(Pow((x2 - x1), 2) + Pow((y2 - y1), 2));
            theta = Angle(x1, y1, x2, y2);

            if (n == 1)
            {
                if (d < r1 + r2)
                {
                    return(null);
                }
                alpha = Acos((r1 + r2) / d);
                a     = theta - alpha;
                p1    = new clsPoint(x1 + r1 * Cos(a), y1 + r1 * Sin(a));
                p2    = new clsPoint(x2 - r2 * Cos(a), y2 - r2 * Sin(a));
            }
            else if (n == 2)
            {
                if (d < Abs(r2 - r1))
                {
                    return(null);
                }
                alpha = Acos((r2 - r1) / d);
                a     = alpha - theta;
                p1    = new clsPoint(x1 + r1 * Cos(a), y1 - r1 * Sin(a));
                p2    = new clsPoint(x2 + r2 * Cos(a), y2 - r2 * Sin(a));
            }
            else if (n == 3)
            {
                if (d < Abs(r2 - r1))
                {
                    return(null);
                }
                alpha = PI / 2 + Asin((r2 - r1) / d);
                a     = alpha + theta;
                p1    = new clsPoint(x1 + r1 * Cos(a), y1 + r1 * Sin(a));
                p2    = new clsPoint(x2 + r2 * Cos(a), y2 + r2 * Sin(a));
            }
            else if (n == 4)
            {
                if (d < r1 + r2)
                {
                    return(null);
                }
                alpha = Acos((r1 + r2) / d);
                a     = theta + alpha;
                p1    = new clsPoint(x1 + r1 * Cos(a), y1 + r1 * Sin(a));
                p2    = new clsPoint(x2 - r2 * Cos(a), y2 - r2 * Sin(a));
            }
            else
            {
                return(null);
            }

            return(new clsLine(p1, p2));
        }