/*
 * Author: Paul Koshevoy
 * Parameters.java  Tue, Feb 3 1998, 23:00:00 1998
 */

public class Parameters
{
public double PI; // Pifogorian constant

public double H2; // height of second mirror
public double HT; // height of the screen
public double WD; // height of the screen
public double D1; // distance d1
public double S1; // distance S1
public double S2; // distance S2
public double G1; // angle gamma1
public double G2; // angle gamma2
public double P1; // angle phi1
public double P2; // angle phi2
public double T1; // angle theta1
public double B1; // beta one angle
public double R1; // radius r1
public double R2; // radius r2
public double I;  // Z-component of upper corner screen coordinates
public double J;  // Y-component of upper corner screen coordinates
public double K;  // Z-component of lower corner screen coordinates
public double L;  // Y-component of lower corner screen coordinates
public double dP; // delta phi
public double dG; // delta gamma
    
private m3x3 M;   // matrix to rotate hit point into world coord system
    
// d1     - distance between laser emmiter and first reflection point
// s2     - distance between first reflection point and second reflection point
// gamma1 - arbitrary mimimal angle at which laser may hit second mirror ( gamma1 > 0)
// ht     - height of the screen
// a      - a-component of a/b ratio between height and width of the screen
// b      - b-component of a/b ratio between height and width of the screen
// r1      - radius of the first slashed-cylinder (mirror)
// r2      - radius of the second half-cylinder (mirror)
public Parameters(double d1, double s2, double gamma1, double ht, double a, double b, double r1, double r2)
    {
	PI = 4*Math.atan(1);
	
	D1 = d1;
	S2 = s2;
	G1 = gamma1;
	HT = ht;
	B1 = Math.atan2(D1, S2)/2;
	T1 = PI - G1 - G1 - B1 - B1;
	S1 = HT/(2*Math.sin(T1/2));
	G2 = Math.PI/2 - B1;
//	H2 = S2*b/a;
	H2 = 2*S2*b/a;
	P2 = Math.atan2(S2, H2/2);
	P1 = Math.PI - P2;
	R1 = r1;
	R2 = r2;
	WD = b*HT/a;
	I  = S1*Math.sin(2*G1);
	J  = S1*Math.cos(2*G1);
	K  = S1*Math.sin(2*B1);
	L  = S1*Math.cos(2*B1);
	dP = P1 - P2;
	dG = G2 - G1;

	M = m3x3.rotx(Math.atan2(I-K, J+L));
    }

public int get_x(v3x1 hit, int sx)
    {
	return (int)((WD/2 + hit.x)/WD*sx);
    }

public int get_y(v3x1 hit, int sy)
    {
	hit = M.times(hit);
	return (int)((HT/2 + hit.y)/HT*sy);
    }
}

