Showing posts with label Interpolation. Show all posts
Showing posts with label Interpolation. Show all posts

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.