[Teleus-cvs] teleus/src/math physics.cpp,1.13,1.14 physics.hpp,1.9,1.10
Status: Inactive
Brought to you by:
spiffgq
|
From: Daniel R. <sp...@us...> - 2004-05-25 23:04:00
|
Update of /cvsroot/teleus/teleus/src/math In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16120/src/math Modified Files: physics.cpp physics.hpp Log Message: Added some geometry functions. Created some Index: physics.cpp =================================================================== RCS file: /cvsroot/teleus/teleus/src/math/physics.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** physics.cpp 25 Feb 2004 06:34:00 -0000 1.13 --- physics.cpp 25 May 2004 23:03:34 -0000 1.14 *************** *** 384,387 **** --- 384,418 ---- /** + * \brief Returns the radius of a bounding sphere + * + * Given a bounding box of dimensions l, w, and h, this method + * returns the radius of a sphere that will enclose the box. + * + * \param l the length of the bounding box + * \param w the width + * \param h the height + * \returns the radius of the bounding sphere + * \author Daniel Royer + */ + double boundingSphere (double l, double w, double h) { + + return sqrt(l*l + w*w + h*h); + + } + + extern double volSphere (double r) { + + // V = (4/3)PI r^3 + return ((4.0/3.0)*PI) * (r * r * r); + } + + extern double surfAreaSphere (double r) { + + // S = 4PI r^2 + return 4.0 * PI * (r*r); + } + + + /** * \brief Cavendish's gravitational constant * *************** *** 695,699 **** * \author Daniel Royer */ ! double kineticEnergy (double mass, double speed) { return 0.5 * mass * square(speed); --- 726,730 ---- * \author Daniel Royer */ ! double kineticEnergy (float mass, double speed) { return 0.5 * mass * square(speed); *************** *** 703,707 **** * \overload */ ! double kineticEnergy (double mass, const Vector3d& vel) { return 0.5 * mass * vel.lengthSquared(); --- 734,738 ---- * \overload */ ! double kineticEnergy (float mass, const Vector3d& vel) { return 0.5 * mass * vel.lengthSquared(); *************** *** 709,712 **** --- 740,770 ---- /** + * \brief Calculates the impulse force acting on two colliding + * masses + */ + Vector3d impulseForce (float mass1, const Vector3d& vel1, + float mass2, const Vector3d& vel2, + const Vector3d& normal, double coeffRest, + double time) + { + + // Calculate the relative speed along the line of action of + // the collision. + Vector3d velRel = vel1 - vel2; + double speedRel = dot(velRel, normal); + + // Calculate the impulse acting on the masses + double impulse = -speedRel*(coeffRest + 1); + impulse /= (1.0 / mass1 + 1.0 / mass2); + + // Calculate the force acting on the masses + //assert (closeEnough(normal.lengthSquared(), 1.0), "Normal is not normalized"); + + Vector3d force = normal.normalized(); + force *= impulse / time; + return force; + } + + /** * * Index: physics.hpp =================================================================== RCS file: /cvsroot/teleus/teleus/src/math/physics.hpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** physics.hpp 25 Feb 2004 06:34:00 -0000 1.9 --- physics.hpp 25 May 2004 23:03:34 -0000 1.10 *************** *** 61,65 **** extern int clamp (int v, int min, int max); extern double clamp (double v, double min, double max); ! extern bool closeEnough (double a, double b, double e); //-- PHYSICS CONSTANTS ----------------------------------------- --- 61,70 ---- extern int clamp (int v, int min, int max); extern double clamp (double v, double min, double max); ! extern bool closeEnough (double a, double b, double e = 1e-6); ! extern double boundingSphere (double l, double w, double h); ! ! //-- GENERAL GEOMETRY FUNCTIONS -------------------------------- ! extern double volSphere (double r); ! extern double surfAreaSphere (double r); //-- PHYSICS CONSTANTS ----------------------------------------- *************** *** 80,85 **** extern Vector3d linearMomentum (float mass, const Vector3d& velocity); ! extern double kineticEnergy (double mass, double speed); ! extern double kineticEnergy (double mass, const Vector3d& vel); extern double escapeSpeed (double planetMass, double planetRadius); --- 85,94 ---- extern Vector3d linearMomentum (float mass, const Vector3d& velocity); ! extern double kineticEnergy (float mass, double speed); ! extern double kineticEnergy (float mass, const Vector3d& vel); ! Vector3d impulseForce (float mass1, const Vector3d& vel1, ! float mass2, const Vector3d& vel2, ! const Vector3d& normal, double coeffRest, ! double time); extern double escapeSpeed (double planetMass, double planetRadius); |