Mondschein Engine  0.3.0
aitken_neville.cpp
1 /* Mondschein Engine is a fast, powerful, and easy-to-use 3D realtime rendering engine.
2  *
3  * Copyright (C) 2009-2013 by Andreas Amereller
4  * E-Mail: andreas.amereller.dev@googlemail.com
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; either version 3 of the License, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include "core/aitken_neville.h"
22 
23 using namespace mondschein;
24 using namespace math;
25 
26 Aitken_Neville::Aitken_Neville() : Pol_Int()
27 {
28  return;
29 }
30 
31 Aitken_Neville::Aitken_Neville(const std::map<float64,float64> &_p) : Pol_Int(_p)
32 {
33  return;
34 }
35 
36 Aitken_Neville::Aitken_Neville(Aitken_Neville_c _obj) : Pol_Int(_obj)
37 {
38  return;
39 }
40 
41 Aitken_Neville::~Aitken_Neville()
42 {
43  return;
44 }
45 
46 Aitken_Neville &Aitken_Neville::operator=(Aitken_Neville_c _obj)
47 {
48  Pol_Int::operator=(_obj);
49  return *this;
50 }
51 
53 {
54  std::vector<float64> x;
55  std::vector<float64> p;
56  for (std::map<float64,float64>::iterator it=get_points().begin(); it!=get_points().end(); ++it)
57  {
58  x.push_back(it->first);
59  p.push_back(it->second);
60  }
61  for (uint32 i=1; i<p.size(); ++i)
62  {
63  for (uint32 k=i; k<p.size(); ++k)
64  {
65  p.at(k)=((_x-x.at(k-1))*p.at(k)-(_x-x.at(k))*p.at(k-1))/(x.at(k)-x.at(k-i));
66  }
67  }
68  return p.back();
69 }