Skip to content
Snippets Groups Projects
Commit 3bad8d02 authored by lmaresz's avatar lmaresz
Browse files

SegmentedAperture

parent 9243caf5
No related branches found
No related tags found
No related merge requests found
...@@ -19,12 +19,12 @@ classdef Antenna ...@@ -19,12 +19,12 @@ classdef Antenna
end end
end end
function [rays, complex_amplitudes] = generateRays(obj, phi) function rays = generateRays(obj, phi) %TODO
rays(size(phi, 2)) = Ray; complexAmplitudes = obj.get_complex_amplitudes(phi);
for k = 1:size(phi, 2) rays(1) = Ray(obj.position, [cos(phi(1)), sin(phi(1))]);
rays(k) = Ray(obj.position, [cos(phi(k)), sin(phi(k))]); for k = 2:size(phi, 2)
rays(k) = Ray(obj.position, [cos(phi(k)), sin(phi(k))], complexAmplitudes(k-1));
end end
complex_amplitudes = obj.get_complex_amplitudes(phi);
end end
function rays = generateRaysB(obj, nRay) function rays = generateRaysB(obj, nRay)
...@@ -34,7 +34,7 @@ classdef Antenna ...@@ -34,7 +34,7 @@ classdef Antenna
minval = min(abs(obj.integral - randArray(j)*obj.integral(end))); minval = min(abs(obj.integral - randArray(j)*obj.integral(end)));
phiIndex = find(abs(obj.integral - randArray(j)*obj.integral(end)) == minval, 1, 'last'); phiIndex = find(abs(obj.integral - randArray(j)*obj.integral(end)) == minval, 1, 'last');
phiRay = phi(phiIndex); phiRay = phi(phiIndex);
rays(j) = Ray(obj.position, [cos(phiRay), sin(phiRay)], obj.phase(phiIndex)); rays(j) = Ray(obj.position, [cos(phiRay), sin(phiRay)], exp(1i*obj.phase(phiIndex)));
end end
end end
...@@ -47,6 +47,7 @@ classdef Antenna ...@@ -47,6 +47,7 @@ classdef Antenna
plot(obj.position.x, obj.position.y, 'kO', 'MarkerSize', 10); plot(obj.position.x, obj.position.y, 'kO', 'MarkerSize', 10);
end end
end end
methods(Access = protected) methods(Access = protected)
function complex_amplitudes = get_complex_amplitudes(obj, phi) function complex_amplitudes = get_complex_amplitudes(obj, phi)
n = size(phi, 2); n = size(phi, 2);
...@@ -77,3 +78,4 @@ classdef Antenna ...@@ -77,3 +78,4 @@ classdef Antenna
end end
end end
end end
...@@ -35,7 +35,7 @@ classdef BalazsAperture < Barrier ...@@ -35,7 +35,7 @@ classdef BalazsAperture < Barrier
function post_collide(obj, col, trace) function post_collide(obj, col, trace)
if (col.collided) %change from original if (col.collided) %change from original
i = floor(obj.nslice*(col.pos.y-obj.center.y+obj.size/2)/obj.size) + 1; i = floor(obj.nslice*(col.pos.y-obj.center.y+obj.size/2)/obj.size) + 1;
phase = trace.init_phase + 2*pi * mod(trace.length, trace.wavelength)/trace.wavelength; phase = angle(trace.complexAmplitude) + 2*pi * mod(trace.length, trace.wavelength)/trace.wavelength;
obj.collisions(i) = obj.collisions(i) + exp(1i*phase); obj.collisions(i) = obj.collisions(i) + exp(1i*phase);
end end
end end
......
...@@ -2,14 +2,14 @@ classdef Ray ...@@ -2,14 +2,14 @@ classdef Ray
properties properties
start Vect = Vect; start Vect = Vect;
dir Vect = Vect; dir Vect = Vect;
initPhase = 0; complexAmplitude = 0;
end end
methods methods
function obj = Ray(start, dir, initPhase) function obj = Ray(start, dir, complexAmplitude)
obj.start = start; obj.start = start;
obj.dir = dir; obj.dir = dir;
if nargin == 3 if nargin == 3
obj.initPhase = initPhase; obj.complexAmplitude = complexAmplitude;
end end
end end
end end
......
classdef SegmentedAperture < Barrier
properties
center Vect = Vect; % center position
size double = 0; % full size of reflector (end to end)
color = [0.5 0.5 0.5];
width = 2;
segments Segment;
prevTrace = Trace(Inf, Ray([0 0],[0 0], 0), 0, [], 0);
prevCol;
end
methods
function obj = SegmentedAperture(center, size)
if nargin == 2
obj.center = center;
obj.size = size;
end
end
function col = collide(obj, ray) % override this function with custom collision
col = Collision;
col.stop = true;
k = (obj.center.x - ray.start.x)/ray.dir.x;
col.pos = ray.start + k*ray.dir;
col.reflDir = Vect(-ray.dir.x, ray.dir.y);
if abs(col.pos.y - obj.center.y) < obj.size/2 && k*ray.dir.mag > 1e-6
col.collided = true;
else
col.collided = false;
end
end
function post_collide(obj, col, trace)
if trace.id == obj.prevTrace.id+1 && abs(trace.complexAmplitude) > 0
segmentSize = abs(obj.prevCol.pos.y - col.pos.y);
obj.segments(end+1) = Segment(obj.prevCol.pos.y, col.pos.y, abs(trace.complexAmplitude)/segmentSize);
end
obj.prevTrace = trace;
obj.prevCol = col;
end
function plot_self(obj)
plot([obj.center.x obj.center.x],...
[obj.center.y - obj.size/2, obj.center.y + obj.size/2],...
'LineWidth', obj.width, 'Color', obj.color);
end
end
end
...@@ -5,15 +5,15 @@ classdef Trace < handle ...@@ -5,15 +5,15 @@ classdef Trace < handle
wavelength; wavelength;
rays Ray; rays Ray;
length = +inf; length = +inf;
init_phase = 0; complexAmplitude = 0;
end end
methods methods
function obj = Trace(id, init_ray, wavelength, barriers, maxCol) function obj = Trace(id, initRay, wavelength, barriers, maxCol)
obj.id = id; obj.id = id;
obj.rays(1) = init_ray; obj.rays(1) = initRay;
obj.init_phase = init_ray.initPhase; obj.complexAmplitude = initRay.complexAmplitude;
obj.wavelength = wavelength; obj.wavelength = wavelength;
ncol = 0; ncol = 0;
...@@ -25,7 +25,7 @@ classdef Trace < handle ...@@ -25,7 +25,7 @@ classdef Trace < handle
for k = 1:size(barriers,2) for k = 1:size(barriers,2)
c = barriers(k).collide(obj.rays(ncol+1)); % get collision from the 'k'th barrier c = barriers(k).collide(obj.rays(ncol+1)); % get collision from the 'k'th barrier
if (c.collided) if (c.collided)
d = Vect.abs(c.pos - init_ray.start); d = Vect.abs(c.pos - initRay.start);
if d < dist if d < dist
dist = d; dist = d;
col = c; col = c;
...@@ -56,9 +56,9 @@ classdef Trace < handle ...@@ -56,9 +56,9 @@ classdef Trace < handle
length = obj.length; length = obj.length;
end end
function plot_trace(obj, stop, color, linewidth) function plot_trace(obj, stop, color, lineWidth)
if nargin < 4 if nargin < 4
linewidth = 1; lineWidth = 1;
end end
if nargin < 3 if nargin < 3
color = 'r'; color = 'r';
...@@ -73,7 +73,9 @@ classdef Trace < handle ...@@ -73,7 +73,9 @@ classdef Trace < handle
x(k) = obj.rays(k).start.x; x(k) = obj.rays(k).start.x;
y(k) = obj.rays(k).start.y; y(k) = obj.rays(k).start.y;
end end
plot(x, y, 'Color', color, 'LineWidth', linewidth); plot(x, y, 'Color', color, 'LineWidth', lineWidth);
end end
end end
end end
clear
close all
progressBar1 = waitbar(0,'Generating rays...','Name','Tracing rays...',...
'CreateCancelBtn','setappdata(gcbf,''canceling'',1)');
setappdata(progressBar1,'canceling',0);
reflectors = PlaneReflector.empty;
reflectors(end+1) = PlaneReflector([2 0], 2);
reflectors(end+1) = ParabolaReflector([0 0], 4, 3);
reflectors(end+1) = SegmentedAperture([3 0], 20);
n = 100;
wavelength = 3e8/1e9;
stepSize = n/100;
antenna = Antenna(Vect(1,0), [ones(1,125), zeros(1,750), ones(1,125)], zeros(1,1000));
rays = antenna.generateRays(linspace(0,2*pi,n));
figure(1);
plot(0, 0);
xlim([0 4]);
ylim([-4 4]);
hold on;
antenna.plot_antenna();
for k = 1:size(reflectors, 2)
reflectors(k).plot_self;
end
for k = 1:size(rays, 2)
if getappdata(progressBar1,'canceling')
break;
end
if mod(k, stepSize) == 0
waitbar(k/n,progressBar1,sprintf('Tracing rays... [%0.1f%%]',k/n*100));
end
traces(k) = Trace(k, rays(k), wavelength, reflectors, 5);
traces(k).plot_trace(4);
end
delete(progressBar1)
hold off;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment