00001
00002
00003
00004
00005
00006 #include "dyn.h"
00007
00008 local void accumulate_acceleration(dyn * bj,
00009 dyn * bi,
00010
00011 real eps_squared)
00012
00013 {
00014 if(bj->get_oldest_daughter() != NULL){
00015 for(dyn * bb = bj->get_oldest_daughter(); bb != NULL;
00016 bb = bb->get_younger_sister()){
00017 accumulate_acceleration(bb, bi, eps_squared);
00018 }
00019 }else{
00020 if(bi != bj){
00021 vector d_pos = bi->get_pos() - bj->get_pos();
00022 real soft_d_pos_squared = d_pos * d_pos + eps_squared;
00023 real inverse_d_pos_cubed =
00024 1 / ( soft_d_pos_squared * sqrt( soft_d_pos_squared ));
00025
00026 bi->inc_acc(-inverse_d_pos_cubed * bj->get_mass() * d_pos);
00027 }
00028 }
00029 }
00030
00031 void dyn::calculate_acceleration(dyn * b,
00032 real eps_squared)
00033 {
00034
00035 if (get_oldest_daughter() != NULL) {
00036 for_all_daughters(dyn, b, bb)
00037 bb->calculate_acceleration(b, eps_squared);
00038 } else {
00039 clear_acc();
00040 accumulate_acceleration(b, this, eps_squared);
00041 }
00042 }