gpt4 book ai didi

c++ - 我的卫星绕行,但沿着非圆形路径(校正球面坐标数学)

转载 作者:太空宇宙 更新时间:2023-11-04 12:00:19 25 4
gpt4 key购买 nike

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

    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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com