Detecting position relative to a gradient