Esempio n. 1
0
        /// <summary>
        /// returns null if ray does not hit the line. When hit, returns the distance from the hit point
        /// </summary>
        /// <param name="line">Line barrier</param>
        /// <returns>distance of ray origins from the hit point along the ray direction</returns>
        public double?DistanceToForIsovist(UVLine line, double tolerance)
        {
            //checking if the lines intersect at all
            double vs = this.Direction.CrossProductValue(this.Origin - line.Start);
            double ve = this.Direction.CrossProductValue(this.Origin - line.End);

            if (vs * ve > -tolerance)
            {
                return(null);
            }
            //finding the intersection
            if (vs == 0)
            {
                return(this.Origin.DistanceTo(line.Start));
            }
            else if (ve == 0)
            {
                return(this.Origin.DistanceTo(line.End));
            }
            else
            {
                double _length = line.GetLength();
                vs = Math.Abs(vs);
                ve = Math.Abs(ve);
                double lengthFromStart = _length * vs / (vs + ve);
                UV     hitPoint        = line.FindPoint(lengthFromStart);
                return(this.Origin.DistanceTo(hitPoint));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// returns null if ray does not hit the line. When hit, returns the distance from the hit point
        /// </summary>
        /// <param name="hitPoint">Hit point on the barrier</param>
        /// <param name="line">Line barrier</param>
        /// <returns>distance of ray origins from the hit point along the ray direction</returns>
        public double?DistanceTo(UVLine line, ref UV hitPoint, double tolerance = 0.0001)
        {
            hitPoint = null;
            double?result = null;
            double vs     = this.Direction.CrossProductValue(this.Origin - line.Start);
            double ve     = this.Direction.CrossProductValue(this.Origin - line.End);

            if (vs * ve > tolerance)
            {
                return(null);
            }
            if (vs == 0)
            {
                result   = this.Origin.DistanceTo(line.Start);
                hitPoint = line.Start;
            }
            else if (ve == 0)
            {
                result   = this.Origin.DistanceTo(line.End);
                hitPoint = line.End;
            }
            else
            {
                double _length = line.GetLength();
                vs = Math.Abs(vs);
                ve = Math.Abs(ve);
                double lengthFromStart = _length * vs / (vs + ve);
                hitPoint = line.FindPoint(lengthFromStart);
                result   = this.Origin.DistanceTo(hitPoint);
            }
            if (result != null)
            {
                var hitDirection = hitPoint - this.Origin;
                if (hitDirection.DotProduct(this.Direction) < 0)
                {
                    result   = null;
                    hitPoint = null;
                }
            }
            return(result);
        }