如何将球面几何转换为椭球几何C++顶点生成

问题描述 投票:0回答:1

我有一个关于如何在 C++ 中生成椭球体顶点几何的问题。我有以下代码:

Sphere::Sphere(const LengthT radius, const LengthT a, const LengthT b, const LengthT c, , std::uint16_t sectorCount, std::uint16_t stackCount) :
    m_radius(radius),
    m_sectorCount(sectorCount),
    m_stackCount(stackCount) {
    const double sectorStep{2 * std::numbers::pi / m_sectorCount};
    const double stackStep{std::numbers::pi / m_stackCount};
    constexpr double half_pi{std::numbers::pi / 2};
    double xy, sectorAngle, stackAngle;
    const auto lengthInv{double(1) / m_radius};
    for(std::uint16_t i{0}; i <= stackCount; i++) {
        Vertex vertex;
        stackAngle = (half_pi) - (i * stackStep);
        xy = m_radius * cos(stackAngle);
        vertex.pos.z = m_radius * sin(stackAngle);
        for(std::uint16_t j{0}; j <= sectorCount; j++) {
            sectorAngle = j * sectorStep;
            vertex.pos.x = xy * cos(sectorAngle);
            vertex.pos.y = xy * sin(sectorAngle);
            vertex.normals.x = vertex.pos.x * lengthInv;
            vertex.normals.y = vertex.pos.y * lengthInv;
            vertex.normals.z = vertex.pos.z * lengthInv;
            vertex.texCords.x = double(j) / sectorCount;
            vertex.texCords.y = double(i) / stackCount;
            verticies.push_back(vertex);
        }
    }
}

这会生成一个球坐标列表,但我想知道如何计算方程: ((x^2)/(a^2)+((y^2)/(b^2)+((z^2)/(c^2)=1 其中 a、b 和 c 用于定义椭圆本身。 我想知道如何将 a、b 和 c 合并到生成方程中

c++ geometry computational-geometry
1个回答
0
投票

根据评论,我认为这将在以下方面进行: ((x^2)/(a^2)+((y^2)/(b^2)+((z^2)/(c^ 2)=1

Ellipsoid::Ellipsoid(const double a, const double b, const double c, std::uint16_t sectorCount, std::uint16_t stackCount) :
    m_a(a),
    m_b(b),
    m_c(c),
    m_sectorCount(sectorCount),
    m_stackCount(stackCount) {
    const double sectorStep{2 * std::numbers::pi / m_sectorCount};
    const double stackStep{std::numbers::pi / m_stackCount};
    constexpr double half_pi{std::numbers::pi / 2};

    for(std::uint16_t i{0}; i <= stackCount; i++) {
        Vertex vertex;
        double stackAngle{(half_pi) - (i * stackStep)};
        double xy{m_b * cos(stackAngle)};
        vertex.pos.z = m_c * sin(stackAngle);
        for(std::uint16_t j{0}; j <= sectorCount; j++) {
            double sectorAngle{j * sectorStep};
            vertex.pos.x = m_a * xy * cos(sectorAngle);
            vertex.pos.y = m_a * xy * sin(sectorAngle);
            vertex.normals.x = 2 * vertex.pos.x / (m_a * m_a);
            vertex.normals.y = 2 * vertex.pos.y / (m_b * m_b);
            vertex.normals.z = 2 * vertex.pos.z / (m_c * m_c);
            vertex.texCords.x = double(j) / sectorCount;
            vertex.texCords.y = double(i) / stackCount;
            vertices.push_back(vertex);
        }
    }
}

我正在测试它以确保没有错误,但如果出现问题我会发布更新......

© www.soinside.com 2019 - 2024. All rights reserved.