This gallery example demonstrates creating custom geometric shapes using Plotly.cpp by generating coordinate points programmatically. It showcases the creation of a five-pointed star through mathematical coordinate calculation and path-based visualization.
The star shape is created with outer radius 1.0, inner radius 0.4, and centered at the origin, demonstrating precise geometric control through programmatic coordinate generation.
#include <cmath>
#include <utility>
#include <vector>
-> std::pair<std::vector<double>, std::vector<double>> {
std::vector<double> x;
std::vector<double> y;
const double angle = M_PI / 5.0;
for (int i = 0; i < 10; i++) {
double r = (i % 2 == 0) ? rOuter : rInner;
double theta = (i * angle) + M_PI / 2.0;
double xPoint = cx + (r * std::cos(theta));
double yPoint = cy + (r * std::sin(theta));
x.push_back(xPoint);
y.push_back(yPoint);
}
x.push_back(x[0]);
y.push_back(y[0]);
return std::make_pair(x, y);
}
auto main(
int argc,
char *argv[]) ->
int {
{"y", y},
{"type", "scatter"},
{"mode", "lines+markers"},
{"line", {{"shape", "linear"}, {"color", "gold"}}},
{"marker", {{"color", "red"}, {"size", 8}}}}},
{{"title", {{"text", "Star Shape Plot"}}},
{"xaxis", {{"scaleanchor", "y"}, {"range", {-1.5, 1.5}}}},
{"yaxis", {{"range", {-1.5, 1.5}}}},
{"showlegend", false}});
if (!args.headless) {
} else {
{"width", 800},
{"height", 600},
{"filename", "star"}};
}
return 0;
}
auto parseGalleryArgs(int argc, char *argv[]) -> GalleryArgs
Parse command line arguments for gallery examples.
Definition arg_parser.cpp:4
auto main() -> int
Definition gallery_animate_sin_wave.cpp:48
auto createStarShape(double cx, double cy, double rOuter, double rInner) -> std::pair< std::vector< double >, std::vector< double > >
Definition gallery_star.cpp:48
nlohmann::json Object
Definition plotly.hpp:26
Public Plotly C++ API header.