same hemisphere test algorithm