Hi All,
I’m trying to search an array based on two angles. The array contains the LeftSideAngle and RightSideAngle. The search is entered in degrees, and there is a further field called variance, also in degrees. The idea being that you can then enter say 90°, with a variance of 90° and the search will return all matches with a LeftSideAngle>=45 and RightSideAngle<=135 (90° ± 90° on each side).
Now the problem comes when the LeftSideAngle>180, as the search will span the 360/0 point. E.g. Search = 0° and Variance = 270°, LeftSideAngle>=225 and RightSideAngle<=135. I’ve had a go at creating an if statement to handle it, but i’m admitting defeat! Here’s what I’ve got:
if (LeftWallAngle>=180) {
if ((Unit.LeftWallAngle>=LeftWallAngle || Unit.LeftWallAngle<=RightWallAngle) && Unit.LeftWallAngle<=360 && Unit.LeftWallAngle>=0) {
leftTrue = true;
}
if (Unit.RightWallAngle>=LeftWallAngle && Unit.RightWallAngle<=360 && Unit.RightWallAngle>=0) {
rightTrue = true;
}
} else if (LeftWallAngle<=180) {
if (Unit.LeftWallAngle>=LeftWallAngle && Unit.LeftWallAngle<=RightWallAngle) {
leftTrue = true;
}
if (Unit.RightWallAngle>=LeftWallAngle && Unit.RightWallAngle<=RightWallAngle) {
rightTrue = true;
}
}
There’s so many ifs it’s got me lost! Any help is, as always, much appreciated!
Thanks!
Darren.