예제 #1
0
파일: C2DArc.cs 프로젝트: kasznare/DIP1
        /// <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));
        }
예제 #2
0
        /// <summary>
        /// Set to be the minimum bounding circle for the 2 points.
        /// </summary>
        /// <param name="Point1">The first point to include.</param> 
        /// <param name="Point2">The second point to include.</param> 
	    public void SetMinimum(C2DPoint Point1, C2DPoint Point2)
        {
	        C2DVector Vec = new C2DVector(Point1, Point2);
	        Vec.Multiply( 0.5);
	        Radius = Vec.GetLength();
	        _Centre.Set(Point1.GetPointTo(Vec));
        }
예제 #3
0
파일: C2DCircle.cs 프로젝트: kasznare/DIP1
        /// <summary>
        /// Set to be the minimum bounding circle for the 2 points.
        /// </summary>
        /// <param name="Point1">The first point to include.</param>
        /// <param name="Point2">The second point to include.</param>
        public void SetMinimum(C2DPoint Point1, C2DPoint Point2)
        {
            C2DVector Vec = new C2DVector(Point1, Point2);

            Vec.Multiply(0.5);
            Radius = Vec.GetLength();
            _Centre.Set(Point1.GetPointTo(Vec));
        }
예제 #4
0
파일: C2DPoint.cs 프로젝트: kasznare/DIP1
        /// <summary>
        /// Reflects this through the point given.
        /// </summary>
        /// <param name="Other">The point to reflect this through.</param>
        public override void Reflect(C2DPoint Other)
        {
            // Set up a vector from this to the other
            C2DVector vec = new C2DVector(this, Other);

            // Now use the vector to find the reflection by continuing along it from the point given.
            this.Set(Other.GetPointTo(vec));
        }
예제 #5
0
파일: C2DCircle.cs 프로젝트: kasznare/DIP1
        /// <summary>
        /// Distance to a circle, returns the closest point on both circles.
        /// </summary>
        /// <param name="Other">Circle to calculate the distance to.</param>
        /// <param name="ptOnThis">Closest point on this circle to recieve the result.</param>
        /// <param name="ptOnOther">Closest point on the other circle to recieve the result.</param>
        public double Distance(C2DCircle Other, C2DPoint ptOnThis, C2DPoint ptOnOther)
        {
            double dCenCenDist  = _Centre.Distance(Other.Centre);
            double dOtherRadius = Other.Radius;

            //    C2DPoint ptThis;
            //   C2DPoint ptOther;
            double dDist = dCenCenDist - Radius - dOtherRadius;

            if (dDist > 0)
            {
                // they do not interect and they are outside each other.
                C2DLine Line = new C2DLine(_Centre, Other.Centre);
                Line.vector.SetLength(Radius);
                ptOnThis.Set(Line.GetPointTo());

                Line.vector.Reverse();
                Line.SetPointFrom(Other.Centre);
                Line.vector.SetLength(Other.Radius);
                ptOnOther.Set(Line.GetPointTo());
            }
            else
            {
                if ((dCenCenDist + Radius) < dOtherRadius)
                {
                    // This is inside the other
                    dDist = dCenCenDist + Radius - dOtherRadius;            // -ve if inside
                    C2DVector vec = new C2DVector(Other.Centre, Centre);
                    vec.Multiply(Radius / dCenCenDist);                     // set the vector to be the length of my radius.
                    ptOnThis.Set(_Centre.GetPointTo(vec));
                    vec.Multiply(dDist / Radius);                           // set the vector to be the distance.
                    ptOnOther.Set(ptOnThis.GetPointTo(vec));
                }
                else if ((dCenCenDist + dOtherRadius) < Radius)
                {
                    // The other is inside this.
                    dDist = dCenCenDist + dOtherRadius - Radius;              // -ve if inside
                    C2DVector vec = new C2DVector(_Centre, Other.Centre);
                    vec.Multiply(dOtherRadius / dCenCenDist);                 // set the vector to be the length of my radius.
                    ptOnOther.Set(Other.Centre.GetPointTo(vec));
                    vec.Multiply(dDist / dOtherRadius);                       // set the vector to be the distance.
                    ptOnThis.Set(ptOnOther.GetPointTo(vec));
                }
                else
                {
                    // there is an intersection
                    dDist = 0;
                    List <C2DPoint> Ints = new List <C2DPoint>();
                    if (Crosses(Other, Ints))
                    {
                        ptOnThis.Set(Ints[0]);
                        ptOnOther.Set(ptOnThis);
                    }
                    else
                    {
                        Debug.Assert(false);
                        return(0);
                    }
                }
            }

            //      if (ptOnThis)
            //        *ptOnThis = ptThis;
            //      if (ptOnOther)
            //        *ptOnOther = ptOther;

            return(dDist);
        }
