【发布时间】:2011-06-15 18:09:25
【问题描述】:
我的程序有问题,我实际上是在使用 Cubic BSplines 进行插值,但是当我在 main() 中调用我的插值函数时,我得到了错误的结果,当我直接在 main() 中编写函数时它可以工作:(。 我看不出两者有什么区别。
void CubicBSpline::interpolation(){
Point3d point;
for(unsigned int i = 3; i < (knots->m_points).size(); i++){
for(double t=0; t<1; t+=0.1){
point = bSplineCubicUniform(i, t);
cout << point.x << " " << point.y <<endl;
}
}
}
int main(){
CubicBSpline cbs(4, 4);
cbs.interpolation(); //this is the call of my function but I got a wrong result
// and here I write directly my function and that's work good
Point3d point;
for(unsigned int i = 3; i < (cbs.knots->m_points).size(); i++){
for(double t=0; t<1; t+=0.1){
point = cbs.bSplineCubicUniform(i, t);
cout << point.x << " " << point.y <<endl;
}
}
return 0;
}
【问题讨论】:
-
“错误结果”是什么意思?
-
很难在没有看到其余代码的情况下判断...可能是例如未初始化变量的问题。如果在 main 中的显式调用之后移动
cbs.interpolation调用会发生什么? -
顺便说一句,这是一个方法而不是一个函数!
-
@Amokrane:如果你想学究气,那就是成员函数,一种函数。在 C++ 中,没有方法之类的东西。
-
我找到了错误的根源,它是Point3d,在我的例子中我是这样使用它的:struct Point3d{ double x, y, z};我用 vector
替换了它,这就是工作。但我不知道Point3d有什么问题。