コード例 #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
ファイル: C2DCircle.cs プロジェクト: micrak/rakomeister-attic
        /// <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
ファイル: C2DArc.cs プロジェクト: micrak/rakomeister-attic
        /// <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));
        }