Beispiel #1
0
 public bool Equals(LineF other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return((Equals(other.Start, Start) && Equals(other.End, End)) ||
            (Equals(other.End, Start) && Equals(other.Start, End)));
 }
Beispiel #2
0
        /// <summary>
        /// Gets the point that the line intersects with this plane.
        /// </summary>
        /// <param name="line">The line to intersect with</param>
        /// <param name="ignoreDirection">Set to true to ignore the direction
        /// of the plane and line when intersecting. Defaults to false.</param>
        /// <param name="ignoreSegment">Set to true to ignore the start and
        /// end points of the line in the intersection. Defaults to false.</param>
        /// <returns>The point of intersection, or null if the line does not intersect</returns>
        public CoordinateF GetIntersectionPoint(LineF line, bool ignoreDirection = false, bool ignoreSegment = false)
        {
            // http://softsurfer.com/Archive/algorithm_0104/algorithm_0104B.htm#Line%20Intersections
            // http://paulbourke.net/geometry/planeline/

            var dir         = line.End - line.Start;
            var denominator = -Normal.Dot(dir);
            var numerator   = Normal.Dot(line.Start - Normal * DistanceFromOrigin);

            if (Math.Abs(denominator) < 0.00001f || (!ignoreDirection && denominator < 0))
            {
                return(null);
            }
            var u = numerator / denominator;

            if (!ignoreSegment && (u < 0 || u > 1))
            {
                return(null);
            }
            return(line.Start + u * dir);
        }
Beispiel #3
0
        /* http://www.gamedev.net/community/forums/topic.asp?topic_id=338987 */
        /// <summary>
        /// Returns true if this box intersects the given line
        /// </summary>
        public bool IntersectsWith(LineF that)
        {
            var start  = that.Start;
            var finish = that.End;

            if (start.X < Start.X && finish.X < Start.X)
            {
                return(false);
            }
            if (start.X > End.X && finish.X > End.X)
            {
                return(false);
            }

            if (start.Y < Start.Y && finish.Y < Start.Y)
            {
                return(false);
            }
            if (start.Y > End.Y && finish.Y > End.Y)
            {
                return(false);
            }

            if (start.Z < Start.Z && finish.Z < Start.Z)
            {
                return(false);
            }
            if (start.Z > End.Z && finish.Z > End.Z)
            {
                return(false);
            }

            var d  = (finish - start) / 2;
            var e  = (End - Start) / 2;
            var c  = start + d - ((Start + End) / 2);
            var ad = d.Absolute();

            if (Math.Abs(c.X) > e.X + ad.X)
            {
                return(false);
            }
            if (Math.Abs(c.Y) > e.Y + ad.Y)
            {
                return(false);
            }
            if (Math.Abs(c.Z) > e.Z + ad.Z)
            {
                return(false);
            }

            var dca = d.Cross(c).Absolute();

            if (dca.X > e.Y * ad.Z + e.Z * ad.Y)
            {
                return(false);
            }
            if (dca.Y > e.Z * ad.X + e.X * ad.Z)
            {
                return(false);
            }
            if (dca.Z > e.X * ad.Y + e.Y * ad.X)
            {
                return(false);
            }

            return(true);
        }
Beispiel #4
0
 public bool EquivalentTo(LineF other, float delta = 0.0001f)
 {
     return((Start.EquivalentTo(other.Start, delta) && End.EquivalentTo(other.End, delta)) ||
            (End.EquivalentTo(other.Start, delta) && Start.EquivalentTo(other.End, delta)));
 }