这是我将圆环(卫星)放置在球体上,然后围绕球体旋转的方式:

    int satellite_1_1_step = 0;
    int &r_satellite_1_1_step = satellite_1_1_step;
    float satellite_1_1_divider = 300;

    float satellite_1_1_theta = 6.5;
    float satellite_1_1_phi = 1;
    float satellite_1_1_theta_increment = 20/satellite_1_1_divider;
    float satellite_1_1_phi_increment = 20/satellite_1_1_divider;

    void satellite_1_1 ()
    {
            float satellite_1_1_theta_math = (satellite_1_1_theta-(satellite_1_1_theta_increment * r_satellite_1_1_step))/10.0*M_PI;
            float satellite_1_1_phi_math = (satellite_1_1_phi-(satellite_1_1_phi_increment * r_satellite_1_1_step))/10.0*2*M_PI;
            r_satellite_1_1_x = radius_exodus_pos * sin(satellite_1_1_theta_math) * cos(satellite_1_1_phi_math);
            r_satellite_1_1_y = radius_exodus_pos * sin(satellite_1_1_theta_math) * sin(satellite_1_1_phi_math);
            r_satellite_1_1_z = radius_exodus_pos * cos(satellite_1_1_theta_math);

            glPushMatrix();
            glTranslatef(r_satellite_1_1_x,r_satellite_1_1_y,r_satellite_1_1_z);
            glColor3f(1,0,0);
            glutSolidTorus(0.04, 0.2, 10, 100);
            glEnd();
            glPopMatrix();
    }

这就是我更新和增加其位置的方法:
    void satellite_1_1_increment()
    {

    if (r_satellite_1_1_step < satellite_1_1_divider)
        {
        ++(r_satellite_1_1_step);
        }

    if (r_satellite_1_1_step >= satellite_1_1_divider)
        {
        r_satellite_1_1_step = 1;
        }
    }

因此,我的圆环(卫星)绕球体移动,最终回到其起始位置,然后再次继续-太好了。但是,它所走的路径沿路径两极(我认为)左右摇摆-而不是简单地绕球旋转。

我的数学是否可以做一些改进,使卫星沿更圆的路径绕球旋转?

最佳答案

我看到的第一个问题是:

void satellite_1_1_increment()
{
    if (r_satellite_1_1_step < satellite_1_1_divider)
    {
        ++(r_satellite_1_1_step);
    }

    if (r_satellite_1_1_step >= satellite_1_1_divider)
    {
        r_satellite_1_1_step = 1;
    }
}

如果在第一个测试中增加步长以使其满足第二个测试,在边缘情况下会发生什么?立即复位,从而丢失该值。我认为您希望这样写可以避免该问题:
void satellite_1_1_increment()
{
    if (r_satellite_1_1_step >= satellite_1_1_divider)
           r_satellite_1_1_step = 1;
    else   ++r_satellite_1_1_step;
}
1是否是正确的重置值?也许应该是0吗?

关于c++ - 我的卫星绕行,但沿非圆形路径(校正球坐标数学),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14390516/

10-11 23:12