When can the law of cosines be used?