10/13/2011

Catmull-Rom Spline interpolation/ C++ source code/ 스플라인 보간

Created Date : 2010.11.
Language : C++
Tool : Visual Studio C++ 2008
Library & Utilized : -
Reference :Catmull-Rom Spline reference
Etc. : STL





This program is Catmull-Rom Spline code.
Please search detail contents about Catmull-Rom Spline in the internet. ^^
In the main.cpp, the source code consisted of Input, calculate spline and output.
In the function of Catmull-Rom Spline, parameters means coordinate(x,y), Step, number of interpolation in a section.

You can get interpolation points easily using this function(PathToCurve).


--------------------------------------------------------------------
이 소스 코드는 Catmull-Rom 보간법을 프로그래밍 한 것 입니다.
이론적인 내용은 인터넷을 검색하시면 많은 자료를 찾을 수 있어서 생략합니다.
메인 함수에는 입력, 보간, 출력으로 구성되어 있고, 입력을 원하는 좌표 값을 입력하여 해당 문제에 적용하시면될 거예요.
보간 함수는 좌표, 스텝,한 구간 보간 갯수를 입력하도록 하였습니다.
매트랩을 통하여 보간결과를 확인해보세요.
간단한 매트랩 파일도 첨부합니다.

좋은 답변 바랍니다. ^^


*main
/////////////////////////////////////////////////////////////////////////
//input
vector< pair<double , double > > InputPath;
FILE * fp1;
fp1 = fopen("input2.txt","r");
double x,y;
while( fscanf(fp1,"%lf %lf", &x, &y)!=EOF )
{
//printf("%lf %lf\n", x,y);
InputPath.push_back( make_pair(x,y) );
}
fclose(fp1);


//////////////////////////////////////////////////////////////////////////
//Spline
vector< pair<double , double > > curvePath;
curvePath = PathToCurve( InputPath, 1, 10);



//////////////////////////////////////////////////////////////////////////
//output
FILE* fp2;
fp2 = fopen("out.txt","w");
for(int i=0; i<curvePath.size(); ++i)
{
fprintf(fp2, "%lf %lf\n", curvePath[i].first, curvePath[i].second );
//printf("%lf %lf\n", curvePath[i].first, curvePath[i].second );
}
fclose(fp2);

*input
5 6
3 4
3 2
5 2
7 4

*output
1.000000 1.000000
1.174000 1.201000
1.392000 1.488000
1.648000 1.837000
1.936000 2.224000
2.250000 2.625000
2.584000 3.016000
2.932000 3.373000
3.288000 3.672000
3.646000 3.889000
4.000000 4.000000
4.359500 3.984500
4.736000 3.856000
5.126500 3.641500
5.528000 3.368000
5.937500 3.062500
6.352000 2.752000
6.768500 2.463500
7.184000 2.224000
7.595500 2.060500
8.000000 2.000000
8.400000 2.056000
8.800000 2.208000
9.200000 2.432000
9.600000 2.704000
10.000000 3.000000
10.400000 3.296000
10.800000 3.568000
11.200000 3.792000
11.600000 3.944000
12.000000 4.000000
12.418000 3.953000
12.864000 3.824000
13.326000 3.631000
13.792000 3.392000
14.250000 3.125000
14.688000 2.848000
15.094000 2.579000
15.456000 2.336000
15.762000 2.137000
16.000000 2.000000


plz give me your valuable comment. Thank you.





No comments:

Post a Comment