Example #1
0
        /// <summary>
        /// Static version of InCentre function.
        /// </summary>
        public static C2DPoint GetInCentre(C2DPoint pt1, C2DPoint pt2, C2DPoint pt3)
        {
            // Set up a line to bisect the lines from 1 to 2 and 1 to 3
            var Line1 = new C2DLine(pt1, pt2);
            var Line2 = new C2DLine(pt1, pt3);

            Line1.SetLength(Line2.GetLength());
            var Line12Bisect = new C2DLine(pt1, pt3.GetMidPoint(Line1.GetPointTo()));

            // Set up a line to bisect the lines from 2 to 1 and 2 to 3
            var Line3 = new C2DLine(pt2, pt1);
            var Line4 = new C2DLine(pt2, pt3);

            Line3.SetLength(Line4.GetLength());
            var Line34Bisect = new C2DLine(pt2, pt3.GetMidPoint(Line3.GetPointTo()));

            // Now intersect the 2 lines and find the point.
            var Int = new List <C2DPoint>();

            // Add the intersection even if there isn't one (i.e. infinite lines)
            bool B1 = true, B2 = true;

            Line12Bisect.Crosses(Line34Bisect, Int, ref B1, ref B2, true);

            Debug.Assert(Int.Count == 1);

            return(Int[0]);
        }
Example #2
0
        /// <summary>
        /// Gets the point half way along the curve as a new object.
        /// </summary>
        public C2DPoint GetMidPoint()
        {
            Debug.Assert(IsValid(), "Invalid arc defined, cannot calculate midpoint");
            // Make a line from the circle centre to the middle of the line
            C2DPoint ptCentre = new C2DPoint(GetCircleCentre());

            C2DPoint ptLineCentre = new C2DPoint(Line.GetMidPoint());

            C2DLine CenToMid = new C2DLine(ptCentre, ptLineCentre);

            if (CenToMid.vector.i == 0 && CenToMid.vector.j == 0)
            {
                // The centre of the line is the same as the centre of the circle
                // i.e. this arc is 180 degrees or half a circle.
                CenToMid.Set(Line);
                CenToMid.SetPointFrom(ptLineCentre);
                if (ArcOnRight)
                {
                    CenToMid.vector.TurnRight();
                }
                else
                {
                    CenToMid.vector.TurnLeft();
                }
            }
            else
            {
                // extend it to the edge of the arc
                CenToMid.SetLength(Radius);
                // if the arc on the opposite side to the centre then reverse the line.
                if (ArcOnRight == CentreOnRight)
                {
                    CenToMid.vector.Reverse();
                }
            }

            return(CenToMid.GetPointTo());
        }
Example #3
0
        /// <summary>
        /// Static version of InCentre function.
        /// </summary>
        public static C2DPoint GetInCentre(C2DPoint pt1, C2DPoint pt2, C2DPoint pt3)
        {
	        // Set up a line to bisect the lines from 1 to 2 and 1 to 3
	        C2DLine Line1 = new C2DLine(pt1, pt2);
	        C2DLine Line2 = new C2DLine(pt1, pt3);
	        Line1.SetLength( Line2.GetLength() );
	        C2DLine Line12Bisect = new C2DLine(  pt1, pt3.GetMidPoint( Line1.GetPointTo()));

	        // Set up a line to bisect the lines from 2 to 1 and 2 to 3
	        C2DLine Line3 = new C2DLine(pt2, pt1);
	        C2DLine Line4 = new C2DLine(pt2, pt3);
	        Line3.SetLength( Line4.GetLength() );
            C2DLine Line34Bisect = new C2DLine(pt2, pt3.GetMidPoint(Line3.GetPointTo()));

	        // Now intersect the 2 lines and find the point.
	        List<C2DPoint> Int = new List<C2DPoint>();

	        // Add the intersection even if there isn't one (i.e. infinite lines)
            bool B1 = true, B2 = true;
	        Line12Bisect.Crosses(Line34Bisect,  Int, ref B1, ref B2, true);

	        Debug.Assert (Int.Count == 1);

	        return Int[0];
        }
Example #4
0
        /// <summary>
        /// Gets the point half way along the curve as a new object.
        /// </summary>
        public C2DPoint GetMidPoint() 
        {
	        Debug.Assert(IsValid(), "Invalid arc defined, cannot calculate midpoint");
	        // Make a line from the circle centre to the middle of the line
	        C2DPoint ptCentre = new C2DPoint(GetCircleCentre());

	        C2DPoint ptLineCentre = new C2DPoint(Line.GetMidPoint());

	        C2DLine CenToMid = new C2DLine(ptCentre, ptLineCentre);

	        if ( CenToMid.vector.i == 0 && CenToMid.vector.j == 0)
	        {
		        // The centre of the line is the same as the centre of the circle
		        // i.e. this arc is 180 degrees or half a circle.
		        CenToMid.Set(Line);
		        CenToMid.SetPointFrom( ptLineCentre );
		        if ( ArcOnRight )
			        CenToMid.vector.TurnRight();
		        else
			        CenToMid.vector.TurnLeft();
	        }
	        else
	        {
		        // extend it to the edge of the arc
		        CenToMid.SetLength( Radius );
		        // if the arc on the opposite side to the centre then reverse the line.
		        if ( ArcOnRight == CentreOnRight)
		        {
			        CenToMid.vector.Reverse();
		        }
	        }

	        return CenToMid.GetPointTo();

        }