%This program gives the spot position on the two PSDs as a function of the wire position.
%All length dimensions are in mm.  Angles are in degrees.

%Inputs
l1 = 30;
l2 = 3;
alpha = 45;
x = [-20:1:20];
y = 0;

%Compute s1 and s2
alpha_rad = alpha * pi / 180.;
s1 = l2 * (cos(alpha_rad) .* x - sin(alpha_rad) .* y) ./ ...
        (sin(alpha_rad) .* x + cos(alpha_rad) .* y + l1);
s2 = -l2 * (cos(alpha_rad) .* x + sin(alpha_rad) .* y) ./ ...
        (-sin(alpha_rad) .* x + cos(alpha_rad) .* y + l1);
    
%Plot the results
figure
plot(x, s1)
xlabel('Xwire (mm)')
ylabel('S1 (mm)')
title('Left Sensor Image Position vs Wire X Position')
grid on

figure
plot(x, s2)
xlabel('Xwire (mm)')
ylabel('S2 (mm)')
title('Right Sensor Image Position vs Wire X Position')
grid on
