Skip to content

Mesh

1
mesh(X, Y, Z);

example_mesh_1

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include <cmath>
#include <matplot/matplot.h>

int main() {
    using namespace matplot;
    auto [X, Y] = meshgrid(iota(-8, .5, +8));
    auto Z = transform(X, Y, [](double x, double y) {
        double eps = std::nextafter(0.0, 1.0);
        double R = sqrt(pow(x, 2) + pow(y, 2)) + eps;
        return sin(R) / R;
    });
    mesh(X, Y, Z);

    show();
    return 0;
}

More examples

example_mesh_2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include <cmath>
#include <matplot/matplot.h>

int main() {
    using namespace matplot;
    auto [X, Y] = meshgrid(iota(-8, .5, +8));
    auto Z = transform(X, Y, [](double x, double y) {
        double eps = std::nextafter(0.0, 1.0);
        double R = sqrt(pow(x, 2) + pow(y, 2)) + eps;
        return sin(R) / R;
    });
    auto C = transform(X, Y, [](double x, double y) { return x * y; });
    mesh(X, Y, Z, C);

    show();
    return 0;
}

example_mesh_3

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#include <cmath>
#include <matplot/matplot.h>

int main() {
    using namespace matplot;
    auto [X, Y] = meshgrid(iota(-5, .5, +5));
    auto Z = transform(
        X, Y, [](double x, double y) { return y * sin(x) - x * cos(y); });
    mesh(X, Y, Z)->palette_map_at_surface(true).face_alpha(0.5);

    show();
    return 0;
}

example_mesh_4

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#include <cmath>
#include <matplot/matplot.h>

int main() {
    using namespace matplot;
    auto [X, Y, Z] = peaks();
    mesh(X, Y, Z)->hidden_3d(false);

    show();
    return 0;
}