79759109

Date: 2025-09-08 15:52:22
Score: 0.5
Natty:
Report link

I was fighting this a bit with while using Tiled and figured I'd throw up what I landed on here. In Tiled it's just a width/height with the ellipse flag toggled so this works for that.

static std::vector<std::pair<float, float>> ellipsePoints(const float &centerX, const float &centerY,
                                                          const float &horizontalRadius, const float &verticalRadius) {
    // Box2d only lets us have a max of 8.
    static constexpr size_t MAX_SEGMENTS = 8;
    std::vector<std::pair<float, float>> points;
    for (size_t i = 0; i < MAX_SEGMENTS; i++) {
        float theta = 2.0f * M_PI * i / MAX_SEGMENTS;
        float x = centerX + horizontalRadius * cosf(theta);
        float y = centerY + verticalRadius * sinf(theta);
        points.emplace_back(x, y);
    }

    return points;
};

enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: accordionfolder