dwell time algorithm (2D) for my project