I found a formula for getting the angle between two 3D vectors (e.g. as shown in https://stackoverflow.com/a/12230083/6607497).
However when trying to implement it in PostScript I realized that PostScript lacks the arcus cosinus function needed to get the angle.
Why doesn't PostScript have that function and how would a work-around look like?
In Wikipedia I found the formula
$\arccos(x)={\frac {\pi }{2}}-\arctan \left({\frac {x}{\sqrt {1-x^{2}}}}\right)}$
, but that looks a bit complicated; and if it's not: Why didn't they add acos
(arcus cosinus) using that definition?
Did I miss something obvious?
As indicated in Wikipedia and done in pst-math, acos
can be implemented rather easily using atan
and sqrt
(among other primitives) like this:
GS>% arcus cosinus, using degrees
GS>/acos { dup dup mul neg 1.0 add sqrt exch atan } bind def
GS>1 acos ==
0.0
GS>-1 acos ==
180.0
GS>0 acos ==
90.0
However this may be less efficient than a native implementation.