%% MATLAB script to draw figures in rectangular coordinates from local solutions data
% W. A. Bukhsh May, 2013

clear all
close all
clc
%% Switches for graph view
right_half=1; %draw only right half plan
fourth_quad=0; %draw only fourth quadrant

%Load data for local solutions
%datafile = 'WB2data_2solns.mat';
%datafile = 'WB3data_2solns.mat';
%datafile = 'WB5data_2solns.mat';
%datafile = 'LMBM3.mat';
%datafile = 'case9data_4solns.mat';
%datafile= 'case22loopdata_2solns.mat';
%datafile= 'case39data_2solns_quadratic';
%datafile= 'case39data_16solns_linear';
%datafile= 'case118data_3solns';
datafile= 'case300data_7solns';
load(datafile)
for q=1:numel(ACsol)
    
    sol=q;
    figure(q)
    hold on
    c=1;
    vmin=params.Vmin(1,2);
    vmax=params.Vmax(1,2);

    for p=1:size(params.A,1)
        p1(c:c+1)=[ACsol(sol).v(sets.B==params.A(p,2))*cos(ACsol(sol).delta(sets.B==params.A(p,2))) ACsol(sol).v(sets.B==params.A(p,3))*cos(ACsol(sol).delta(sets.B==params.A(p,3)))];
        p2(c:c+1)=[ACsol(sol).v(sets.B==params.A(p,2))*sin(ACsol(sol).delta(sets.B==params.A(p,2))) ACsol(sol).v(sets.B==params.A(p,3))*sin(ACsol(sol).delta(sets.B==params.A(p,3)))];
        c=c+2;

    end
    plot(p1,p2,'or','MarkerFaceColor','r','MarkerSize',5)
    plot(p1,p2,'--r','LineWidth',1.5) 

    tmin=linspace(-vmin,vmin,1000);
    tmax=linspace(-vmax,vmax,1000);
    plot(tmin,sqrt(vmin^2-tmin.^2),'--g');
    plot(tmin,-sqrt(vmin^2-tmin.^2),'--g');
    plot(tmax,sqrt(vmax^2-tmax.^2),'--g');
    plot(tmax,-sqrt(vmax^2-tmax.^2),'--g');
    plot(0,0,'og','MarkerFaceColor','g','MarkerSize',5)
    axis equal
    if right_half
        q=axis;
        axis([0 q(2) q(3) q(4)]);
    elseif fourth_quad 
        q=axis;
        axis([0 q(2) q(3) 0]);
    else
        axis equal
    end
  %  title(['Local Solution ' num2str(q)], 'FontSize', 15)
    
end

%% Save figures as jpg files
 for q=1:numel(ACsol)
     print(figure(q),'-djpeg','-r650',[ datafile(1:end-4) '_sol' num2str(q)]);
 end