Skip to content

Commit

Permalink
Implement 1D point offset
Browse files Browse the repository at this point in the history
  • Loading branch information
nunofachada committed May 6, 2020
1 parent bdc4780 commit 08e9dad
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions generateData.m
Expand Up @@ -209,29 +209,44 @@
% along the line using either the uniform or normal distribution)
positions = distfun(lengths(i), clustPoints(i));

% Determine x coordinates of point projections
% Determine (x, y) coordinates of point projections on the line
points_x = cos(atan(slopes(i))) * positions;

% Determine y coordinates of point projections
points_y = points_x * slopes(i);

if strcmp(p.Results.pointOffset, '1D')
error('Not implemented');

% Get distances from points to their projections on the line
points_dist = lateralStd * randn(clustPoints(i), 1);

% Get perpendicular vectors to the current line for each point
perpVecs = [-sign(points_dist) * slopes(i) sign(points_dist)];
% Normalize vectors
perpVecs = perpVecs / norm([slopes(i) 1]);
% Set vector magnitudes
perpVecs = abs(points_dist) .* perpVecs;

% Add perpendicular vectors to point projections on the line,
% yielding point (x,y) coordinates
points_x = points_x + perpVecs(:, 1);
points_y = points_y + perpVecs(:, 2);

elseif strcmp(p.Results.pointOffset, '2D')

% Get point distances from line in x coordinate
points_x = points_x + lateralStd * randn(clustPoints(i), 1);

% Get point distances from line in y coordinate
points_y = points_y + lateralStd * randn(clustPoints(i), 1);

% Determine the actual points
data(cumSumPoints(i) + 1 : cumSumPoints(i + 1), :) = ...
[(xCenters(i) + points_x) (yCenters(i) + points_y)];
else
% We should never get here
error('Invalid program state');
end;

% Determine the actual points
data(cumSumPoints(i) + 1 : cumSumPoints(i + 1), :) = ...
[(xCenters(i) + points_x) (yCenters(i) + points_y)];

% Update idx
idx(cumSumPoints(i) + 1 : cumSumPoints(i + 1)) = i;
end;

0 comments on commit 08e9dad

Please sign in to comment.