Esempio n. 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(LineSegment2f one, LineSegment2f other,
                                     out float t1, out float t2)
        {
            t1 = t2 = 0.0f;

            // We solve 2x2 system and then check if it is ok for the third argument.
            Vector2f r = LinearSolver.SolveSystem(
                new Matrix2x2f(one.Direction.X, -other.Direction.X,
                               one.Direction.Y, -other.Direction.Y),
                new Vector2f(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.0f || r.X > 0.0f)
            {
                return(false);
            }
            if (r.Y < 0.0f || r.Y > 0.0f)
            {
                return(false);
            }

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

            // We copy interpolation.
            t1 = r.X;
            t2 = r.Y;
            return(true);
        }
Esempio n. 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(LineSegment2f one, LineSegment2f other, out Vector2f result)
        {
            float t1, t2;

            if (!Intersect(one, other, out t1, out t2))
            {
                result = Vector2f.Zero;
                return(false);
            }
            else
            {
                result = one.Sample(t1);
                return(true);
            }
        }
Esempio n. 3
0
        //#endfor instanced to '2Dd'

        //#foreach instanced to '2Df'


        /// <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(LineSegment2f one, LineSegment2f other)
        {
            float t1, t2;

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