static void get_weight_factor(struct efp *efp, double *mass_fact, mat_t *inertia_fact) { size_t n_frags; check_fail(efp_get_frag_count(efp, &n_frags)); double xyzabc[6 * n_frags]; check_fail(efp_get_coordinates(efp, xyzabc)); for (size_t i = 0; i < n_frags; i++) { double mass; check_fail(efp_get_frag_mass(efp, i, &mass)); double inertia[3]; check_fail(efp_get_frag_inertia(efp, i, inertia)); double a = xyzabc[6 * i + 3]; double b = xyzabc[6 * i + 4]; double c = xyzabc[6 * i + 5]; mat_t rotmat; euler_to_matrix(a, b, c, &rotmat); mass_fact[i] = 1.0 / sqrt(mass); get_inertia_factor(inertia, &rotmat, inertia_fact + i); } }
static void set_body_mass_and_inertia(struct efp *efp, size_t idx, struct body *body) { double mass, inertia[3]; check_fail(efp_get_frag_mass(efp, idx, &mass)); check_fail(efp_get_frag_inertia(efp, idx, inertia)); body->mass = AMU_TO_AU * mass; body->inertia.x = AMU_TO_AU * inertia[0]; body->inertia.y = AMU_TO_AU * inertia[1]; body->inertia.z = AMU_TO_AU * inertia[2]; body->inertia_inv.x = body->inertia.x < EPSILON ? 0.0 : 1.0 / body->inertia.x; body->inertia_inv.y = body->inertia.y < EPSILON ? 0.0 : 1.0 / body->inertia.y; body->inertia_inv.z = body->inertia.z < EPSILON ? 0.0 : 1.0 / body->inertia.z; }