示例#1
0
        public void AddPoint(double mx, double my, double mw = 1)
        {
            foreach (ChRecPoint iter in m_points)
            {
                double dist = mx - iter.x;
                if (Math.Abs(dist) < double.Epsilon)
                {
                    // Overwrite current iterator
                    iter.x = mx;
                    iter.y = my;
                    iter.w = mw;
                    return;
                }
                else if (dist > 0)
                {
                    // Insert before current iterator
                    ChRecPoint rec = new ChRecPoint(mx, my, mw);
                    m_points.Insert(iter.GetHashCode(), rec);
                    return;
                }
            }

            // Insert in front of list
            m_points.Add(new ChRecPoint(mx, my, mw));
        }
示例#2
0
        public override double Get_y(double x)
        {
            if (m_points.Count == 0)
            {
                return(0);
            }

            if (x <= m_points.First().x)
            {
                return(m_points.First().y);
            }

            if (x >= m_points[m_points.Count - 1].x)
            {
                return(m_points[m_points.Count - 1].y);
            }

            // At this point we are guaranteed that there are at least two records.

            if (m_last == m_points.Last())
            {
                m_last = m_points.First();
            }

            if (x > m_last.x)
            {
                // Search to the right
                foreach (ChRecPoint iter in m_points)
                {
                    if (x <= iter.x)
                    {
                        return(Interpolate_y(x, m_last, iter));
                    }
                    m_last = iter;
                }
            }
            else
            {
                // Search to the left
                foreach (ChRecPoint iter in m_points)
                {
                    //--iter;
                    if (x >= iter.x)
                    {
                        return(Interpolate_y(x, iter, m_last));
                    }
                    m_last = iter;
                }
            }

            return(0);
        }
示例#3
0
 private double Interpolate_y(double x, ChRecPoint p1, ChRecPoint p2)
 {
     return(((x - p1.x) * p2.y + (p2.x - x) * p1.y) / (p2.x - p1.x));
 }
示例#4
0
 public ChFunction_Recorder(ChFunction_Recorder other)
 {
     m_points = other.m_points;
     m_last   = m_points[m_points.Count - 1];
 }
示例#5
0
 // Use this for initialization
 public ChFunction_Recorder()
 {
     m_last = m_points[m_points.Count - 1];
 }
示例#6
0
 public void Reset()
 {
     m_points.Clear();
     m_last = m_points[m_points.Count - 1];
 }