1
0

surface.cpp 561 B

123456789101112131415161718192021222324
  1. #include "../matplotlibcpp.h"
  2. #include <cmath>
  3. namespace plt = matplotlibcpp;
  4. int main()
  5. {
  6. std::vector<std::vector<double>> x, y, z;
  7. for (double i = -5; i <= 5; i += 0.25) {
  8. std::vector<double> x_row, y_row, z_row;
  9. for (double j = -5; j <= 5; j += 0.25) {
  10. x_row.push_back(i);
  11. y_row.push_back(j);
  12. z_row.push_back(::std::sin(::std::hypot(i, j)));
  13. }
  14. x.push_back(x_row);
  15. y.push_back(y_row);
  16. z.push_back(z_row);
  17. }
  18. plt::plot_surface(x, y, z);
  19. plt::show();
  20. }