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.