コード例 #1
0
        /// <summary>
        /// Returns a parameter at the intersection point with another line if found. This function takes the length of this line if it is available for performance optimization.
        /// </summary>
        /// <param name="line">The line.</param>
        /// <param name="length">The length of this line.</param>
        /// <param name="tolerance">The tolerance.</param>
        /// <returns>System.Nullable&lt;System.Double&gt;.</returns>
        public double?Intersection(UVLine line, double length, double tolerance = .000001f)
        {
            UV     lineVector = this.End - this.Start;
            double area1      = lineVector.CrossProductValue(line.Start - this.Start);
            double area2      = lineVector.CrossProductValue(line.End - this.Start);

            if (area1 * area2 > tolerance)
            {
                lineVector = null;
                return(null);
            }
            lineVector = line.End - line.Start;
            area1      = lineVector.CrossProductValue(this.Start - line.Start);
            area2      = lineVector.CrossProductValue(this.End - line.Start);
            if (area1 * area2 > tolerance)
            {
                lineVector = null;
                return(null);
            }
            double a1 = (line.Start - this.Start).CrossProductValue(line.End - this.Start);

            if (a1 == 0)
            {
                return(Math.Min(line.Start.DistanceTo(this.Start), line.End.DistanceTo(this.Start)));
            }
            lineVector = null;
            double u = length * Math.Abs(a1) / (Math.Abs(area1) + Math.Abs(area2));

            return(u);
        }
コード例 #2
0
        /// <summary>
        /// Returns a parameter at the intersection point with another line if found.
        /// </summary>
        /// <param name="l">The l.</param>
        /// <param name="tolerance">The tolerance.</param>
        /// <returns>System.Nullable&lt;System.Double&gt;.</returns>
        public double?Intersection(UVLine l, double tolerance = OSMDocument.AbsoluteTolerance)
        {
            UV     lineVector = this.End - this.Start;
            double area1      = lineVector.CrossProductValue(l.Start - this.Start);
            double area2      = lineVector.CrossProductValue(l.End - this.Start);

            if (area1 * area2 > tolerance)
            {
                lineVector = null;
                return(null);
            }
            lineVector = l.End - l.Start;
            area1      = lineVector.CrossProductValue(this.Start - l.Start);
            area2      = lineVector.CrossProductValue(this.End - l.Start);
            if (area1 * area2 > tolerance)
            {
                lineVector = null;
                return(null);
            }
            //double lengthL = l.GetLength();
            double a1 = (l.Start - this.Start).CrossProductValue(l.End - this.Start);

            if (a1 == 0)
            {
                return(Math.Min(l.Start.DistanceTo(this.Start), l.End.DistanceTo(this.Start)));
            }
            lineVector = null;
            double u = this.GetLength() * Math.Abs(a1) / (Math.Abs(area1) + Math.Abs(area2));

            return(u);
        }
コード例 #3
0
        /// <summary>
        /// Determines if this line intersects with another line.
        /// </summary>
        /// <param name="l">The l.</param>
        /// <param name="tolerance">The tolerance.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public bool Intersects(UVLine l, double tolerance = OSMDocument.AbsoluteTolerance)
        {
            UV     lineVector = this.End - this.Start;
            double area1      = lineVector.CrossProductValue(l.Start - this.Start);
            double area2      = lineVector.CrossProductValue(l.End - this.Start);

            if (area1 * area2 > tolerance)
            {
                lineVector = null;
                return(false);
            }
            lineVector = l.End - l.Start;
            area1      = lineVector.CrossProductValue(this.Start - l.Start);
            area2      = lineVector.CrossProductValue(this.End - l.Start);
            if (area1 * area2 > tolerance)
            {
                lineVector = null;
                return(false);
            }
            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Loads the factors.
        /// </summary>
        public void LoadFactors()
        {
            UV  v1 = new UV();
            UV  v2 = new UV();
            int i  = 0;

            foreach (var item in this.Connections)
            {
                if (i == 2)
                {
                    break;
                }
                else if (i == 0)
                {
                    v1 = this.Point - item.Point;
                }
                if (i == 1)
                {
                    v2 = this.Point - item.Point;
                }
                i++;
            }
            if (i < 2)
            {
                this.AngleFacotr    = double.PositiveInfinity;
                this.DistanceFactor = double.PositiveInfinity;
            }
            else
            {
                double d1 = v1.GetLengthSquared();
                double d2 = v2.GetLengthSquared();
                this.DistanceFactor = Math.Min(d1, d2);
                double crossProductValue = v1.CrossProductValue(v2);
                this.AngleFacotr = crossProductValue * crossProductValue / (d1 * d2);
            }
        }