
%\bigskip
\section{Geometry/Trigonometry Reference}
\bigskip
Illustration of geometric construction of trigonometric functions:

\includegraphics[height=2in]{images/Circle-trig}

Ranges of trig functions:
\begin{tabular}{l|l|l}
	any		&	$\cos$	&	-1 to 1 \\
	any		&	$\sin$	&	-1 to 1 \\
	any		&	$\tan$	&	any	\\
	-1 to  +1	&	$acos$	&	0 to $pi$ \\
	-1 to  +1	&	$asin$	&	$-pi/2$ to $pi/2$ \\
	any		&	$atan$	&	$-pi/2$ to $pi/2$
\end{tabular}

Finding point(s) of intersection of two circles:

\includegraphics[height=2in]{images/2circle1}

$$x_3 = x_2 +- h (y_1 - y_0)/d$$ 
$$y_3 = y_2 -+ h (x_1 - x_0)/d$$ 

% http://mathworld.wolfram.com/GausssCircleProblem.html
Number of lattice points inside a circle of radius $r$ centered at the origin
is 
$$N(r) = 1 + 4 \lfloor r \rfloor + 4 \sum_{i=1}^{\rfloor r \lfloor}{\lfloor \sqrt{r^2-i^2} \rfloor}$$
First few values are 1, 5, 13, 29, 49, 81...
\newpage
\subsection{Java Geometry}
\begin{lstlisting}
  P dir(P a, P b) {
     return new P(b.x - a.x,
                  b.y - a.y); }
  P perp(P a) {
     return new P(-a.y, a.x); }

 // a dot b = |a||b| cos theta
 // a dot a = |a|^2
 double dot(P a, P b) {
     return a.x*b.x +
            a.y*b.y; }

 // a x b = |a||b| sin theta = 2x triangle area
 // >0 if b is right of a, <0 if b is right of a
 double cross(P a, P b) {
     return dot(perp(a), b);
 }
 // Computes intersection of lines ab and cd.
 P intersect(P a, P b, P c, P d) {
    P ab = dir(a,b), cd = dir(c,d);
    double r0 = cross(dir(a,c), cd);
    double r = r0 / cross(ab, cd);
    return new P(a.x + r*ab.x,
                 a.y + r*ab.y);
 }
 // Closest point to C on line AB
 P closest(P a, P b, P c) {
    P ab = dir(a,b), ac = dir(a,c);
    double r = dot(ab,ac)/dot(ab,ab);
    return new P(a.x + r*ab.x,
                 a.y + r*ab.y);
 }
 double area(P a, P b, P c) {
    return cross(dir(a,b), dir(a,c));
 }
 double length(double[] v) {
    return Math.sqrt(dot(v,v));
 }
 double dot(double[] v, double[] z) {
     return v[0]*z[0]
          + v[1]*z[1]
          + v[2]*z[2];
 }

 // len of result = |v||z| sin theta
 double[] cross(double[] v,
                double[] z) {
     return new double[] {
         v[1]*z[2] - v[2]*z[1],
         v[2]*z[0] - v[0]*z[2],
         v[0]*z[1] - v[1]*z[0] };
 }
 double[] dir(double[] a,
              double[] b) {
     return new double[] {
         b[0] - a[0],
         b[1] - a[1],
         b[2] - a[2] }; }
\end{lstlisting}
%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "ref-doc"
%%% End: 
