Example #1
0
        public static Segment IntersectCircleLine(Circle circle, Line line)
        {
            var H = circle.center.ProjectToLine(line);

            if (!circle.ContainsPoint(H))
            {
                return(null);
            }
            Point  v = line.Direction.SetLength(1);
            double h = (circle.center - H).Length;
            double d = Math.Sqrt(circle.radius * circle.radius - h * h);

            return(new Segment(H + v * d, H - v * d));
        }