コード例 #1
0
        /// <summary>
        /// Intersection test.
        /// </summary>
        /// <remarks>Test does not handle parallel lines.</remarks>
        /// <param name="one">The first line segment.</param>
        /// <param name="other">The second line segment.</param>
        /// <param name="t1">The interpolation for first line segment, only if intersects is true.</param>
        /// <param name="t2">The interpolation for second line segment, only if intersects is true.</param>
        /// <returns>Do lines intersect.</returns>
        public static bool Intersect(LineSegment2d one, LineSegment2d other,
                                     out double t1, out double t2)
        {
            t1 = t2 = 0.0;

            // We solve 2x2 system and then check if it is ok for the third argument.
            Vector2d r = LinearSolver.SolveSystem(
                new Matrix2x2d(one.Direction.X, -other.Direction.X,
                               one.Direction.Y, -other.Direction.Y),
                new Vector2d(other.A.X - one.A.X, other.A.Y - one.A.Y));

            // If system has the solution, it must be in range [0,1].
            if (r.X < 0.0 || r.X > 0.0)
            {
                return(false);
            }
            if (r.Y < 0.0 || r.Y > 0.0)
            {
                return(false);
            }

            // We check if the last line satisfies.
            if (!Vector2d.NearEqual(one.Sample(r.X), other.Sample(r.Y)))
            {
                return(false);
            }

            // We copy interpolation.
            t1 = r.X;
            t2 = r.Y;
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Intersection test.
        /// </summary>
        /// <remarks>Test does not handle parallel lines.</remarks>
        /// <param name="one">The first line segment.</param>
        /// <param name="other">The second line segment.</param>
        /// <param name="result">The resulting intersection point, only if it returns true.</param>
        /// <returns>Do lines intersect.</returns>
        public static bool Intersect(LineSegment2d one, LineSegment2d other, out Vector2d result)
        {
            double t1, t2;

            if (!Intersect(one, other, out t1, out t2))
            {
                result = Vector2d.Zero;
                return(false);
            }
            else
            {
                result = one.Sample(t1);
                return(true);
            }
        }
コード例 #3
0
        //#foreach instanced to '2Dd'


        /// <summary>
        /// Pure intersection test.
        /// </summary>
        /// <remarks>Test does not handle parallel lines.</remarks>
        /// <param name="one">The first line segment.</param>
        /// <param name="other">The second line segment.</param>
        /// <returns>Do lines intersect.</returns>
        public static bool Intersect(LineSegment2d one, LineSegment2d other)
        {
            double t1, t2;

            return(Intersect(one, other, out t1, out t2));
        }