a b/createmainimage.m
1
function [ im_main ] = createmainimage(Xus,r,theta,num_pixel)
2
3
%%%this code block is used to create the images %%%%%
4
%%%later part of this code block is used to save images %%%%%%%
5
6
%%theta=(2*pi)/180; %in radian
7
%%r=2;
8
%%Xus=10;
9
angle=-(pi/10):theta:(pi/10);  %%outf this angle no images are taken 
10
[alpha,beta]=size(angle);
11
%num_pixel=Xus/0.1;
12
13
im=zeros(Xus/0.1,Xus/0.1,beta);
14
for alpha=1:beta
15
    notice=waitbar(0,'loading visualization at an angle, please wait...');
16
    % Define the input grid (in 3D) %%that sutta code
17
    figure;
18
    
19
    [x3, y3, z3] = meshgrid(linspace(-10,10));
20
    % Compute the implicitly defined function x^2 + (y-6)^2 + z^3 - 2^2 = 0
21
    f1 = x3.^2 + (y3-6).^2 + z3.^2 - 2^2;                    %%why is this taking an elipse 
22
23
    % This surface plane, which can also be expressed as
24
    f2 = z3-tan(angle(alpha))*y3 - 0*x3.^3 ;
25
    % Also compute plane in the 'traditional' way.
26
    [x2, y2] = meshgrid(linspace(-10,10));
27
    z2 = tan(angle(alpha))*y2 - 0*x2;
28
    % Visualize the two surfaces.
29
    patch(isosurface(x3, y3, z3, f1, 0), 'FaceColor', [0.5 1.0 0.5], 'EdgeColor', 'none');
30
    patch(isosurface(x3, y3, z3, f2, 0), 'FaceColor', [1.0 0.0 0.0], 'EdgeColor', 'none');
31
    view(3); camlight; axis vis3d;
32
    set(gca,'xlim',[-5 5 ], 'ylim',[1 11], 'zlim',[-5 5]);
33
    xlabel('X');ylabel('Y');zlabel('Z');
34
    
35
    %title('visualization at',angle(alpha),'radians');
36
    
37
    
38
    % Find the difference field.
39
    f3 = f1 - f2;
40
    % Interpolate the difference field on the explicitly defined surface.
41
    f3s = interp3(x3, y3, z3, f3, x2, y2, z2);
42
43
    % Find the contour where the difference (on the surface) is zero.
44
    C = contours(x2, y2, f3s, [0 0]);
45
    % Extract the x- and y-locations from the contour matrix C.
46
    xL = C(1, 2:end);
47
    yL = C(2, 2:end);
48
    % Interpolate on the first surface to find z-locations for the intersection
49
    % line.
50
    
51
    if ~isempty(xL) & ~isempty(yL) 
52
        zL = interp2(x2, y2, z2, xL, yL);
53
        % Visualize the line.
54
        line(xL,yL,zL,'Color','k','LineWidth',3);
55
56
        %xL_1=ceil(xL/0.2)+50; %conversion to pixels
57
        %yL_1=ceil(yL/0.2)+50; %conversion to pixels   %%commented since errors
58
59
        max_xL=max(xL);
60
        min_xL=min(xL);
61
        max_yL=max(yL);
62
        min_yL=min(yL);
63
64
        
65
        %%direct substuition into eclipse formula
66
        a=(max_xL-min_xL)/2; %average to reduce errors
67
        b=(max_yL-min_yL)/2; 
68
69
        a=a/0.1;        %convertion to pixels
70
        b=b/0.1;
71
72
        H=0;Y=0; %center of the eclipse
73
        for i=1:num_pixel
74
            for j=1:num_pixel
75
                    if ((i-num_pixel/2)/a)^2+((j-num_pixel/2)/b)^2 <= 1 %no need to worry about the world cordinates for now
76
                        im(i,j,alpha)=255;
77
                    end
78
            end
79
        end
80
    end
81
    
82
%figure, 
83
%imshow(im);
84
    close(notice)
85
end
86
87
88
%%%%%%image save%%%%%%%%
89
90
%%% a total of 61 image slices will be saved <as 0 is included as well>%%%%%%%%
91
%%% need to add a total of 21 empty images both at the front and back %%%%%%%%% 
92
93
im_main=zeros(Xus/0.1,Xus/0.1,61);
94
for i=[22:40]
95
    im_main(:,:,i)=im(:,:,i-21);
96
end
97
98
%%run this loop if you wish to save the images
99
 %%image_index=1;
100
 %%filename = 'p%d.bmp';
101
 %%filename = sprintf(filename,image_index);
102
 %%image_index = image_index + 1;
103
 %%imwrite(im,filename);
104
    
105
im_main=uint8(im_main);
106
end
107