예제 #6
0
 /// <summary>
 /// Reflects this through the point given.
 /// </summary>
 /// <param name="Other">The point to reflect this through.</param>
 public override void Reflect(C2DPoint Other)
 {
     // Set up a vector from this to the other
     C2DVector vec = new C2DVector(this, Other);
     // Now use the vector to find the reflection by continuing along it from the point given.
     this.Set(  Other.GetPointTo(vec) );
 }
예제 #7
0
        /// <summary>
        /// Distance to a circle, returns the closest point on both circles.
        /// </summary>
        /// <param name="Other">Circle to calculate the distance to.</param> 
        /// <param name="ptOnThis">Closest point on this circle to recieve the result.</param> 
        /// <param name="ptOnOther">Closest point on the other circle to recieve the result.</param> 
        public double Distance(C2DCircle Other,  C2DPoint ptOnThis,  C2DPoint ptOnOther)
        {
            double dCenCenDist = _Centre.Distance(Other.Centre);
            double dOtherRadius = Other.Radius;

            //    C2DPoint ptThis;
             //   C2DPoint ptOther;
            double dDist = dCenCenDist - Radius - dOtherRadius;

            if (dDist > 0 )
            {
                // they do not interect and they are outside each other.
                    C2DLine Line = new C2DLine(_Centre, Other.Centre);
                    Line.vector.SetLength( Radius);
                    ptOnThis.Set( Line.GetPointTo() );

                    Line.vector.Reverse();
                    Line.SetPointFrom(Other.Centre);
                    Line.vector.SetLength(Other.Radius);
                    ptOnOther.Set(Line.GetPointTo());
            }
            else
            {
                if ( (dCenCenDist + Radius) < dOtherRadius)
                {
                    // This is inside the other
                    dDist =  dCenCenDist + Radius  - dOtherRadius ; // -ve if inside
                        C2DVector vec = new C2DVector( Other.Centre, Centre);
                        vec.Multiply(   Radius   /dCenCenDist  ); // set the vector to be the length of my radius.
                        ptOnThis.Set( _Centre.GetPointTo( vec));
                        vec.Multiply(   dDist   /Radius  ); // set the vector to be the distance.
                        ptOnOther.Set(ptOnThis.GetPointTo( vec));

                }
                else if ( (dCenCenDist + dOtherRadius) < Radius)
                {
                    // The other is inside this.
                    dDist = dCenCenDist + dOtherRadius -  Radius; // -ve if inside
                        C2DVector vec = new C2DVector( _Centre, Other.Centre);
                        vec.Multiply (   dOtherRadius   /dCenCenDist  ); // set the vector to be the length of my radius.
                        ptOnOther.Set( Other.Centre.GetPointTo( vec));
                        vec.Multiply(   dDist   /  dOtherRadius  ); // set the vector to be the distance.
                        ptOnThis.Set(ptOnOther.GetPointTo( vec));

                }
                else
                {
                    // there is an intersection
                    dDist = 0;
                    List<C2DPoint> Ints = new List<C2DPoint>();
                    if (Crosses(Other,  Ints))
                    {
                        ptOnThis.Set(Ints[0]);
                        ptOnOther.Set(ptOnThis);
                    }
                    else
                    {
                        Debug.Assert(false);
                        return 0;
                    }
                }
            }

              //      if (ptOnThis)
            //        *ptOnThis = ptThis;
              //      if (ptOnOther)
            //        *ptOnOther = ptOther;

            return dDist;
        }
예제 #8
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));
        }