image thumbnail
from Forming ray lines for plots by Michael Chan
The objective is to construct different line beams.

rayLinesScheme_fan (numberOfLines, ...
function [x y numberOfLines_total totalNumberOfBeamSets] = rayLinesScheme_fan (numberOfLines, ...
    upperBound, lowerBound, degreeStepSize, ...
    fanningLeftRange, fanningRightRange, ...
    centerShiftedBy_x, centerShiftedBy_y, ... % centroid of fan beams
    rangeForXandY)

% clear all;
% clc;
% 
% upperBound = 3;
% lowerBound = -3;

%numberOfLines = 10;
stepSize = (upperBound - lowerBound)/numberOfLines;
%rangeForXandY = lowerBound:stepSize:upperBound;

x = rangeForXandY;

%lowerRange = -3;
%upperRange = 3;
    
% determines the fanning out of the lines, ie. how widely spread they are
% apart

% fanningLeftRange = 45;          % 0;
% fanningRightRange = (180-45);   % 180;

  % degreeStepSize = 5;
  degreeRanges = fanningLeftRange:degreeStepSize:fanningRightRange;  % rotation
  radianRanges = degreeRanges*(pi/180);
  gradient = tan(radianRanges);
  numberOfLines = length(degreeRanges);
  
%for j = 1:numberOfRotations
   for i = 1:numberOfLines 
      y(i,:) = (gradient(i)*x);
      % y(i) = 1;
   end
   
%    centerShiftedBy = [-3 -3];
%    centerShiftedBy = [0 0];
%    centerShiftedBy = [0 -3];
    centerShiftedBy = [centerShiftedBy_x centerShiftedBy_y];
   
   x = x + centerShiftedBy(1, 1);
   y = y + centerShiftedBy(1, 2);
   
    %   plot 1 fan set
    plot(x, y, '--');               % plot lines
    axis([lowerBound upperBound lowerBound upperBound]);
    grid on;   
   
   degreeStepSize = 10;
   degree_angle_range = [0:degreeStepSize:360];
   center = [0 0];
   numberOfSetsOfLineArray = length(degree_angle_range);
   
   fanLineArraySetsCollection = [];
   
   count = 0;
    for ang = degree_angle_range
        for i =   1:numberOfLines % (per set)
            coord = [x' y(i,:)'];
   
            lineRotated = rotateCoordinates(coord, center, ang);
            % hold off;
            plot(coord(:,1),coord(:,2),'b*-');
            axis([lowerBound upperBound lowerBound upperBound]);
            hold on;
            plot(lineRotated(:,1), lineRotated(:,2),'r+-');
            
            count = count + 1;
            % fanLineArraySetsCollection = [fanLineArraySetsCollection; lineRotated(:,1), lineRotated(:,2)];                      
            fanLineArraySetsCollection(count,:) = lineRotated(:,2);                      
            x_new(count,:) = lineRotated(:,1);
            
            % plot(center(1),center(2),'xk');
        end
            pause(0.3);
            % close;
    end   

    % title('Clockwise by degrees');
    
    % close all;
    

% plot(fanLineArraySetsCollection(:,1), fanLineArraySetsCollection(:,2));
%     axis([lowerBound upperBound lowerBound upperBound]);
%     grid on;

    % x = fanLineArraySetsCollection(:,1);
    % y = fanLineArraySetsCollection(:,2);
    x = x_new;
    y = fanLineArraySetsCollection;
    
 %fprintf('Lines done (percentage) : %s %%\n', num2str((i/numberOfLines)*100));
%  figure,
%     plot(x, y, '--');               % plot lines
%     axis([lowerBound upperBound lowerBound upperBound]);
%     grid on;
%     pause (0.5);
%     close all;
%end


numberOfLines_total = numberOfLines*count;

    % Caveat: For plotting outside the function, total number of sets is required
    % to assist in breaking the [x y] into groups of sets
    totalNumberOfBeamSets = length(degree_angle_range);

end


Contact us