Ejemplo n.º 1
0
        /// <summary>
        /// Returns the corresponding circle's centre.
        /// </summary>
        public C2DPoint GetCircleCentre()
        {
            if (!IsValid())
            {
                return(new C2DPoint(0, 0));
            }

            C2DPoint MidPoint    = new C2DPoint(Line.GetMidPoint());
            double   dMinToStart = MidPoint.Distance(Line.point);

            double dMidToCentre = Math.Sqrt(Radius * Radius - dMinToStart * dMinToStart);

            C2DVector MidToCentre = new C2DVector(Line.vector);

            if (CentreOnRight)
            {
                MidToCentre.TurnRight();
            }
            else
            {
                MidToCentre.TurnLeft();
            }

            MidToCentre.SetLength(dMidToCentre);

            return(MidPoint.GetPointTo(MidToCentre));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// True if this crosses the other and returns the intersectin points.
        /// </summary>
        /// <param name="Other">The other circle.</param>
        /// <param name="IntersectionPts">The point set to recieve the result.</param>
        public bool Crosses(C2DCircle Other, List <C2DPoint> IntersectionPts)
        {
            double x1 = _Centre.x;
            double y1 = _Centre.y;
            double R1 = Radius;

            double x2 = Other.Centre.x;
            double y2 = Other.Centre.y;
            double R2 = Other.Radius;

            double D = Other.Centre.Distance(_Centre);

            if (D == 0)
            {
                return(false);
            }

            if (D == (R1 + R2))
            {
                C2DVector V = new C2DVector(_Centre, Other.Centre);
                V.SetLength(R1);
                C2DPoint P = new C2DPoint(_Centre.GetPointTo(V));
                IntersectionPts.Add(P);

                return(true);
            }

            if (D > (R1 + R2) || D < Math.Abs(R1 - R2))
            {
                return(false);
            }

            double A = (D + R1 + R2) * (D + R1 - R2) * (D - R1 + R2) * (-D + R1 + R2);

            A = Math.Sqrt(A) / 4;

            double XE1 = (x1 + x2) / 2 - (x1 - x2) * (R1 * R1 - R2 * R2) / (2 * D * D);
            double XE2 = 2 * (y1 - y2) * A / (D * D);

            double YE1 = (y1 + y2) / 2 - (y1 - y2) * (R1 * R1 - R2 * R2) / (2 * D * D);
            double YE2 = 2 * (x1 - x2) * A / (D * D);

            C2DPoint pt1 = new C2DPoint(XE1 + XE2, YE1 - YE2);
            C2DPoint pt2 = new C2DPoint(XE1 - XE2, YE1 + YE2);

            IntersectionPts.Add(pt1);
            IntersectionPts.Add(pt2);


            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// True if this crosses the other and returns the intersectin points.
        /// </summary>
        /// <param name="Other">The other circle.</param> 
        /// <param name="IntersectionPts">The point set to recieve the result.</param> 
        public bool Crosses(C2DCircle Other,  List<C2DPoint> IntersectionPts)
        {
            double x1 = _Centre.x;
            double y1 = _Centre.y;
            double R1 = Radius;

            double x2 = Other.Centre.x;
            double y2 = Other.Centre.y;
            double R2 = Other.Radius;

            double D = Other.Centre.Distance(_Centre);

            if (D == 0)
                return false;

            if (D == (R1 + R2) )
            {
                C2DVector V = new C2DVector(_Centre, Other.Centre);
                V.SetLength(R1);
                C2DPoint P = new C2DPoint(_Centre.GetPointTo( V ));
                IntersectionPts.Add(P);

                return true;
            }

            if ( D > (R1 + R2) || D < Math.Abs(R1 - R2))
                return false;

            double A = (D + R1 + R2) * (D + R1 - R2) * (D - R1 + R2) * (-D + R1 + R2);
            A = Math.Sqrt(A) / 4;

            double XE1 = (x1 + x2) / 2 - (x1 - x2) * (R1 * R1 - R2 * R2) / (2 * D * D);
            double XE2 = 2 * (y1 - y2) * A / (D * D);

            double YE1 = (y1 + y2) / 2 - (y1 - y2) * (R1 * R1 - R2 * R2) / (2 * D * D);
            double YE2 = 2 * (x1 - x2) * A / (D * D);

            C2DPoint pt1 = new C2DPoint( XE1 + XE2, YE1 - YE2);
            C2DPoint pt2 = new C2DPoint( XE1 - XE2, YE1 + YE2);

            IntersectionPts.Add(pt1);
            IntersectionPts.Add(pt2);

            return true;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns the corresponding circle's centre.
        /// </summary>
        public C2DPoint GetCircleCentre() 
        {
	        if (!IsValid() ) 
		        return new C2DPoint(0, 0);

	        C2DPoint MidPoint = new C2DPoint(Line.GetMidPoint());
	        double dMinToStart = MidPoint.Distance( Line.point);

	        double dMidToCentre = Math.Sqrt( Radius * Radius - dMinToStart * dMinToStart);

	        C2DVector MidToCentre = new C2DVector(Line.vector);
	        if ( CentreOnRight) 
                MidToCentre.TurnRight();
	        else 
                MidToCentre.TurnLeft();

	        MidToCentre.SetLength(dMidToCentre);

	        return (MidPoint.GetPointTo(MidToCentre));
        }