Skip to content

Commit

Permalink
Merge pull request #22 from Kotakku/feat/n-d_spline
Browse files Browse the repository at this point in the history
Feat/n d spline
  • Loading branch information
Kotakku authored Jan 27, 2024
2 parents d513529 + 3402f61 commit 92d89ac
Show file tree
Hide file tree
Showing 7 changed files with 622 additions and 547 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ set(example_files
path_planning/fmt_star
path_planning/dwa
path_planning/navigation_diffbot
path_planning/spline

unit/unit_example
)
Expand Down
Binary file added docs/example/fig/spline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions docs/example/path_planning/spline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# スプライン曲線

スプライン曲線による補間
CatmullRomとCubicSplineを比較する

![](../fig/spline.png)

{{ include_example("example/path_planning/spline.cpp") }}
64 changes: 64 additions & 0 deletions example/path_planning/spline.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <cpp_robotics/path_planning/spline_path.hpp>
#include <cpp_robotics/matplotlibcpp.hpp>
#include <Eigen/Dense>

int main()
{
using namespace cpp_robotics;
namespace plt = matplotlibcpp;

std::vector<Eigen::Vector2d> waypoints =
{
{0, 0},
{1, 2},
{2, 3},
{3, 1},
{4, 1},
{5, 0},
{4, -1},
{2, -2},
{1, -1}
};

CatumullRomSplinePath2d cutmull_spline(waypoints);
CubicSplinePath2d cubic_spline(waypoints);

std::vector<double> x, y;
{
const double length = cutmull_spline.length();
for (double i = 0; i < length; i += 0.05)
{
Eigen::Vector2d pos = cutmull_spline.position(i);
x.push_back(pos[0]);
y.push_back(pos[1]);
}
plt::named_plot("CatmullRomCurve", x, y);
}

x.clear();
y.clear();
{
const double length = cubic_spline.length();
for (double i = 0; i < length; i += 0.05)
{
Eigen::Vector2d pos = cubic_spline.position(i);
x.push_back(pos[0]);
y.push_back(pos[1]);
}
plt::named_plot("CubicSplineCurve", x, y);
}

x.clear();
y.clear();
// waypoints
for (const auto& p : waypoints)
{
x.push_back(p[0]);
y.push_back(p[1]);
}
plt::named_plot("Waypoint", x, y, "o");
plt::legend();
plt::show();

return 0;
}
Loading

0 comments on commit 92d89ac

Please sign in to comment.