Can I expand ABS() with OR/AND

81 Views Asked by At

I need check one condition regarding if the car is the similar (+/- 30 degrees) azimuth (compass direction) as the road.

Azimuth is an integer [0..359], 0 mean North

So if carAzimuth = 0 it is in the same general direction as other roads with roadAzimuth = [330, 345, 0, 15, 30]

enter image description here

So I create the formula to check for +/- 30

IF ( ABS(carAzimuth - roadAzimuth ) <= 30   OR
     ABS(carAzimuth - roadAzimuth ) >= 330  ) THEN // 360 -30   

I wonder if I can rewrite this without using ABS()

1

There are 1 best solutions below

1
On

You could always use the definition of the absolute value. Take the function $ABS(x)=\left \{ \begin{array}{ll} -x & x\leq 0 \\ x & x > 0 \\ \end{array} \right. $

So if we let $d$ = carAzimuth-roadAzimuth we can write

( IF(d>0) THEN
(
    IF(d<=30 OR d>=330) 
)

OR

IF(d<0) THEN
(
    IF(-d<=30 OR -d>=330) 
) )

THEN //360-30