Please post your sketch, complete, not just the snippet where you do the calculation (because in that case more often than not the problem is in the part you don't show).
Please post your sketch, complete, not just the snippet where you do the calculation (because in that case more often than not the problem is in the part you don't show).