Select Git revision
PlaneReflector.m 1.18 KiB
classdef PlaneReflector < Barrier
properties
center Vect = Vect; % center position
size double = 0; % full size of reflector (end to end)
color = 'k';
width = 3;
end
methods
function obj = PlaneReflector(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 = false;
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)
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