From: William Murray on
I have a list of xy points (around 1000) and am trying to be able to graph a line that is offset from these xy points. It works well if the line curves in a convex way, but when any area of the line is concave it doubles back on itself. I wrote this function that will take x y points and offset the points by a certain amount:

function [x2,y2] = offsetxy(x,y,offset)

for i = 1:length(x)
if i == 1
temp(i,1) = (y(i+1,1) - y(i,1))/(x(i+1,1) - x(i,1));
else
temp(i,1) = (y(i,1) - y(i-1,1))/(x(i,1) - x(i-1,1));
end
end

for i = 1:length(temp)
m(i,1) = -1*(1/temp(i,1));
theta(i,1) = atan(m(i,1));
x2(i,1) = offset*cos(theta(i,1)) + x(i,1);
y2(i,1) = offset*sin(theta(i,1)) + y(i,1);
end

Try plugging in some points that make a convex line and you will see where it doesnt work. I know why it doesn't but I cant come up with a good way to fix it.

Thanks.
From: dpb on
William Murray wrote:
> I have a list of xy points (around 1000) and am trying to be able to
> graph a line that is offset from these xy points. ...

OK, let's start at the basics...what would be your definition of
"offset" for the example you go on to say is unsatisfactory?

One could simply displace x or y and meet a perfectly adequate
definition of "offset" w/o additional qualifications or restrictions and
requirements.

--