I'm writing a program to model the launch of a rocket. Here's the particular function so far.
The problem bit is that upon reaching the altitude of pitchtime, the rocket is then supposed to pitch over at an inputted rate toward a final pitch at an inputted azimuth. The describe the attitude of the rocket, I created the vec att, which is a unit vector pointing in the direction of the rocket (vec is a class defined to act like a 3D physics vector). The tricky part is that I'm not sure how to alter the value of the vec att through the pitch rate and the azimuth.Code://1. Load the position and speed of the rocket on the pad double lslat = ( latdegbox->value() + ( latminbox->value() + latsecbox->value()/60) / 60 ) * M_PI / 180; if ( southbutton->set() ) { lslat *= -1; } double lslong = ( longdegbox->value() + ( longminbox->value() + longsecbox->value()/60) / 60 ) * M_PI / 180; if ( westbutton->set() ) { lslong *= -1; } double lselev = elevbox->value() * 0.3048; double t0 = ( utchourbox->value() + ( utcminbox->value() + utcsecbox->value()/60) / 60 ) * M_PI / 180; double x = (lselev + georad) * cos (lslat) * cos ( lslong + t0); double y = (lselev + georad) * cos (lslat) * sin ( lslong + t0); double z = (lselev + georad) * sin (lslat); vec r(x,y,z); x = - ( lselev + georad ) * cos (lslat) * georate * sin (lslong); y = ( lselev + georad ) * cos (lslat) * georate * cos (lslong); z = 0; vec v(x,y,z); lsspeedbox->value(v.mag()); vec att = r.unit(); double t=0; double tstep = 0.001; //2. Load the parameters of the launch double oew = oewbox->value(); double payload = payloadbox->value(); double zfw = oew + payload; double fuel = fuelbox->value(); double mass = zfw + fuel; double mdot = mdotbox->value(); double vex = vexbox->value(); double azimuth = azimuthbox->value() * M_PI / 180; double pitchtime = pitchtimebox->value() * 0.3048; double pitchrate = pitchratebox->value(); double pitchterm = pitchtermbox->value(); double pitch = 0; vec g = r*(-mu/pow(r.mag(),3)); vec mg = g*mass; towbox->value(mg.mag()); thrustbox->value(mdot*vex); //3. Liftoff from the pad do { //mdv = cdm + mgdt vec g = r*(-mu/pow(r.mag(),3)); v = v + att*vex*mdot*tstep/mass + g*tstep; vec gforce = att*vex*mdot/mass; r = r + v*tstep; mass -= mdot*tstep; t += tstep; wtf << t << " " << r.mag() - georad << " " << v.mag() << " " << gforce.mag()/9.81 << endl; } while ( r.mag() - georad < pitchtime && mass > zfw);


Reply With Quote
.