Пример #1
0
        /// <summary>
        /// 线和BOX相交
        /// </summary>
        /// <param name="line"></param>
        /// <param name="box"></param>
        /// <returns></returns>
        public static Segment2?IntersectionWith(this Line2 line, Box2 box)
        {
            IntersectionLine2Box2 intersectionLine2Box = new IntersectionLine2Box2(line, box);
            bool flag = intersectionLine2Box.Find();

            if (flag && intersectionLine2Box.IntersectionType == Intersection.Type.IT_SEGMENT)
            {
                return(new Segment2?(new Segment2(intersectionLine2Box.Point0, intersectionLine2Box.Point1)));
            }
            if (flag && intersectionLine2Box.IntersectionType == Intersection.Type.IT_POINT)
            {
                return(new Segment2?(new Segment2(intersectionLine2Box.Point0, line.Direction, 0.0)));
            }
            return(null);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="line"></param>
        /// <param name="axisAlignedBox"></param>
        /// <returns></returns>
        public static Segment2?IntersectionWith(this Line2 line, AxisAlignedBox2 axisAlignedBox)
        {
            Box2 box = new Box2(axisAlignedBox.Center, UnitVector2.UnitX, UnitVector2.UnitY, axisAlignedBox.ExtentX, axisAlignedBox.ExtentY);
            IntersectionLine2Box2 intersectionLine2Box = new IntersectionLine2Box2(line, box);
            bool flag = intersectionLine2Box.Find();

            if (flag && intersectionLine2Box.IntersectionType == Intersection.Type.IT_SEGMENT)
            {
                return(new Segment2?(new Segment2(intersectionLine2Box.Point0, intersectionLine2Box.Point1)));
            }
            if (flag && intersectionLine2Box.IntersectionType == Intersection.Type.IT_POINT)
            {
                return(new Segment2?(new Segment2(intersectionLine2Box.Point0, line.Direction, 0.0)));
            }
            return(null);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="line"></param>
        /// <param name="box"></param>
        /// <returns></returns>
        public static ICollection <Vector2> IntersectionPointsWith(this Line2 line, Box2 box)
        {
            IntersectionLine2Box2 intersectionLine2Box = new IntersectionLine2Box2(line, box);

            intersectionLine2Box.Find();
            List <Vector2> list = new List <Vector2>();

            Vector2[] array = new Vector2[]
            {
                intersectionLine2Box.Point0,
                intersectionLine2Box.Point1
            };
            for (int i = 0; i < intersectionLine2Box.Quantity; i++)
            {
                list.Add(array[i]);
            }
            return(list);
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="line"></param>
        /// <param name="axisAlignedBox"></param>
        /// <returns></returns>
        public static ICollection <Vector2> IntersectionPointsWith(this Line2 line, AxisAlignedBox2 axisAlignedBox)
        {
            Box2 box = new Box2(axisAlignedBox.Center, UnitVector2.UnitX, UnitVector2.UnitY, axisAlignedBox.ExtentX, axisAlignedBox.ExtentY);
            IntersectionLine2Box2 intersectionLine2Box = new IntersectionLine2Box2(line, box);

            intersectionLine2Box.Find();
            List <Vector2> list = new List <Vector2>();

            Vector2[] array = new Vector2[]
            {
                intersectionLine2Box.Point0,
                intersectionLine2Box.Point1
            };
            for (int i = 0; i < intersectionLine2Box.Quantity; i++)
            {
                list.Add(array[i]);
            }
            return(list);
        }