function lightDir = getLightingDirection(brightSpot, center, radius)
% input: bright sport is a cell array and have the bright spot of the 10
% images. 'center' is the center of the chrome, and 'radius' is the radius
% of the chrome.

% output: the light direction. should be a cell array, and each element of
% the array is a vector for each image. There are 10 image, so the element
% of the lightDir should be 10.

% Need to change the cooridnate of the brightSpot based on the origin (the
% chrome center) of the coordinate.

K = length(brightSpot);     % number of the images.
for k = 1:K
    brightSpot{k}(1) = brightSpot{k}(1) - center(1);    % Get new coordinate X.
    brightSpot{k}(2) = brightSpot{k}(2) - center(2);    % Get new coordinate Y.
end;

Z = zeros(1,K);     % the z coordinate of the bright spot.
for k = 1:K
    Z(k) = sqrt(radius^2 - brightSpot{k}(1)^2 - brightSpot{k}(2)^2);
end;
    

%now normalized the vector ( from the origin to the bright spot).
% for k = 1:K
%     brightSpot{k}(1) = brightSpot{k}/radius;
%     brightSpot{k}(2) = brightSpot{k}(2)/radius;
%     Z(k) = Z(k)/radius;
% end;

% We then make the assumption that all light rays travel in parallel from
% the image plane to the camera lens, and all such rays are perpendicular
% to the plane themselves. This gives us the vector of light from the
% surface point to the camera v = (0,0,1). 
vecR = [0 0 1];
lightDir = cell(1,K);
vecN = zeros(1,3);
for k = 1:K
    vecN(1) = brightSpot{k}(1);
    vecN(2) = brightSpot{k}(2);
    vecN(3) = Z(k);
    vecN = vecN/norm(vecN);     % we normalized the normal vector here.
    lightDir{k} = 2 * (vecN * vecR') * vecN - vecR;
    lightDir{k} = lightDir{k}/norm(lightDir{k});
end;


    



