I am trying to calculate the rotation from one cross to another. The correspondences between lines in the crosses are known.
The rotation needs to be calculated within 180 degrees either clockwise or anti-clockwise, currently I can calculate within 90 degrees but the algorithms fails with anything larger. The problem seems to be when the matching bearings pass around 360 degrees, such that A = 350 and A' = 80. Repeating this for each line of the cross, causes an incorrect total rotation to be calculated.
The algorithm at present, works as follows for comparing the rotation between two lines, from two crosses is; where crossB and crossA are the corresponding bearings for each cross.
if ((crossB < 360 && crossB >= 270) && (crossA >= 0 && crossA < 90)) { angle = -((360) - crossB) - crossA; } else if ((crossA < 360 && crossA >= 270) && (crossB >= 0 && crossB < 90) { angle = crossB + (360 - crossA); } else { angle = crossB - crossA; } Any thoughts on how to improve or change the algorithm so that it will allow any amount of rotation to be determined?
int deg = val % 360;' - that will take a value inval` and ensure that it's within 360 by dividingvalby 360, and assigning the remainder todeg.