1

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

    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;  
        }
    }

所以,我的圆环(卫星)围绕球体移动,最终回到起始位置,然后再次继续——这很棒。然而,它所走的路径在两极(我认为)周围摇摆不定——而不是简单地环绕球体。

是否可以对我的数学进行改进,使卫星以更圆形的路径环绕球体?

4

2 回答 2

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

于 2013-01-18T00:36:10.493 回答
0

更改了前两行:

    void satellite_1_1 ()
    float satellite_1_1_theta_math = (satellite_1_1_theta+(satellite_1_1_theta_increment* r_satellite_1_1_step))*M_PI;
    float satellite_1_1_phi_math = (satellite_1_1_phi-(satellite_1_1_phi_increment* r_satellite_1_1_step))*M_PI/360;

现在卫星沿赤道运行 360 度。在我的 glPushMatrix 之后添加一个 glRotatef 可以让我微调它的轴。

再次感谢沃利克。- 克罗普克

于 2013-01-18T02:29:05.173 回答