summaryrefslogtreecommitdiff
path: root/macros/latex209/contrib/misc/sines.tex
blob: 4d5cbc4daff5bb4299cd3eaa1199a4d9f658073f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% macros to calculate sines from 90 to -90
% Jim Walker,  Dept Mathematics,  University of South Carolina
\newdimen\x
\newdimen\y
\newdimen\xsquare
\newdimen\xfourth
{% change char codes
    \catcode`\p=12
    \catcode`\t=12
    \gdef\numonly#1pt{%
        \def\xx{#1}%
    }%
}%
\def\MULTyBYx{%
    \expandafter\numonly\the\x
    \edef\b{\y=\xx\y}%
    \b
}%
\def\calcsin{% Find sin(\x) and put it in \y. Say \x is in degrees.
    \x=0.0174533\x % Convert to radians.
    \y=\x
    \MULTyBYx
    \xsquare=\y
    \MULTyBYx
    \MULTyBYx
    \xfourth=\y
    \y=1pt
    \advance\y by -0.1666666\xsquare
    \advance\y by 0.008333333\xfourth
    \MULTyBYx
}%
% Example of use:
%\x=23pt \calcsin \expandafter\numonly\the\y
% Now \xx should contain the sine of 23 degrees.
%\def\sine#1{\x=#1 \calcsin \expandafter\numonly\the\y \message{sine of
%#1 is \xx}}
%----------------------------------------------------------
% given a box with width W and height H,  then its height after rotation by R
% is W * sin(R) + H * cos(R),  and it extends W * cos(R) to the right
% and H * sin(R) to the left
% (arithmetic courtesy of Nico Poppelier)
%
\newdimen\xh\newdimen\xw\newdimen\xtemp\newdimen\xcos\newdimen\xsin
\newdimen\xleft\newdimen\xright
\def\MULTxtempBYxcos{\expandafter\numonly\the\xcos\edef\b{\xtemp=\xx\xtemp}\b}%
\def\MULTxtempBYxsin{\expandafter\numonly\the\xsin\edef\b{\xtemp=\xx\xtemp}\b}%