close all;clear all;

Ai0 = [0, 1];Bi1 = [1, 0];

Bi0 = [.75, .75];
%Bi0 = [.25, .25];

D = Bi1 - Ai0;
L = Bi0 - Ai0;

Dx = [Ai0(1), Bi1(1)]; Dy = [Ai0(2), Bi1(2)];
Lx = [Ai0(1), Bi0(1)]; Ly = [Ai0(2), Bi0(2)];
figure, hold on;
plot(Dx, Dy, 'b');
plot(Lx, Ly, 'r', 'linewidth', 3);

L_par = D/norm(D)^2*dot(D, L);
L_perp = L - L_par;

COS_THETA = dot(L, D)/norm(L)/norm(D);
SIN_THETA = D(1)*L_perp(2) - D(2)*L_perp(1);
disp(['SIN_THETA = ', num2str(SIN_THETA)]);

L_par_x = [Ai0(1), Ai0(1) + L_par(1)]; L_par_y = [Ai0(2), Ai0(2) + L_par(2)];
L_perp_x = [L_par_x(2), L_par_x(2) + L_perp(1)]; L_perp_y = [L_par_y(2), L_par_y(2) + L_perp(2)];
plot(L_par_x, L_par_y, 'g', 'linewidth', 3);
plot(L_perp_x, L_perp_y, 'g', 'linewidth', 3);
axis equal;