Vector mathematics, Check out info about dot product, and cross product with that functions u can make orientation check.