
I have one curve. I want to create another curve offset to that one at right angle.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Prashant Dhabaliya
el 4 de Nov. de 2018
Respondida: Prashant Dhabaliya
el 4 de Nov. de 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 comentarios
Respuesta aceptada
Bruno Luong
el 4 de Nov. de 2018
Editada: Bruno Luong
el 4 de Nov. de 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 comentario
Bruno Luong
el 4 de Nov. de 2018
Be careful: such curve can cross it-self for large curvature and/or move with with large step.
Más respuestas (3)
Image Analyst
el 4 de Nov. de 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 comentarios
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!