Example #1
0
        public double GetDotProduct(LinearEquation p)
        {
            p = p ?? new LinearEquation(0, 0);
            var q     = this;
            var qdotp = q * p;

            return(qdotp[0] + qdotp[1]);
        }
Example #2
0
        internal LinearEquation GetReciprocal(LinearEquation r)
        {
            r = r ?? new LinearEquation(0, 0);
            var recipSlope     = -1 * (1 / Slope);
            var recipIntercept = r.Intercept - recipSlope * r.Slope;

            return(new LinearEquation(recipSlope, recipIntercept));
        }
Example #3
0
        public double GetAngle(LinearEquation p)
        {
            p = p ?? new LinearEquation(0, 0);
            var q           = this;
            var cosTheta    = q.GetCosTheta(p);
            var acosRadians = System.Math.Acos(cosTheta);

            return(System.Math.Round(acosRadians * (180 / System.Math.PI), RoundTo));
        }
Example #4
0
        internal static Tuple <double, double, double> GetImplicitCoeffs(LinearEquation p, LinearEquation q)
        {
            var v  = q - p;
            var ab = new LinearEquation(v[0], -1 * v[1]).GetTranspose();
            var a  = ab[0];
            var b  = ab[1];
            var c  = -1 * a * p[0] - b * p[1];

            return(new Tuple <double, double, double>(a, b, c));
        }
Example #5
0
        internal static LinearEquation GetLineFromVectors(LinearEquation p, LinearEquation q)
        {
            var abc       = GetImplicitCoeffs(p, q);
            var a         = abc.Item1;
            var b         = abc.Item2;
            var c         = abc.Item3;
            var slope     = (-1 * a) / b;
            var intercept = (-1 * c) / b;

            return(new LinearEquation(slope, intercept));
        }
Example #6
0
        public LinearEquation GetIntersect(LinearEquation p)
        {
            p = p ?? new LinearEquation(0, 0);
            var interceptTick = p.Intercept;
            var slopeTick     = p.Slope;

            var interceptX = (interceptTick - Intercept) / (Slope - slopeTick);
            //plug it back into either
            var inteceptY = SolveForY(interceptX);

            return(new LinearEquation(interceptX, inteceptY));
        }
Example #7
0
        /// <summary>
        /// Parse a string in the format of [intercept],[slope]
        /// where both intercept and slope may be parsed to doubles
        /// and are joined by a comma.
        /// </summary>
        /// <param name="csv"></param>
        /// <param name="lq"></param>
        /// <returns></returns>
        public static bool TryParse(string csv, out LinearEquation lq)
        {
            lq = null;
            if (string.IsNullOrWhiteSpace(csv) || !csv.Contains(","))
            {
                return(false);
            }
            var interceptStr = csv.Split(',')[0];
            var slopeStr     = csv.Split(',')[1];

            if (double.TryParse(interceptStr, out var intercept) && double.TryParse(slopeStr, out var slope))
            {
                lq = new LinearEquation(slope, intercept);
            }
            return(lq != null);
        }
Example #8
0
 public double GetDistance(LinearEquation p)
 {
     p = p ?? new LinearEquation(0, 0);
     return((this - p).EuclideanNorm);
 }