#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "rtbp.h"
#include "ctants.h"

int main (int argc, char *argv[]) {
    double r0, v0, alf0, alff, pmax;
    int nalf, nt;
    if (argc<8
         || sscanf(argv[1], "%lf", &r0)!=1
         || sscanf(argv[2], "%lf", &v0)!=1
         || sscanf(argv[3], "%lf", &alf0)!=1
         || sscanf(argv[4], "%lf", &alff)!=1
         || sscanf(argv[5], "%d", &nalf)!=1
         || sscanf(argv[6], "%d", &nt)!=1
         || sscanf(argv[7], "%lf", &pmax)!=1
      ) {
        fprintf(stderr,"%s r0 v0 alf0 alff nalf nt pmax\n", argv[0]);
        return -1;
    }
    
    double z[4], zf[4];
    for (int i = 0; i < nalf; i++) {
        double alfi = alf0 + i * (alff - alf0) / (nalf - 1);
        rva2z(MU, r0, v0, cos(alfi), sin(alfi), z);
        proptraj(MU, nt, z, zf, NULL, pmax, NULL);
        double rzf = (MU - 1.0) - zf[0];
        double dm = rzf * AMOON;
        if (dm < 0.0) dm += RMOON;
        else dm -= RMOON;
        fprintf(stdout, "%.16g %.16g %.16g\n", alfi, zf[2], dm);
    }
    return 0;
}
