DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

ACOS(x) can error with industry standard expression

Started by ablincoe, March 17, 2014, 01:35:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ablincoe

The Numeric Function  -  ACOS(x)  -  can throw an exception with the following industry standard expression and values
Standard Expression  -  ACOS((D1A^2 + D2A^2 - D3A^2) / (2 * D1A * D2A))
     D1A = Length of Side-1 of a triangle        -  2.84592511099023810000
     D2A = Length of Side-2 of a triangle        -  2.84592511099023770000
     D3A = Length of Side-3 of a triangle        -  0.00000000000000355271

     Outcome  -  1.00000000000000020000

Logical checks performed:  The sum of the length of any 2 sides is always greater than the length of the remaining side
     Side-1 + Side-2  >  Side-3  -  True
     Side-1 + Side-3  >  Side-2  -  True
     Side-2 + Side-3  >  Side-1  -  True
     
The function's limitations are  -  -1 <= X <= 1
While the above came out just slightly over  1,  there may be instances where the opposite is true also (lower than -1).

Work around:
Put the  ACOS(x)  into a Subroutine similar to:

Main Routine:
...
  X = ((D1A^2 + D2A^2 - D3A^2) / (2 * D1A * D2A))
    GoSub       DO_ACOS
    Angle = X
...

DO_ACOS:
  IF X < -1  THEN       X = -1
  IF X >  1  THEN       X =  1
  X = ACOS(X)
RETURN