示例#1
0
 // 將不同interval的方程式加到hp term中
 private void DetermineEquationToHpTerm(Equation eq, Intersaction intersaction)
 {
     if (eq.X != 0)
     {
         if (eq.X > 0)
         {
             _hpTerm.AddEquation(new Equation(eq.Constant, eq.X, eq.X2, intersaction.X, eq.MaxInterval));
         }
         else
         {
             _hpTerm.AddEquation(new Equation(eq.Constant, eq.X, eq.X2, eq.MinInterval, intersaction.X));
         }
     }
     else
     {
         Equation parallel = (intersaction.Equation1.X == 0) ? intersaction.Equation1 : intersaction.Equation2;
         Equation slash    = (intersaction.Equation1.X != 0) ? intersaction.Equation1 : intersaction.Equation2;
         if (slash.X > 0)
         {
             parallel.MaxInterval = intersaction.X;
         }
         else
         {
             parallel.MinInterval = intersaction.X;
         }
         _hpTerm.AddEquation(parallel);
     }
 }
示例#2
0
 // 若交點y不是最大或跟其他交點相同的則清除它
 private bool CleanIntersaction(Intersaction intersaction, Term term)
 {
     if (!term.IsInInterval(intersaction.X))
     {
         return(false);
     }
     foreach (Equation eq in term.Equations)
     {
         if (eq.IsInInterval(intersaction.X) && eq.GetY(intersaction.X) > intersaction.Y)
         {
             _intersactions.Remove(intersaction);
             return(true);
         }
     }
     return(false);
 }
示例#3
0
 // 判斷是否重疊並加入交點
 private void AddIntersaction(Equation lhs, Equation rhs)
 {
     if (lhs.IsEquationsIntervalOverlap(rhs) && !lhs.IsEqual(rhs))
     {
         // 1     y = ax + b
         // 2     y = cx + d
         // 1-2   -(b - d) / (a - c)
         double       x        = -(lhs.Constant - rhs.Constant) / (lhs.X - rhs.X);
         double       y        = lhs.X * x + lhs.Constant;
         Intersaction newInter = new Intersaction(x, y, lhs, rhs);
         if (lhs.MinInterval <= x && x <= lhs.MaxInterval &&
             rhs.MinInterval <= x && x <= rhs.MaxInterval &&
             !_intersactions.Any(eq => eq.IsEqual(newInter)))
         {
             _intersactions.Add(newInter);
         }
     }
 }
 // 判斷是否一樣
 public bool IsEqual(Intersaction intersaction)
 {
     return(_x == intersaction.X &&
            _y == intersaction.Y);
 }