我的数组继续将数组的先前值添加到值中,任何人都可以帮忙解决这个问题我只需要计算出的值而不是之前添加的值
这是我的代码中计算和排序值的部分:
for (int i = 0; i < ARRAYSIZE; i++)
{
angle = random_angle(angle, STEP_SIZE);
// Compute the initial speed, using the selected angle.
xspeed = INITSPEED * cos(2 * PI * angle / 360.0);
yspeed = INITSPEED * sin(2 * PI * angle / 360.0);
//Look up windspeed
if (beaufort == 6)
{
wind = random_speed(STRONG_BREEZE_LO, STRONG_BREEZE_HI, STEP_SIZE);
wave = random_wave(B6_WAVE_LO, B6_WAVE_HI, STEP_SIZE);
}
else if (beaufort == 5)
{
wind = random_speed(FRESH_BREEZE_LO, FRESH_BREEZE_HI, STEP_SIZE);
wave = random_wave(B5_WAVE_LO, B5_WAVE_HI, STEP_SIZE);
}
else if (beaufort == 4)
{
wind = random_speed(MODERATE_BREEZE_LO, MODERATE_BREEZE_HI, STEP_SIZE);
wave = random_wave(B4_WAVE_LO, B4_WAVE_HI, STEP_SIZE);
}
else if (beaufort == 3)
{
wind = random_speed(GENTLE_BREEZE_LO, GENTLE_BREEZE_HI, STEP_SIZE);
wave = random_wave(B3_WAVE_LO, B3_WAVE_HI, STEP_SIZE);
}
else if (beaufort == 2)
{
wind = random_speed(LIGHT_BREEZE_LO, LIGHT_BREEZE_HI, STEP_SIZE);
wave = random_wave(B2_WAVE_LO, B2_WAVE_HI, STEP_SIZE);
}
else if (beaufort == 1)
{
wind = random_speed(LIGHT_AIR_LO, LIGHT_AIR_HI, STEP_SIZE);
wave = random_wave(B1_WAVE_LO, B1_WAVE_HI, STEP_SIZE);
}
else
{
wind = random_speed(CALM_LO, CALM_HI, STEP_SIZE);
}
//Repeat the following, as long a the y-position is greater than equal to wave height or the speed in y-direction is positive
while(ycoord >= wave || yspeed >= 0)
{
//Compute the new positions
xcoord = xcoord + xspeed * DELTA_T;
ycoord = ycoord + yspeed * DELTA_T;
//Compute new speeds
xspeed = xspeed - DELTA_T * DRAG * (xspeed + wind);
yspeed = yspeed - DELTA_T * GRAVITY - DELTA_T * DRAG * yspeed;
}
array[i] = xcoord;
}
答案 0 :(得分:1)
xcoord = xcoord + xspeed * DELTA_T;
您要将之前的值添加到此处的计算值
array[i] = xcoord;
然后你分配给数组。
您可能缺少重置xcoord / ycoord等的步骤