- Radius can be the magnitude
- Adjust the period to achieve the desired length.
Creating curved line with given parameters
4 views (last 30 days)
Show older comments
Róbert Straka
on 17 Mar 2021
Edited: Cris LaPierre
on 17 Mar 2021
Hello
I want to ask if there is easier way to creat a curved line or an arc with given parameters then the way I'm doing it right now. First I creat 2 bigger curved lines, that consist of two lines and a circle between them, that cross each other and find the coordinates of the point where they cross each other as seen on the picture below.

Then I fillter out everything that is under the cross point and only take points that are starting on that cross to plot the curved lines I need as seen below.

My question is if it is possible to skip the first step completely and to creat only the curved lines on the second image if the angles, radius and a length is given. Down below is a code for how I generate all of this.
%Equations for generating x,y coordinates
clc
pz = 6;
radius = 0.8;
length = 0.15;
ap = 0.1;
po = 101.6;
dx = 10^(-pz);
angel1 = 89;
angel2 = 89;
xa = (radius*(sin(angel1)))*-1;
xb = radius*(sin(angel2));
ya = (xa*(tan(angel1)))+(radius/(cos(angel1)))-radius;
%Straight line A
N = 10^(pz);
xpA = xa - (0:N-1)*dx;
xpA = xpA';
xpA = sort(xpA);
xpA = round(xpA,pz);
ypA = (xpA*tan(angel1))+(radius/(cos(angel1)))-radius;
ypA = sort(ypA);
ypA = round(ypA,pz);
%Straight line B
xpB = xb + (0:N-1)*dx;
xpB = xpB';
xpB = round(xpB,pz);
ypB = (-xpB*tan(angel2))+(radius/(cos(angel2)))-radius;
ypB = round(ypB,pz);
%circle
N1 = 2*N;
xk1 = xa + (1:N1)*dx;
xk1 = round(xk1,pz);
xk1 = xk1';
[c,d]= intersect(xk1,min(xpB));
xk = xa +(1:d-1)*dx;
xk = round(xk,pz);
xk = xk';
yk = (sqrt((radius^2)-(xk.^2)))-radius;
yk = round(yk,pz);
%tool shape
X = [xpA;xk;xpB];
Y = [ypA;yk;ypB];
b = po-ap;
x = X(1);
X1 = X-x;
Y1 = Y+b;
X2 = X1+length;
Y2 = Y1;
%coordinates of the point where two tool paths cross each other
[Y1max,Y1ix] = max(Y1);
[Y2max,Y2ix] = max(Y2);
Xi = linspace(X1(Y1ix), X2(Y2ix), 100);
Y1i = interp1(X1,Y1,Xi);
Y2i = interp1(X2,Y2,Xi);
Ydif = sort(Y2i-Y1i);
[val,ind1] = min(abs(Y2i-Y1i));
Xq = interp1(Ydif, Xi, 0);
Yq = interp1(Xi, Y1i, Xq);
Xq_vzdialenost = Xq - X1(Y1ix); % x distance between Y1 peak and Xq
%Tool model
figure
plot(X1,Y1)
hold on
plot(X2,Y1)
plot(Xq, Yq, 'sg', 'MarkerSize', 10)
title ("Tool path model")
xlabel("Feed [mm]")
hold off
text(Xq, Yq, sprintf('\\uparrow\nX = %.4f\nY = %.4f',Xq,Yq), 'HorizontalAlignment','center', 'VerticalAlignment','top')
%Theoretical surface roughness
ind1 = find(X1>X1(Y1ix)-Xq_vzdialenost & X1<X1(Y1ix)+Xq_vzdialenost);
Xi1 = X1(ind1);
Y1ii = interp1(X1,Y1,Xi1);
xi11 = Xi1(1);
Xrh = Xi1 - xi11;
yi11 = Y1ii(1);
Yrh = Y1ii - yi11;
Xrh2 = Xrh+ length;
Yrh2 = Yrh;
Xrh3 = Xrh2 + length;
Yrh3 = Yrh;
Xrh4 = Xrh3 + length;
Yrh4 = Yrh;
Xrh5 = Xrh4 + length;
Yrh5 = Yrh;
figure
tiledlayout(2,1);
ax1 = nexttile;
plot(ax1,Xrh,Yrh,'k')
hold on
plot(ax1,Xrh2,Yrh2,'k')
plot(ax1,Xrh3,Yrh2,'k')
plot(ax1,Xrh4,Yrh2,'k')
plot(ax1,Xrh5,Yrh2,'k')
title ("Theoretical surface roughness")
xlabel("Feed [mm]")
ylabel("Y")
hold off
0 Comments
Accepted Answer
Cris LaPierre
on 17 Mar 2021
Edited: Cris LaPierre
on 17 Mar 2021
What about taking the abs of a sin wave? Angle is going to be a function of radius and length, so I consider it a fixed parameter.
r=.8;
l = 0.15;
n=5;
t = 0:l/20:n*l;
y = r*abs(sin(t/l*pi));
plot(t,y)
axis equal
xticks([0:l:0.75])
0 Comments
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!