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

조회 수: 2 (최근 30일)
Diaa
Diaa 2023년 7월 24일
댓글: Dyuman Joshi 2023년 8월 7일

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.

답변 (1개)

Shushant
Shushant 2023년 8월 7일
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
Diaa
Diaa 2023년 8월 7일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by