Derive an explicit integral formula for the amoeba-to-coamoeba mapping in the case of polynomials that define Harnack curves. As a consequence obtain an exact description of the coamoebas of such polynomials. This formula can be viewed as a generalization of the familiar law of cosines that is used for solving triangles.