function [ distance ] = IRSensorRight45All( coords, rectangles,...
    numberOfRectangles, sensorx, sensory, sensorTheta)
%UNTITLED3 Summary of this function goes here
%   Detailed explanation goes here
    distance = -1;
    intersectionx = 0;
    intersectiony = 0;
    
    for i = 1:numberOfRectangles
        rect = rectangles(i, :);
        [thisDistance, thisIntx, thisInty] = IRSensorRight45(rect, sensorx, sensory, sensorTheta); 
        if (distance == -1 || (thisDistance > 0 && thisDistance < distance))
            distance = thisDistance;
            intersectionx = thisIntx;
            intersectiony = thisInty;
        end
    end
    
    %have IR also react to other cars
    %check car 1:
    car1x = coords(1, 1);
    car1y = coords(1, 2);
    car1theta = coords(1, 3);
    thisDistance = IRSensorCarRight45(sensorx, sensory, sensorTheta, car1x, car1y, car1theta);
    if (distance == -1 || (thisDistance > 0 && thisDistance < distance))
        distance = thisDistance;
    end
    
    %check car 2:
    car2x = coords(2, 1);
    car2y = coords(2, 2);
    car2theta = coords(2, 3);
    thisDistance = IRSensorCarRight45(sensorx, sensory, sensorTheta, car2x, car2y, car2theta);
    if (distance == -1 || (thisDistance > 0 && thisDistance < distance))
        distance = thisDistance;
    end
end
