Beispiel #1
0
        /// <summary>
        /// Finds the x-coordinate of the point where two linear functions meet (or null if they have approximately the same slope).
        /// </summary>
        /// <param name="other">The other function that this function may intersect with.</param>
        /// <returns>The x-coordinate of the intersection, or null if the functions have approximately the same slope.</returns>
        public double?GetIntersection(LinearFunction other)
        {
            if (this.Slope.ApproximatelyEquals(other.Slope))
            {
                return(null);
            }

            /* Formula for the intersection of two (non-parallel) lines:
             *
             * Assuming one line is y = ax + c and the other is y = bx + d,
             *
             * x = (d - c) / (a - b)
             * y = a * ( (d - c) / (a - b) ) + c
             *
             * Of course, we only need the x-value.
             * So, let's use the following:
             *   a - slope of first
             *   b - slope of second
             *   c - y-intersect of first
             *   d - y-intersect of second
             */

            return((other.YIntersect - this.YIntersect) / (this.Slope - other.Slope));
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LinearFunction"/> class, copied from another instance.
 /// </summary>
 /// <param name="other">The target <see cref="LinearFunction"/> to copy.</param>
 public LinearFunction(LinearFunction other)
 {
     this.Slope      = other.Slope;
     this.YIntersect = other.YIntersect;
 }