From 3869f6cb3e9d10475b7c917eebbd7966ac096c57 Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Sat, 30 Jun 2007 20:20:35 +0000 Subject: [PATCH] collision debugging stuff --- scripts/veltest.nsl | 6 +++--- src/container.cpp | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/scripts/veltest.nsl b/scripts/veltest.nsl index 4f8dcb5..c36cd99 100644 --- a/scripts/veltest.nsl +++ b/scripts/veltest.nsl @@ -1,8 +1,8 @@ add edmexperiment "Velocity Test Experiment" { set phase_steps 30 #phase average loops - set bounces 10000 #number of bounces to run the simulation over - #set lifetime 60 #The lifetime of a particle (seconds) +# set bounces 10000 #number of bounces to run the simulation over + set lifetime 120 #The lifetime of a particle (seconds) #Set the distance to 'lift' the particle off of the bottles #surface after a collision has happened. This is in to fix @@ -37,7 +37,7 @@ add edmexperiment "Velocity Test Experiment" { #vary velocity from 10 to 200 in 20 steps #set velocity 3 # (Meters per second) - #vary velocity from 1 to 500 in 40 steps + #vary velocity from 100 to 500 in 3 steps set velocity 500 #This will 'spread out' the velocity to a random point on a #maxwell-boltzmann distribution of velocities diff --git a/src/container.cpp b/src/container.cpp index d6b3fa1..47642d3 100644 --- a/src/container.cpp +++ b/src/container.cpp @@ -24,6 +24,9 @@ #include #include #include +#include + +#include #include "nslobject.h" #include "nslobjectfactory.h" @@ -279,7 +282,25 @@ void container::reflect ( vector3& velocity_vec, const vector3& normal, const lo if (normal.z < 0) velocity_vec.z *= -1.; } - + // Dump out the dot product between this and the normal + static std::ofstream dotps("dotps.txt"); + static std::ofstream dotwrong("dotwrong.txt"); + static std::ofstream reflects("reflects.txt"); + + { + static boost::mutex output_mutex; + boost::mutex::scoped_lock lock(output_mutex); + + long double dotp = dot(velocity_vec / velocity, normal); + + dotps << dotp << endl; + + if (dotp < 0) + logger << "NEGATIVE DOT PRODUCT ON REFLECTION" << endl; + if (dotp > 1) + dotwrong << dotp << "\t(" << velocity_vec << ")\t(" << normal*velocity << ")" << endl; + reflects << velocity_vec << endl; + } } else throw runtime_error("Unrecognised reflection type requested for reflection");