コード例 #1
0
        public override List <Intersection> Intersect(CircLine other)
        {
            List <Intersection> intersections = new List <Intersection>();

            if (other is Circle)
            {
                Circle otherC = (Circle)other;
                intersections = otherC.Intersect(this);
                if (intersections == null)
                {
                    intersections = otherC.Intersect(this);
                }

                return(intersections.Select(i => new CircLine.Intersection(i.Point, i.ParamB, i.ParamA)).ToList());
            }

            Line line = (Line)other;

            Complex denominator = b.Conjugate * line.b - b * line.b.Conjugate;

            if (denominator == Complex.Zero)
            {
                return(null);
            }

            Complex z = -(b * line.c - line.b * c) / denominator;

            intersections.Add(new Intersection(z, Project(z).Param, line.Project(z).Param));

            return(intersections);
        }
コード例 #2
0
        public override List <Intersection> Intersect(CircLine other)
        {
            List <Intersection> intersections = new List <Intersection>();

            if (other is Circle)
            {
                Circle otherC = (Circle)other;

                Complex p0 = this.Center;
                Complex p1 = otherC.Center;
                double  d  = (p1 - p0).Modulus;
                double  r0 = this.Radius;
                double  r1 = otherC.Radius;

                if (d > (r0 + r1))                 // outside
                {
                    return(null);
                }
                if (d < Math.Abs(r0 - r1))
                {
                    return(intersections);
                }
                if (d == 0)
                {
                    return(intersections);
                }

                double  a  = (r0 * r0 - r1 * r1 + d * d) / (2 * d);
                double  h  = Math.Sqrt(r0 * r0 - a * a);
                Complex p2 = p0 + a * (p1 - p0) / d;

                Complex intersect;
                intersect = new Complex(
                    p2.Re + h * (p1.Im - p0.Im) / d,
                    p2.Im - h * (p1.Re - p0.Re) / d
                    );

                intersections.Add(new Intersection(
                                      intersect,
                                      Math.Atan2(p0.Im - intersect.Im, p0.Re - intersect.Re),
                                      Math.Atan2(p1.Im - intersect.Im, p1.Re - intersect.Re)
                                      ));

                intersect = new Complex(
                    p2.Re - h * (p1.Im - p0.Im) / d,
                    p2.Im + h * (p1.Re - p0.Re) / d
                    );

                intersections.Add(new Intersection(
                                      intersect,
                                      Math.Atan2(p0.Im - intersect.Im, p0.Re - intersect.Re),
                                      Math.Atan2(p1.Im - intersect.Im, p1.Re - intersect.Re)
                                      ));

                return(intersections);
            }

            Line line = (Line)other;

            Complex nearPoint = line.Project(Center).Point - line.Origin;

            double dist = (Center - nearPoint).Modulus;

            if (dist - Radius > 0)
            {
                return(null);
            }

            Complex p;

            p = Line.Create(nearPoint, line.Angle).Evaluate(Math.Sqrt(RadiusSquared - dist * dist));
            intersections.Add(new Intersection(
                                  p,
                                  line.Angle - Math.Asin(dist / Radius),
                                  line.Project(p).Param
                                  ));

            p = Line.Create(nearPoint, line.Angle).Evaluate(-Math.Sqrt(RadiusSquared - dist * dist));
            intersections.Add(new Intersection(
                                  p,
                                  line.Angle + Math.Asin(dist / Radius) + Math.PI,
                                  line.Project(p).Param
                                  ));

            return(intersections);
        }