diff --git a/polygon_generator.cc b/polygon_generator.cc index d234c0b..e55a32d 100644 --- a/polygon_generator.cc +++ b/polygon_generator.cc @@ -46,3 +46,34 @@ polygon poly_generate::triangle( one_over_36 * mass * base * std::pow(height, 3), mass}; } + +polygon poly_generate::regular(double radius, uint n_sides, double mass) { + assert(n_sides > 2); + std::vector points; + points.reserve(n_sides); + double theta = 2 * M_PI / n_sides; + + for (uint i = 0; i < n_sides; i++) + points.push_back({radius * cos(i * theta), radius * sin(i * theta)}); + + double l = vec2d::norm(points[1] - points[0]); + + double sin_, cos_; + sincos(M_PI / n_sides, &sin_, &cos_); + double cot = cos_ / sin_; + + double inertia = mass * l * l / 24 * (1 + 3 * cot * cot); + return polygon{{0, 0}, 0, points, inertia, mass}; +} + +static double intertia_of_polygon_subtriangle( + vec2d& centroid, vec2d& p1, vec2d& p2) { + double base, height; + if (vec2d::norm(p1 - centroid) > vec2d::norm(p2 - centroid)) + base = vec2d::norm(p1 - centroid); +} + +polygon poly_generate::general(std::vector& points, double mass) { + double intertia = 0; + return polygon{{0, 0}, 0, points, intertia, mass}; +} diff --git a/polygon_generator.h b/polygon_generator.h index f92655f..c223c23 100644 --- a/polygon_generator.h +++ b/polygon_generator.h @@ -16,5 +16,9 @@ namespace poly_generate { polygon triangle(double side1, double side2, double angle, double mass = 1); + polygon regular(double radius, uint n_sides, double mass = 1); + + polygon general(std::vector& points, double mass = 1); + }; // namespace poly_generate #endif