Ejemplo n.º 1
0
        public static Circle2d[] CirclePointPoint(Circle2d ci, Point2d pt1, Point2d pt2)
        {
            // Solution by Robert.P. 2013-02-10
            // solved by intersecting the line which has equal distance to pt1 and pt2 at every point,
            // with the hyperbola that has equal distance to ci and pt1 at every point.


            List <Circle2d> res = null;

            //get squared constants of hyperbola
            double c2 = ci.Center.SquaredDistance(pt1) / 4.0; //center->focus distance squared

            double a = 0.5 * ci.Radius;
            double b = Math.Sqrt(c2 - a * a);

            if (double.IsNaN(b))
            {
                return(null);    //negative square root, no such hyperbola
            }
            // this hyperbola has equal distance to ci and pt1 at every point.
            // it also has focus at ci.Center and pt1
            Hyperbola2d hyper = new Hyperbola2d(new Point2d((ci.X + pt1.X) * 0.5, (ci.Y + pt1.Y) * 0.5), a, b, ci.Center.Angle(pt1));

            //get constants of line dx+ey+f=0, which is equal distance from p1,p2 on every point
            double dx = pt2.X - pt1.X, dy = pt2.Y - pt1.Y;
            double mx   = pt1.X + dx * 0.5;
            double my   = pt1.Y + dy * 0.5;
            Line2d perp = new Line2d(mx, my, mx - dy, my + dx);    //starts from mipoint pt1-pt2 and is perpendicular to that line

            var intpts = Intersect2d.HyperbolaLine(hyper, perp);

            if (intpts == null)
            {
                return(null);
            }

            foreach (Point2d intpt in intpts)
            {
                AddResult(ref res, intpt.X, intpt.Y, intpt.Distance(pt1));
            }

            return(MakeResult(res));
        }