项目作者: chen0040

项目描述 :
Package provides C++ implementation of spline interpolation
高级语言: C++
项目地址: git://github.com/chen0040/cpp-spline.git
创建时间: 2017-05-30T03:41:08Z
项目社区:https://github.com/chen0040/cpp-spline

开源协议:MIT License

下载


cpp-spline

Package provides C++ implementation of spline interpolation

Features

  • Bezier Curve
  • B-Spline
  • CatmullRom

Usage

Bezier

To create a Bezier Curve in 2D or 3D environment:

  1. #include <iostream>
  2. #include "../../main/cpp/Bezier.h"
  3. int main(char** argv, int argc) {
  4. Curve* curve = new Bezier();
  5. curve->set_steps(100); // generate 100 interpolate points between the last 4 way points
  6. curve->add_way_point(Vector(1, 1, 0));
  7. curve->add_way_point(Vector(2, 3, 0));
  8. curve->add_way_point(Vector(3, 2, 0));
  9. curve->add_way_point(Vector(4, 6, 0));
  10. ...
  11. std::cout << "nodes: " << curve->node_count() << std::endl;
  12. std::cout << "total length: " << curve->total_length() << std::endl;
  13. for (int i = 0; i < curve->node_count(); ++i) {
  14. std::cout << "node #" << i << ": " << curve->node(i).toString() << " (length so far: " << curve->length_from_starting_point(i) << ")" << std::endl;
  15. }
  16. delete curve;
  17. }

BSpline

To create a BSpline Curve in 2D or 3D environment:

  1. #include <iostream>
  2. #include "../../main/cpp/BSpline.h"
  3. int main(char** argv, int argc) {
  4. Curve* curve = new BSpline();
  5. curve->set_steps(100); // generate 100 interpolate points between the last 4 way points
  6. curve->add_way_point(Vector(1, 1, 0));
  7. curve->add_way_point(Vector(2, 3, 0));
  8. curve->add_way_point(Vector(3, 2, 0));
  9. curve->add_way_point(Vector(4, 6, 0));
  10. ...
  11. std::cout << "nodes: " << curve->node_count() << std::endl;
  12. std::cout << "total length: " << curve->total_length() << std::endl;
  13. for (int i = 0; i < curve->node_count(); ++i) {
  14. std::cout << "node #" << i << ": " << curve->node(i).toString() << " (length so far: " << curve->length_from_starting_point(i) << ")" << std::endl;
  15. }
  16. delete curve;
  17. }

CatmullRom

To create a CatmullRom Curve in 2D or 3D environment:

  1. #include <iostream>
  2. #include "../../main/cpp/CatmullRom.h"
  3. int main(char** argv, int argc) {
  4. Curve* curve = new CatmullRom();
  5. curve->set_steps(100); // generate 100 interpolate points between the last 4 way points
  6. curve->add_way_point(Vector(1, 1, 0));
  7. curve->add_way_point(Vector(2, 3, 0));
  8. curve->add_way_point(Vector(3, 2, 0));
  9. curve->add_way_point(Vector(4, 6, 0));
  10. ...
  11. std::cout << "nodes: " << curve->node_count() << std::endl;
  12. std::cout << "total length: " << curve->total_length() << std::endl;
  13. for (int i = 0; i < curve->node_count(); ++i) {
  14. std::cout << "node #" << i << ": " << curve->node(i).toString() << " (length so far: " << curve->length_from_starting_point(i) << ")" << std::endl;
  15. }
  16. delete curve;
  17. }