/* Danger from the Deep - Open source submarine simulation Copyright (C) 2003-2006 Thorsten Jordan, Luis Barrancos and others. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // (physics) physics formulas // subsim (C)+(W) SEE LICENSE #include #include "physics.h" const double math::DELTA = 1e-5; // For IS_ZERO // math - Floating-Point bool math::IS_ZERO (double value) { return (value < DELTA && value > -DELTA); } // math - Statistics double math::average (std::vector& values) { double avg = 0.0; for (unsigned int i=0; i& values, std::vector& weights) { if (values.size() != weights.size()) throw error("value and weights vectors must have same size"); double avg = 0.0; for (unsigned int i=0; i& forces) { vector3 net; for (unsigned int i=0; i& density, std::vector& occupacy) { return math::weighted_average(density, occupacy); }