function f = lecture4_1

[x,y,z] = sphere(20);
figure
h = surface(x,y,z);
set(h,'EdgeColor','none', ...
      'FaceColor','b', ...
      'FaceLighting','phong', ...
      'AmbientStrength',0.3, ...
      'DiffuseStrength',0.8, ...
      'SpecularStrength',0.9, ...
      'SpecularExponent',25, ...
      'BackFaceLighting','lit');
view(3)

hold on
camlight left;
hidden off

da = .5;
s=.4;
for theta = 0:da:pi,
  for phi = -pi:da:pi,
    [p, J] = S2_point([theta, phi]);
    plot3(p(1), p(2), p(3), '.')
    quiver3(p(1), p(2), p(3), s*J(1,1), s*J(2,1), s*J(3,1), 'r', 'LineWidth',2);
    quiver3(p(1), p(2), p(3), s*J(1,2), s*J(2,2), s*J(3,2), 'g', 'LineWidth',2);

%    v = J*[-theta; 
%           -phi];

%    quiver3(p(1), p(2), p(3), s*v(1), s*v(2), s*v(3), 'y', 'LineWidth',3);

    
    %    quiver3(p(1), p(2), p(3), J(1,2), J(2,2), J(3,2));
  end
end



function [p, J] = S2_point(x)
% spherical to cartesian map

x(1) = x(1) + pi/4;

c1 = cos(x(1));
s1 = sin(x(1));
c2 = cos(x(2));
s2 = sin(x(2));

p = [s1*c2; s1*s2; c1];

J = [c1*c2, -s1*s2;
     c1*s2, s1*c2;
     -s1,   0];
