% Basic trig... % We use csnames \sin@# and \cos@# where # is int % We could use differentials to get MUCH more accuracy % but at the cost of expandability... % These are not delimited - why are they scooping up % entire numbers?!? \def\Pos-{} \def\Neg#1{\ifdim#11\p@<\z@\Pos#1\else-#1\fi} %\def\Abs#1\relax{\ifnum#1<\z@\Pos#1\else#1\fi} \def\Abs#1{\ifdim#11\p@<\z@\else#1\fi} \def\endgroupsetdim#1#2{% \expandafter\endgroup\expandafter#1\the#2\relax } % Need atan2... how? (we could just ask perl...) % Instead, We'll make the horrific approximation (not even % a Taylor series) that, if 0\AbsValD\@tempdima \@testtrue \dimen@\@tempdima \@tempdima#1\relax %\debug1{swap: a=\the\@tempdima, @=\the\dimen@} \fi \div\dimen@\@tempdima %\debug1{ratio: \the\dimen@} \@tempdima=\mul\dimen@\dimen@ \debug5{atan2 \the#1/\the#2 -> \the\dimen@, \the\@tempdima}% \edef\sgn{\ifdim\dimen@<\z@+\else-\fi0.2}% \advance\dimen@ \sgn\@tempdima \dimen@=57.296\dimen@ % 180/pi -> deg %\debug1{atan(ratio)=\the\dimen@} \if@test % if we swapped... % dimen=90-dimen if positive, -90-dimen if negative \advance\dimen@\ifdim\dimen@>\z@-\fi90\p@ \dimen@-\dimen@ %\debug1{swapped: \the\dimen@} \fi \ifdim#2<\z@ \advance\dimen@180\p@ %\debug1{x<0: \the\dimen@} \fi \ifdim\dimen@<\z@ \advance\dimen@360\p@ %\debug1{want pos: \the\dimen@} \fi \endgroupsetdim#3\dimen@ } % not expandable... but more precise... \def\dosin#1{% \ifdim#1<0\p@ #1=-#1\relax\dosin#1\relax#1=-#1\relax \else \ifdim#1>45\p@ \advance#1-90\p@ \docos#1 % slowly work down to the right spot...! \else \begingroup \dimen@=.017453#1\relax %pi/180 -> rad \@tempdima=\mul\dimen@\dimen@ \advance\dimen@-.12\@tempdima \endgroupsetdim#1\dimen@ \fi \fi } \def\docos#1{% \ifdim#1<0\p@#1=-#1\relax\fi \ifdim#1>45\p@ \advance#1-90\p@ \dosin#1 % slowly work down to the right spot...! #1=-#1\relax \else \begingroup \dimen@=.017453#1\relax %pi/180 -> rad \dimen@=\mul\dimen@\dimen@ \@tempdima=1\p@ \advance\@tempdima-.48\dimen@ \endgroupsetdim#1\@tempdima \fi } \def\normalizeangle#1{ \ifdim#1>180\p@ \advance#1-360\p@\fi \ifdim#1>180\p@ \advance#1-360\p@\fi \ifdim#1<-180\p@ \advance#1360\p@\fi \ifdim#1<-180\p@ \advance#1360\p@\fi }