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