
I have one curve. I want to create another curve offset to that one at right angle.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Prashant Dhabaliya
am 4 Nov. 2018
Beantwortet: Prashant Dhabaliya
am 4 Nov. 2018
%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;
0 Kommentare
Akzeptierte Antwort
Bruno Luong
am 4 Nov. 2018
Bearbeitet: Bruno Luong
am 4 Nov. 2018

%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 Kommentar
Bruno Luong
am 4 Nov. 2018
Be careful: such curve can cross it-self for large curvature and/or move with with large step.
Weitere Antworten (3)
Image Analyst
am 4 Nov. 2018
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;

0 Kommentare
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!