Reordering radiation value at particular point calculated in Spherical system and converted to Cartesian coordinate system for plot counter slice.

15 views (last 30 days)
I calculate irradiation value coming out from LED using spherical system in defined Meshgrid. Then I defineed one more meshgrid of cartesian coordinate system for plot. Then I convert Spherical coordinate to cartesian coordinate but my calculated radiation intensity is still related to spherical coordinate system so that I reorder it.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initializing
variables;
% End Initialization
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% User Input to size graphs
stepSize = .1; %cm
xGridMin = -10; %cm
xGridMax = 10; %cm
yGridMin = -10;
yGridMax = 10;
zGridMin = 0;
zGridMax = 10;
%%%%%%%%%%%%%%%%%%%%
% Set Up Spherical and Cartesian Space
%%%%%%%%%%%%%%%%%%%
%creates values for azimuth, elevation, and r
azInitial = linspace(-179,180, 360); %degrees
elInitial = linspace((90-va),90, 100); %degrees, limits elevation to
values within visual angle
rInitial = linspace(.1,zGridMax, 100); %cm
[az,el,r] = meshgrid(azInitial,elInitial,rInitial); %creates grid for
all az (degrees), el (degrees), and r (cm) values
%%%%%%%%%%%%%%%%%%%%
% Size graphs
xSteps = ((xGridMax - xGridMin)/stepSize)+1; %cm
ySteps = ((yGridMax - yGridMin)/stepSize)+1;
zSteps = ((zGridMax - zGridMin)/stepSize)+1;
x1 = linspace(xGridMin,xGridMax,xSteps); %tenths
y1 = linspace(yGridMin,yGridMax,ySteps);
z1 = linspace(zGridMin,zGridMax,zSteps);
[xGraph,yGraph,zGraph] = meshgrid(x1,y1,z1); % creates x,y,z matrixes
to describe the points in the 'intensity' matrix
%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculate Irradiance
irradiance = irradiance(az,el,r,va,p); % power function calculates power at each spherical coordinate [uW/cm^2]
% End Irradiance Calculations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Convert Spherical to Cartesian Coordinates, Move Cartesian Coordinates to
% Closest Grid and ReOrder Matrix
[x,y,z] = sph2cart(deg2rad(az),deg2rad(el),r); %converts az, el, r
spherical coordinates to x, y, z cartesian coordinates
xMoved = conversion(x, stepSize); %moves x,y,z coordinates to closest
evenly spaced x,y,z grid, spaced .1 cm
yMoved = conversion(y, stepSize);
zMoved = conversion(z, stepSize);
irradianceOrdered = reOrder(irradianceAbsorption, xMoved, yMoved,zMoved); %re-orders x,y,z, and intensity matrixes to later graph them
% 201x201x101 matrix representing x:-10:.1:10, y:-10:.1:10, z:0:.1:10
%Single Bulb Graphs
vSingle = irradianceOrdered ./ 1000; %converts irradiance from uW to mW
%%%%%%%%%%%%%%%%
figure
contourslice(xGraph,yGraph,zGraph,vSingle,[xGridMin:.5:xGridMax],[yGridMin:.5:yGridMax],[zGridMin:.5:zGridMax],linspace(0.1,1000,100));%shoulder region, mW/cm^2 shows
Conversion function
% converts spherical to cartesian coordinates
function [ oMoved ] = conversion(o, stepSize)
oSize = size(o);
% step = .1; %tenths
newValue = -10:stepSize:10;
for i = 1:oSize(1);
for j = 1:oSize(2);
for k = 1:oSize(3);
z = 1;
while o(i,j,k) ~= newValue(z);
if o(i,j,k) >= newValue(z)-.5*stepSize && o(i,j,k) <
newValue(z)+.5*stepSize;
o(i,j,k) = newValue(z);
else z = z + 1;
end
end
end
end
end
oMoved = o(:,:,:);
end
I have reorder function but actually I did not getting it. Please anyone can help me to understand this function and how its works.
% orders intensity points by increasing values of x,y, and z
function [ irradianceReorder ] = reOrder(irradiance, xMoved, yMoved,zMoved)
intensSize = size(irradiance);
irradianceReorder = zeros(201,201,101); %tenths
for i = 1:intensSize(1);
for j = 1:intensSize(2);
for k = 1:intensSize(3);
a = xMoved(i,j,k);
b = yMoved(i,j,k);
c = zMoved(i,j,k);
% a1 = (a*100)+1001; %hundreths
% b1 = (b*100)+1001;
% c1 = (c*100)+1;
a1 = (a*10)+101; %tenths
b1 = (b*10)+101;
c1 = (c*10)+1;
irradianceReorder(round(a1),round(b1),round(c1)) = irradiance(i,j,k) + irradianceReorder(round(a1),round(b1),round(c1));
%tenths, need round so indeces are not 1.00, 2.00 etc...
% intensity(a+11,b+11,(c*10)+1) = intens(i,j,k) +
intensity(a+11,b+11,c+1); %whole numbers
end
end
end
end
I also welcome alternative method to plot directly irradiance value with spherical cordinate system mesh grid.

Answers (0)

Categories

Find more on Solar Power in Help Center and File Exchange

Products


Release

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!