예제 #1
0
파일: C2DArc.cs 프로젝트: kasznare/DIP1
        /// <summary>
        /// Distance between this and the test point.
        /// </summary>
        /// <param name="TestPoint">The test point.</param>
        /// <param name="ptOnThis">The closest point on this to the given point as a returned value.</param>
        public override double Distance(C2DPoint TestPoint, C2DPoint ptOnThis)
        {
            C2DPoint  ptCen       = new C2DPoint(GetCircleCentre());
            C2DCircle Circle      = new C2DCircle(ptCen, Radius);
            C2DPoint  ptOnCircle  = new C2DPoint();
            double    dCircleDist = Circle.Distance(TestPoint, ptOnCircle);

            if (ArcOnRight ^ Line.IsOnRight(ptOnCircle))
            {
                // The closest point on the circle isn't on the curve
                double d1 = TestPoint.Distance(Line.point);
                double d2 = TestPoint.Distance(Line.GetPointTo());

                if (d1 < d2)
                {
                    ptOnThis.Set(Line.point);
                    return(d1);
                }
                else
                {
                    ptOnThis.Set(Line.GetPointTo());
                    return(d2);
                }
            }
            else
            {
                // The closest point on the circle IS on the curve
                ptOnThis.Set(ptOnCircle);
                return(Math.Abs(dCircleDist));
            }
        }
예제 #2
0
파일: C2DArc.cs 프로젝트: kasznare/DIP1
        /// <summary>
        /// Distance between this and another straight line.
        /// </summary>
        /// <param name="TestLine">The test line.</param>
        /// <param name="ptOnThis">The closest point on this to the other as a returned value.</param>
        /// <param name="ptOnOther">The closest point on the other to this as a returned value.</param>
        public double Distance(C2DLine TestLine, C2DPoint ptOnThis, C2DPoint ptOnOther)
        {
            C2DCircle Circle = new C2DCircle(GetCircleCentre(), Radius);

            double dCircDist = Circle.Distance(TestLine, ptOnThis, ptOnOther);
            double dDist     = 0;

            if (TestLine.IsOnRight(ptOnThis) ^ ArcOnRight)
            {
                // The point found isn't on this.
                // This means the 2 closest points cannot be ON both lines, we must have a end point as one.

                ptOnThis.Set(Line.point);
                dDist = TestLine.Distance(ptOnThis, ptOnOther);

                C2DPoint ptThisTemp  = new C2DPoint(Line.GetPointTo());
                C2DPoint ptOtherTemp = new C2DPoint();
                double   d2          = TestLine.Distance(ptThisTemp, ptOtherTemp);
                if (d2 < dDist)
                {
                    dDist = d2;
                    ptOnThis.Set(ptThisTemp);
                    ptOnOther.Set(ptOtherTemp);
                }
                // If the line was outside the circle then stop here as no need to go any further.
                // This is because the closest point on this must be one of the end points.
                if (dCircDist < 0)
                {
                    double d3 = Distance(TestLine.point, ptThisTemp);
                    if (d3 < dDist)
                    {
                        dDist = d3;
                        ptOnThis.Set(ptThisTemp);
                        ptOnOther.Set(Line.point);
                    }
                    double d4 = Distance(TestLine.GetPointTo(), ptThisTemp);
                    if (d4 < dDist)
                    {
                        dDist = d4;
                        ptOnThis.Set(ptThisTemp);
                        ptOnOther.Set(Line.GetPointTo());
                    }
                }
            }
            else
            {
                dDist = Math.Abs(dCircDist);
            }

            //    ptOnThis.Set(ptThis);
            //    ptOnOther.Set(ptOther);

            return(dDist);
        }
예제 #3
0
        /// <summary>
        /// Distance between this and another straight line.
        /// </summary>
        /// <param name="TestLine">The test line.</param>
        /// <param name="ptOnThis">The closest point on this to the other as a returned value.</param>
        /// <param name="ptOnOther">The closest point on the other to this as a returned value.</param>   
        public double Distance(C2DLine TestLine,  C2DPoint ptOnThis,  C2DPoint ptOnOther) 
        {
	        C2DCircle Circle = new C2DCircle( GetCircleCentre(), Radius);

            double dCircDist = Circle.Distance(TestLine,  ptOnThis,  ptOnOther);
	        double dDist = 0;

            if (TestLine.IsOnRight(ptOnThis) ^ ArcOnRight)
	        {
		        // The point found isn't on this. 
		        // This means the 2 closest points cannot be ON both lines, we must have a end point as one.

                ptOnThis.Set(Line.point);
                dDist = TestLine.Distance(ptOnThis,  ptOnOther);

                C2DPoint ptThisTemp = new C2DPoint(Line.GetPointTo());
		        C2DPoint ptOtherTemp = new C2DPoint();
                double d2 = TestLine.Distance(ptThisTemp,  ptOtherTemp);
		        if (d2 < dDist)
		        {
			        dDist = d2;
                    ptOnThis.Set(ptThisTemp);
                    ptOnOther.Set(ptOtherTemp);
		        }
		        // If the line was outside the circle then stop here as no need to go any further.
		        // This is because the closest point on this must be one of the end points.
		        if (dCircDist < 0)
		        {
                    double d3 = Distance(TestLine.point,  ptThisTemp);
			        if (d3 < dDist)
			        {
				        dDist = d3;
                        ptOnThis.Set(ptThisTemp);
                        ptOnOther.Set(Line.point);
			        }
                    double d4 = Distance(TestLine.GetPointTo(),  ptThisTemp);
			        if (d4 < dDist)
			        {
				        dDist = d4;
                        ptOnThis.Set(ptThisTemp);
                        ptOnOther.Set(Line.GetPointTo());
			        }	
		        }
	        }
	        else
	        {
		        dDist = Math.Abs(dCircDist);
	        }

		//    ptOnThis.Set(ptThis);
		//    ptOnOther.Set(ptOther);

	        return dDist;


        }
예제 #4
0
        /// <summary>
        /// Distance between this and the test point.
        /// </summary>
        /// <param name="TestPoint">The test point.</param>
        /// <param name="ptOnThis">The closest point on this to the given point as a returned value.</param>
        public override double Distance(C2DPoint TestPoint,  C2DPoint ptOnThis) 
        {
	        C2DPoint ptCen = new C2DPoint( GetCircleCentre());
	        C2DCircle Circle = new C2DCircle(ptCen, Radius);
	        C2DPoint ptOnCircle = new C2DPoint();
	        double dCircleDist = Circle.Distance(TestPoint,  ptOnCircle);

	        if (ArcOnRight ^ Line.IsOnRight(ptOnCircle))
	        {
		        // The closest point on the circle isn't on the curve
		        double d1 = TestPoint.Distance(Line.point);
		        double d2 = TestPoint.Distance(Line.GetPointTo());
        		
		        if (d1 < d2)
		        {
				    ptOnThis.Set(Line.point);
			        return d1;
		        }
		        else
		        {
			        ptOnThis.Set(Line.GetPointTo());
			        return d2;
		        }
	        }
	        else
	        {
		        // The closest point on the circle IS on the curve
		        ptOnThis.Set(ptOnCircle);
		        return Math.Abs(dCircleDist);
	        }


        }