I have one curve. I want to create another curve offset to that one at right angle.

3 ビュー (過去 30 日間)
%initial conditions%
t = 0:0.01:1;
b0 = (1-t).^2;
b1 = 2.*t.*(1-t);
b2 = t.^2;
%point conditions%
p0 = [5,12];
p1 = [9,8];
p2 = [5,1];
P = [p0;p1;p2];
x = p0(1).*b0 + p1(1).*b1 + p2(1).*b2;
y = p0(2).*b0 + p1(2).*b1 + p2(2).*b2;
%c = (x(t),y(t))
%offset curve
%for 1st curve
Offx1= x + 1;
Offy1= y + 1;
plot(x,y)
hold on
%plot Bezier Curve offset
plot(Offx1,Offy1)
axis equal
hold off
grid on;

採用された回答

Bruno Luong
Bruno Luong 2018 年 11 月 4 日
編集済み: Bruno Luong 2018 年 11 月 4 日
%initial conditions%
t = 0:0.01:1;
b0 = (1-t).^2;
b1 = 2.*t.*(1-t);
b2 = t.^2;
B = [b0; b1; b2];
% derivative
b0p = -2*(1-t);
b1p = 2*(1-t) - 2*t;
b2p = 2*t;
Bp = [b0p; b1p; b2p];
%point conditions%
p0 = [5,12];
p1 = [9,8];
p2 = [5,1];
P = [p0; p1; p2];
xy = P'*B;
% rotate unit-tangent vector by 90 deg to find normal
xyp = P'*Bp;
xyp = xyp./sqrt(sum(xyp.^2,1));
normal = [0 -1;
1 0]*xyp;
% move points in the normal direction
step = sqrt(2);
xy1 = xy + step*normal;
Offx1 = xy1(1,:);
Offy1 = xy1(2,:);
x = xy(1,:);
y = xy(2,:);
plot(x,y)
hold on
%plot Bezier Curve offset
plot(Offx1,Offy1)
axis equal
hold off
grid on;
  1 件のコメント
Bruno Luong
Bruno Luong 2018 年 11 月 4 日
Be careful: such curve can cross it-self for large curvature and/or move with with large step.

サインインしてコメントする。

その他の回答 (3 件)

Image Analyst
Image Analyst 2018 年 11 月 4 日
Just don't add the offset to the y vector and it will be to the right and not to the right and up:
%initial conditions%
t = 0:0.01:1;
b0 = (1-t).^2;
b1 = 2.*t.*(1-t);
b2 = t.^2;
%point conditions%
p0 = [5,12];
p1 = [9,8];
p2 = [5,1];
P = [p0;p1;p2];
x = p0(1).*b0 + p1(1).*b1 + p2(1).*b2;
y = p0(2).*b0 + p1(2).*b1 + p2(2).*b2;
%c = (x(t),y(t))
%offset curve
%for 1st curve
Offx1= x + 1;
plot(x, y, 'b-', 'LineWidth', 2)
hold on
%plot Bezier Curve offset
plot(Offx1, y, 'r-', 'LineWidth', 2)
axis equal
hold off
grid on;

Prashant Dhabaliya
Prashant Dhabaliya 2018 年 11 月 4 日
Thank you Matt. I would like to create the curve attached to this file. I request you to see this one.

Prashant Dhabaliya
Prashant Dhabaliya 2018 年 11 月 4 日
Thank you Bruno Luong and Image analyst for your support.

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by