"jason " <mcmains.1@osu.edu> wrote in message <gabct5$a7u$1@fred.mathworks.com>...
> please post if you can figure out any improvements to this code.
% --------------------------
function [X Y] = fcnlineoff(x, y, offset)
% find slope
m = diff(x + i*y);
% use average of slope on each side
% better result for large spaces between points
m = [m(1) (m(1:(end-1)) + m(2:end))/2 m(end)];
% calculate offset
vOff = offset*m*exp(-i*pi/2) ./ abs(m);
% generate ouput vectors
X = [x-real(vOff), fliplr(x+real(vOff))];
Y = [y-imag(vOff), fliplr(y+imag(vOff))];
% use to plot the normals
% X = [x+real(vOff); x; x-real(vOff)];
% Y = [y+imag(vOff); y; y-imag(vOff)];
end
% --------------------------
~Adam
note: both methods epically fail if there's ANY noise on the line
> please post if you can figure out any improvements to this code.
% --------------------------
function [X Y] = fcnlineoff(x, y, offset)
% find slope
m = diff(x + i*y);
% use average of slope on each side
% better result for large spaces between points
m = [m(1) (m(1:(end-1)) + m(2:end))/2 m(end)];
% calculate offset
vOff = offset*m*exp(-i*pi/2) ./ abs(m);
% generate ouput vectors
X = [x-real(vOff), fliplr(x+real(vOff))];
Y = [y-imag(vOff), fliplr(y+imag(vOff))];
% use to plot the normals
% X = [x+real(vOff); x; x-real(vOff)];
% Y = [y+imag(vOff); y; y-imag(vOff)];
end
% --------------------------
~Adam
note: both methods epically fail if there's ANY noise on the line