--- trunk/src/brains/Snapshot.cpp 2013/06/16 15:15:42 1879 +++ trunk/src/brains/Snapshot.cpp 2013/07/02 20:02:31 1896 @@ -297,22 +297,24 @@ namespace OpenMD { frameData.volume = vol; } + /** Wrap a vector according to periodic boundary conditions */ void Snapshot::wrapVector(Vector3d& pos) { - - Vector3d scaled = scaleVector(pos); - - for (int i = 0; i < 3; i++) - scaled[i] -= roundMe(scaled[i]); - if( !frameData.orthoRhombic ) - pos = frameData.hmat * scaled; - else { - + if( !frameData.orthoRhombic ) { + Vector3d scaled = frameData.invHmat * pos; + for (int i = 0; i < 3; i++) { + scaled[i] -= roundMe( scaled[i] ); + } // calc the wrapped real coordinates from the wrapped scaled coordinates - for (int i=0; i<3; i++) { - pos[i] = scaled[i] * frameData.hmat(i, i); - } + pos = frameData.hmat * scaled; + } else { + RealType scaled; + for (int i=0; i<3; i++) { + scaled = pos[i] * frameData.invHmat(i,i); + scaled -= roundMe( scaled ); + pos[i] = scaled * frameData.hmat(i,i); + } } }