/* *******************  AngRecSp.cpp  *******************/
//C++2ltx+

#include <math.h>
#include "AngRecSp.h"

// \section{Definitions}

// {\bf Approximate vs. exact formulae}
char RecSpaceNearOriginApprox = 1;

extern double VelkeK;  //- I define it in ...I.h

/*
% \newpage

\section{Angular to reciprocal coordinates}

Transformation
$(\theta_1,\theta_2) \longrightarrow (Q_x,Q_z)$.
Note: it uses the global value \||VelkeK|$=\displaystyle\frac{2\pi}{\lambda}$.
*/

void QxQz_from_Theta1Theta2 (
  double& Qx, double& Qz, double Theta1, double Theta2 ) {
if (RecSpaceNearOriginApprox) {
    Qz = VelkeK * ( Theta1 + Theta2 ); //+ $Q_z=K(\theta_1+\theta_2)$
    Qx = Qz * ( Theta1 - Theta2 ) /2;  //+ $Q_x=\frac K2(\theta_1^2-\theta_2^2)$
    }
 else {
    Qz = VelkeK * ( sin(Theta2)+sin(Theta1) ); //+ $Q_z=K(\sin\theta_1+\sin\theta_2)$
    Qx = VelkeK * ( cos(Theta2)-cos(Theta1) ); //+ $Q_x=K(\cos\theta_1-\cos\theta_2)$
    }
}


/*+
\section{Reciprocal to angular coordinates}

Transformation
$(Q_x,Q_z) \longrightarrow (\theta_1,\theta_2)$.
Note: it uses the global value \||VelkeK|$=\displaystyle\frac{2\pi}\lambda$.
*/

void Theta1Theta2_from_QxQz (
 double& Theta1, double& Theta2, double Qx, double Qz) {
if (Qz==0) { Theta1=Theta2=0; return; }
double sigma, delta;
if (RecSpaceNearOriginApprox) {
    /*+ $\theta_1=\frac{Q_z}{2K}+\frac{Q_x}{Q_z}$ \quad
	$\theta_2=\frac{Q_z}{2K}-\frac{Q_x}{Q_z}$  */
    sigma = Qz/(2*VelkeK);
    delta = Qx/Qz;
    Theta1=sigma+delta; Theta2=sigma-delta; }
  else {
    /*+ $\theta_1=\atan \frac{Q_x}{Q_z}-\asin\frac{|Q|}{2K}$ \quad
	$\theta_2=\atan \frac{Q_x}{Q_z}+\asin\frac{|Q|}{2K}$ */
    sigma = asin ( sqrt( Qx*Qx+Qz*Qz ) / (2*VelkeK) );
    delta = atan ( Qx/Qz );
    Theta1=sigma-delta; Theta2=sigma+delta; }
};


//- eof AngRecSp.cpp


/*
\newpage
\section{Now some trip and trap test, nothing to do with X-rays:}
*/ 

//C++2ltx-

/* 5 full line comment */
/* 6 full line comment which is veeerry looong ze by se nam z toho chtelo straslive moc plakat, ne? */ 
/* ū | !
7 ahojūline with comment 
8 full line which is 
*/
/*+
10 helemeSeNaNeho \LaTeX{} cau a tak nevim co si o tom mam myslit, \TeX{}u. Ty prvni radek, druhy i treti radek by mohly byt OK? prvni radek, druhy i treti radek by mohly byt OK? snad jo? 
11 helemeSeNaNeho \LaTeX{} cau a tak nevim co si o tom mam myslit, \TeX{}u. Ty prvni radek, druhy i treti radek by mohly byt OK? prvni radek, druhy i treti radek by mohly byt OK? snad jo? 
*/

