Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
 public static Circle CreateFromRadiusSquared(Complex center, double radiusSquared)
 {
     return(new Circle(-center, center.ModulusSquared - radiusSquared));
 }
Ejemplo n.º 3
0
 public override CircLine Scale(Complex scale)
 {
     return(Create(Center * scale, Radius * scale.Modulus));
 }
Ejemplo n.º 4
0
 public override CircLine Translate(Complex translation)
 {
     return(CreateFromRadiusSquared(Center + translation, RadiusSquared));
 }
Ejemplo n.º 5
0
 public override Complex Evaluate(double t)
 {
     return(Center + Complex.CreatePolar(Radius, t));
 }
Ejemplo n.º 6
0
 public Circle(Complex b, double c)
     : base(1, b, c)
 {
     Debug.Assert(RadiusSquared > -Accuracy.LinearToleranceSquared);
 }