How to create two paths parallel to a non-uniform curve on its both sides?

1 view (last 30 days)

Suppose I have a path y that can be defined in different ways x1 = 1:0.1:20;

y1 = [3*x1(1:20) + 6, ... 5*x1(21:100) - 9, ... -2*x(101:end)];

% or

x2 = 0:0.1*pi:pi;

y2 = [sin(x2(1:5)), cos(2*x2(6:end))];

% or

x3 = [0, 5, 10, 10];

y3 = [5, -5, 15, 20]; how can I create two paths/curves parallel to y on its both sides with a constant offset (euclidean distance) = 1? I need to find the two parallel paths for each case of the three given above knowing that I need the parallel paths start and end at the normal vectors to the curve at the start and end points, respectively.

Answers (1)

Shushant
Shushant on 7 Aug 2023
Hi Diaa,
I understand you want to plot two lines parallel to your curve "y" with "offset = 1". To achieve this, you can define a simple function which returns two lines "lower_y" and "upper_y" which are parallel to the line "y" and are at an “offset” of 1. Then all the three lines can be plotted together to get the desired result.
The following code demosntrates the same -
x1 = 1:0.1:20;
y1 = [3*x1(1:20) + 6, ...
5*x1(21:100) - 9, ...
-2*x1(101:end)];
figure;
myplot(x1,y1);
x2 = 0:0.1*pi:pi;
y2 = [sin(x2(1:5)), cos(2*x2(6:end))];
figure;
myplot(x2,y2);
x3 = [0, 5, 10, 10];
y3 = [5, -5, 15, 20];
figure;
myplot(x3,y3);
% function that plots the lines
function myplot(x,y)
[uy, ly] = parallel_lines(y, 1); % define the value of offset
plot(x,y);
hold on;
plot(x,uy);
plot(x,ly);
hold off;
end
%function that returns lines parallel to y
function [upper_y, lower_y] = parallel_lines(y, offset)
upper_y = y + offset;
lower_y = y - offset;
end
Refer to the following documentation for more information on functions -
I hope this provides you with the required information regarding your query.
Thank you,
Shushant
  3 Comments
Diaa
Diaa on 7 Aug 2023
Thanks for your answer. However, the main issue is to keep the euclidean distance the same in any direction, not just in the y-direction.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!