Beispiel #1
0
        //-----------------------------------------------------------------------------

        /// <summary>
        /// Check whether a line intersect a rectangle or not.
        /// </summary>
        /// <param name="p1">TcPoint 1 of Line 1</param>
        /// <param name="p2">TcPoint 2 of Line 1</param>
        /// <param name="r">Rectangle</param>
        /// <returns>True if intersects and False otherwise</returns>
        static public Boolean LineIntersectRectangle(TcPoint p1, TcPoint p2, TcRectangle r)
        {
            return(LineIntersectsLine(p1, p2, new TcPoint(r.UpperLeftX, r.LowerRightY), new TcPoint(r.LowerRightX, r.LowerRightY)) ||
                   LineIntersectsLine(p1, p2, new TcPoint(r.LowerRightX, r.LowerRightY), new TcPoint(r.LowerRightX, r.UpperLeftY)) ||
                   LineIntersectsLine(p1, p2, new TcPoint(r.LowerRightX, r.UpperLeftY), new TcPoint(r.UpperLeftX, r.UpperLeftY)) ||
                   LineIntersectsLine(p1, p2, new TcPoint(r.UpperLeftX, r.UpperLeftY), new TcPoint(r.UpperLeftX, r.LowerRightY)) ||
                   (r.Contains(p1) && r.Contains(p2)));
        }
Beispiel #2
0
        //-----------------------------------------------------------------------------

        /// <summary>
        /// Check whether two lines intersect or not.
        /// </summary>
        /// <param name="l1p1">TcPoint 1 of Line 1</param>
        /// <param name="l1p2">TcPoint 2 of Line 1</param>
        /// <param name="l2p1">TcPoint 1 of Line 2</param>
        /// <param name="l2p2">TcPoint 2 of Line 2</param>
        /// <returns>True if intersects and False otherwise</returns>
        static private Boolean LineIntersectsLine(TcPoint l1p1, TcPoint l1p2, TcPoint l2p1, TcPoint l2p2)
        {
            Double q = (l1p1.Y - l2p1.Y) * (l2p2.X - l2p1.X) - (l1p1.X - l2p1.X) * (l2p2.Y - l2p1.Y);
            Double d = (l1p2.X - l1p1.X) * (l2p2.Y - l2p1.Y) - (l1p2.Y - l1p1.Y) * (l2p2.X - l2p1.X);

            if (d == 0)
            {
                return(false);
            }

            Double r = q / d;

            q = (l1p1.Y - l2p1.Y) * (l1p2.X - l1p1.X) - (l1p1.X - l2p1.X) * (l1p2.Y - l1p1.Y);
            Double s = q / d;

            if (r < 0 || r > 1 || s < 0 || s > 1)
            {
                return(false);
            }

            return(true);
        }
Beispiel #3
0
 public TcTileGrid(TcPoint prmUpperLeft, TcPoint prmLowerRight)
     : base(prmUpperLeft, prmLowerRight)
 {
 }
Beispiel #4
0
        //-----------------------------------------------------------------------------

        /// <summary>
        /// Calculates the angle between two points on a 2D plane.
        /// </summary>
        /// <param name="pt1">Point 1</param>
        /// <param name="pt2">Point 2</param>
        /// <returns>Angle between two points</returns>
        static public Double PointAngle(TcPoint pt1, TcPoint pt2)
        {
            return(PointAngle(pt1.X, pt1.Y, pt2.X, pt2.Y));
        }