예제 #1
0
파일: C2DArc.cs 프로젝트: kasznare/DIP1
        /// <summary>
        /// True if this crosses the straight line.
        /// </summary>
        /// <param name="TestLine">The other line.</param>
        /// <param name="IntersectionPts">The interection point list to recieve the result.</param>
        public bool Crosses(C2DLine TestLine, List <C2DPoint> IntersectionPts)
        {
            List <C2DPoint> IntPtsTemp = new List <C2DPoint>();
            C2DCircle       TestCircle = new C2DCircle(GetCircleCentre(), Radius);

            if (TestCircle.Crosses(TestLine, IntPtsTemp))
            {
                for (int i = IntPtsTemp.Count - 1; i >= 0; i--)
                {
                    if (Line.IsOnRight(IntPtsTemp[i]) ^ ArcOnRight ||
                        IntPtsTemp[i].PointEqualTo(Line.point) ||
                        IntPtsTemp[i].PointEqualTo(Line.GetPointTo()))
                    {
                        IntPtsTemp.RemoveAt(i);
                    }
                }

                if (IntPtsTemp.Count == 0)
                {
                    return(false);
                }
                else
                {
                    IntersectionPts.InsertRange(0, IntPtsTemp);
                    //    .( IntersectionPts );
                    //      IntersectionPts << IntPtsTemp;
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
파일: C2DArc.cs 프로젝트: kasznare/DIP1
        /// <summary>
        /// True if this crosses a curved line.
        /// </summary>
        /// <param name="Other">The other arc.</param>
        /// <param name="IntersectionPts">The interection point list to recieve the result.</param>
        public bool Crosses(C2DArc Other, List <C2DPoint> IntersectionPts)
        {
            C2DCircle TestCircleThis  = new C2DCircle(GetCircleCentre(), Radius);
            C2DCircle TestCircleOther = new C2DCircle(Other.GetCircleCentre(), Other.Radius);

            List <C2DPoint> IntPtsTemp = new List <C2DPoint>();

            if (TestCircleThis.Crosses(TestCircleOther, IntPtsTemp))
            {
                for (int i = IntPtsTemp.Count - 1; i >= 0; i--)
                {
                    if ((Line.IsOnRight(IntPtsTemp[i]) ^ ArcOnRight) ||
                        Other.Line.IsOnRight(IntPtsTemp[i]) ^ Other.ArcOnRight ||
                        IntPtsTemp[i].PointEqualTo(Line.point) ||
                        IntPtsTemp[i].PointEqualTo(Line.GetPointTo()) ||
                        IntPtsTemp[i].PointEqualTo(Other.GetPointFrom()) ||
                        IntPtsTemp[i].PointEqualTo(Other.GetPointTo()))
                    {
                        IntPtsTemp.RemoveAt(i);
                    }
                }

                if (IntPtsTemp.Count == 0)
                {
                    return(false);
                }
                else
                {
                    IntersectionPts.InsertRange(0, IntPtsTemp);
                    //    IntPtsTemp.CopyTo( IntersectionPts );

                    //        (*IntersectionPts) << IntPtsTemp;
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
파일: C2DArc.cs 프로젝트: kasznare/DIP1
        /// <summary>
        /// The distance between this and another arc.
        /// </summary>
        /// <param name="Other">The test point.</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(C2DArc Other, C2DPoint ptOnThis, C2DPoint ptOnOther)
        {
            List <C2DPoint> IntPts1 = new List <C2DPoint>();
            List <C2DPoint> IntPts2 = new List <C2DPoint>();

            C2DPoint ptThisCen  = new C2DPoint(GetCircleCentre());
            C2DPoint ptOtherCen = new C2DPoint(Other.GetCircleCentre());

            C2DCircle CircleThis  = new C2DCircle(ptThisCen, Radius);
            C2DCircle CircleOther = new C2DCircle(ptOtherCen, Other.Radius);

            if (CircleThis.Crosses(CircleOther, IntPts1))
            {
                for (int i = 0; i < IntPts1.Count; i++)
                {
                    if ((Line.IsOnRight(IntPts1[i]) == ArcOnRight) &&
                        (Other.Line.IsOnRight(IntPts1[i]) == Other.ArcOnRight))
                    {
                        ptOnThis.Set(IntPts1[i]);
                        ptOnOther.Set(IntPts1[i]);
                        return(0);
                    }
                }

                IntPts1.Clear();
            }


            C2DLine LineCenToOther = new C2DLine();

            LineCenToOther.point  = new C2DPoint(ptThisCen);
            LineCenToOther.vector = new C2DVector(ptThisCen, ptOtherCen);
            LineCenToOther.GrowFromCentre(Math.Max(Radius, Other.Radius) * 10);

            double dMinDist = 1.7E308;
            double dDist    = 0;

            if (Crosses(LineCenToOther, IntPts1) && Other.Crosses(LineCenToOther, IntPts2))
            {
                for (int i = 0; i < IntPts1.Count; i++)
                {
                    for (int j = 0; j < IntPts2.Count; j++)
                    {
                        dDist = IntPts1[i].Distance(IntPts2[j]);
                        if (dDist < dMinDist)
                        {
                            ptOnThis.Set(IntPts1[i]);
                            ptOnOther.Set(IntPts2[j]);

                            dMinDist = dDist;
                        }
                    }
                }
            }

            C2DPoint ptOnThisTemp = new C2DPoint();

            dDist = Distance(Other.GetPointFrom(), ptOnThisTemp);
            if (dDist < dMinDist)
            {
                ptOnThis.Set(ptOnThisTemp);
                ptOnOther.Set(Other.GetPointFrom());

                dMinDist = dDist;
            }

            dDist = Distance(Other.GetPointTo(), ptOnThisTemp);
            if (dDist < dMinDist)
            {
                ptOnThis.Set(ptOnThisTemp);
                ptOnOther.Set(Other.GetPointTo());

                dMinDist = dDist;
            }

            C2DPoint ptOnOtherTemp = new C2DPoint();

            dDist = Other.Distance(GetPointFrom(), ptOnOtherTemp);
            if (dDist < dMinDist)
            {
                ptOnThis.Set(GetPointFrom());
                ptOnOther.Set(ptOnOtherTemp);
                dMinDist = dDist;
            }

            dDist = Other.Distance(GetPointTo(), ptOnOtherTemp);
            if (dDist < dMinDist)
            {
                ptOnThis.Set(GetPointTo());
                ptOnOther.Set(ptOnOtherTemp);
                dMinDist = dDist;
            }

            return(dMinDist);
        }
예제 #4
0
        /// <summary>
        /// The distance between this and another arc.
        /// </summary>
        /// <param name="Other">The test point.</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(C2DArc Other,  C2DPoint ptOnThis,  C2DPoint ptOnOther)
        {
	        List<C2DPoint> IntPts1 = new List<C2DPoint>();
	        List<C2DPoint> IntPts2 = new List<C2DPoint>();

	        C2DPoint ptThisCen = new C2DPoint( GetCircleCentre() );
	        C2DPoint ptOtherCen = new C2DPoint(Other.GetCircleCentre());

	        C2DCircle CircleThis = new C2DCircle( ptThisCen, Radius);
	        C2DCircle CircleOther = new C2DCircle( ptOtherCen, Other.Radius );

	        if (CircleThis.Crosses(  CircleOther ,  IntPts1 ) )
	        {
		        for (int i = 0; i < IntPts1.Count; i++)
		        {
			        if (  (Line.IsOnRight( IntPts1[i] ) == ArcOnRight ) &&
				          (Other.Line.IsOnRight( IntPts1[i] ) == Other.ArcOnRight )     )
			        {
					    ptOnThis.Set(IntPts1[i]);
					    ptOnOther.Set(IntPts1[i]);
				        return 0;
			        }
		        }

		        IntPts1.Clear();
	        }


	        C2DLine LineCenToOther = new C2DLine();
	        LineCenToOther.point = new C2DPoint(ptThisCen);
	        LineCenToOther.vector = new C2DVector(ptThisCen, ptOtherCen);
	        LineCenToOther.GrowFromCentre( Math.Max(Radius, Other.Radius) * 10);

	        double dMinDist = 1.7E308;
	        double dDist = 0;

	        if ( Crosses(LineCenToOther,  IntPts1) && Other.Crosses(LineCenToOther,  IntPts2))
	        {
		        for (int i = 0 ; i < IntPts1.Count; i++)
		        {
			        for (int j = 0 ; j < IntPts2.Count; j++)
			        {
				        dDist = IntPts1[i].Distance(IntPts2[j]);
				        if (dDist < dMinDist)
				        {
						    ptOnThis.Set( IntPts1[i]);
						    ptOnOther.Set( IntPts2[j]);

					        dMinDist = dDist;
				        }
			        }
		        }
	        }

	        C2DPoint ptOnThisTemp = new C2DPoint();
	        dDist = Distance(Other.GetPointFrom(),  ptOnThisTemp);
	        if (dDist < dMinDist)
	        {
			    ptOnThis.Set(ptOnThisTemp);
			    ptOnOther.Set(Other.GetPointFrom());

		        dMinDist = dDist;
	        }

	        dDist = Distance(Other.GetPointTo(),  ptOnThisTemp);
	        if (dDist < dMinDist)
	        {
			    ptOnThis.Set(ptOnThisTemp);
			    ptOnOther.Set(Other.GetPointTo());

		        dMinDist = dDist;
	        }

	        C2DPoint ptOnOtherTemp = new C2DPoint();
	        dDist = Other.Distance(GetPointFrom(),  ptOnOtherTemp);
	        if (dDist < dMinDist)
	        {
			    ptOnThis.Set( GetPointFrom());
			    ptOnOther.Set( ptOnOtherTemp);
		        dMinDist = dDist;
	        }

	        dDist = Other.Distance(GetPointTo(),  ptOnOtherTemp);
	        if (dDist < dMinDist)
	        {
			    ptOnThis.Set( GetPointTo());
			    ptOnOther.Set( ptOnOtherTemp);
		        dMinDist = dDist;
	        }

	        return dMinDist;

        }
예제 #5
0
        /// <summary>
        /// True if this crosses a curved line.
        /// </summary>
        /// <param name="Other">The other arc.</param>
        /// <param name="IntersectionPts">The interection point list to recieve the result.</param>
        public bool Crosses(C2DArc Other,   List<C2DPoint> IntersectionPts) 
        {
	        C2DCircle TestCircleThis = new C2DCircle (GetCircleCentre(), Radius);
	        C2DCircle TestCircleOther= new C2DCircle (Other.GetCircleCentre(), Other.Radius);

	        List<C2DPoint> IntPtsTemp = new List<C2DPoint>();

	        if (TestCircleThis.Crosses(TestCircleOther,  IntPtsTemp))
	        {

		        for (int i = IntPtsTemp.Count - 1; i >= 0 ; i--)
		        {
			        if ((Line.IsOnRight(IntPtsTemp[i]) ^ ArcOnRight) ||
				        Other.Line.IsOnRight(IntPtsTemp[i]) ^ Other.ArcOnRight ||
				        IntPtsTemp[i].PointEqualTo( Line.point) ||
				        IntPtsTemp[i].PointEqualTo( Line.GetPointTo()) ||
				        IntPtsTemp[i].PointEqualTo( Other.GetPointFrom()) ||
				        IntPtsTemp[i].PointEqualTo( Other.GetPointTo()))
			        {
				        IntPtsTemp.RemoveAt(i);
			        }
		        }

		        if (IntPtsTemp.Count == 0)
			        return false;
		        else
		        {

                    IntersectionPts.InsertRange(0, IntPtsTemp);
                //    IntPtsTemp.CopyTo( IntersectionPts );

				//        (*IntersectionPts) << IntPtsTemp;
			        return true;
		        }
	        }
	        else
	        {
		        return false;
	        }


        }
예제 #6
0
        /// <summary>
        /// True if this crosses the straight line.
        /// </summary>
        /// <param name="TestLine">The other line.</param>
        /// <param name="IntersectionPts">The interection point list to recieve the result.</param>
        public bool Crosses(C2DLine TestLine,  List<C2DPoint> IntersectionPts)
        {
	        List<C2DPoint> IntPtsTemp = new List<C2DPoint>();
	        C2DCircle TestCircle = new C2DCircle(GetCircleCentre(), Radius);
            if (TestCircle.Crosses(TestLine,  IntPtsTemp))
	        {
		        for (int i = IntPtsTemp.Count - 1 ; i >= 0  ; i--)
		        {
                    if (Line.IsOnRight(IntPtsTemp[i]) ^ ArcOnRight ||
                        IntPtsTemp[i].PointEqualTo( Line.point) ||
                        IntPtsTemp[i].PointEqualTo( Line.GetPointTo()))
			        {
				        IntPtsTemp.RemoveAt(i);
			        }

		        }

		        if (IntPtsTemp.Count == 0)
			        return false;
		        else
		        {
                    IntersectionPts.InsertRange(0,  IntPtsTemp);
                //    .( IntersectionPts );
			  //      IntersectionPts << IntPtsTemp;
			        return true;
		        }
	        }
	        else
	        {
		        return false;
	        }

        }