# Constructing an Offset-Curve

55 views (last 30 days)

Show older comments

Ben
on 2 Dec 2014

Commented: Robert Daly
on 23 May 2024 at 0:47

Probably this question has already been posted several times, however I was not able to find an answer.

I have a smooth curve given as a set of X and Y data points and I am trying to constrcut an offset curve. Bascially my strategie was to search for the perpendicular direction at each point of the given [X,Y] data set and then follow this direction according to the desired offset. This works well for convex curves. However for concave curves, there will be a setback at certain points.

This is actually a very common problem in CNC programming. Commercial CAD and CAM software packages mostly offer a solution to this problem. Unfortunately I was not able to find a solution in matlab. Maybe I am looking in the wrong place...

I would be glad if someone could share their knowledge.

Thanks in advance! Ben

##### 2 Comments

Will Walton
on 27 Mar 2015

### Accepted Answer

Unai San Miguel
on 28 Apr 2017

### More Answers (2)

alper yeldan
on 8 Dec 2021

It is an old question but I think I can explain a bit more. You shoul check this. If you know the equation of your function can express in x = [x(t), y(t)]. Parallel curve with a distance d can be expressed in Cartesian coordinates as:

x_d(t) = x(t) + d*dy(t) / sqrt(dx(t)^2 + dy(t)^2);

y_d(t) = y(t) - d*dx(t)/sqrt(dx(t)^2 + dy(t)^2);

From here you can easily plot the parallel curves in MATLAB, but it might not be possible in CAD programs, because these lines are generally NOT polynomial. If you want to see more examples check this link too.

##### 1 Comment

Robert Daly
on 23 May 2024 at 0:47

I had a similar question, thanks for your answer and links.

I had a bunch of points along a transect line and wanted to feed them in all at once rather than make a loop so I made a vectorised version of your answer. Thought it might help someone else out (58 views in the last 30 days).

x=[0:0.1:20];

m=1;

c = 2;

%y= m.*x+c %Test on a straight line

y= m.*x+sin(x) + c;

d= 1;

dx = [x(2)-x(1),diff(x)];

dy = [y(2)-y(1),diff(y)];

% Non vectorised

% x_d(t) = x(t) + d*dy(t) / sqrt(dx(t)^2 + dy(t)^2);

% y_d(t) = y(t) - d*dx(t)/sqrt(dx(t)^2 + dy(t)^2);

% Vectorised

x_d = x + d.*dy./sqrt(dx.^2 + dy.^2);

y_d = y - d.*dx./sqrt(dx.^2 + dy.^2);

figure

plot(x,y,'DisplayName','Original')

hold on

plot(x_d,y_d,'DisplayName','Offset')

axis equal

Matt J
on 2 Dec 2014

##### 5 Comments

Mohammad Abouali
on 2 Dec 2014

Matt, a simple translation of all points doesn't work. It is more complicated than just a simple translation of points.

And the goal is not just to keep the red and blue line parallel to each other. But also a t a certain distance from each other. So, depending on the curves and the distance they gradually actually reshape and change their form.

This is very common in CAD softwares. AutoCAD had it as long as I remember.

Matt J
on 2 Dec 2014

### See Also

### Categories

### Products

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!