Solving for cosine with given sine and quadrant