Plot a curve on vertical axis

7 views (last 30 days)
federico nutarelli
federico nutarelli on 20 Sep 2021
Hi all,
I am producin the following image (the red arrows and the red circles are added artificially using a picture software to let you better understand the question):
The plot above has been produceed with the following mwe code:
clear
percorso=1;
angle_in_degrees=75;
theta = deg2rad(angle_in_degrees);
l=2*pi;
if percorso ==1
%da 0 a pi-epsilon
if theta>=0 && theta<=deg2rad(45)
s_bar = l/(2*abs(cos(theta)));
elseif theta>deg2rad(45) && theta<=deg2rad(90)
s_bar=l/(2*abs(sin(theta)));
elseif theta>-deg2rad(90) && theta<=-deg2rad(45)
s_bar=l/(2*abs(sin(theta)));
elseif theta>=-deg2rad(45) && theta<=0
s_bar = l/(2*abs(cos(theta)));
elseif theta>=deg2rad(90) && theta<=deg2rad(135)
s_bar=l/(2*abs(sin(theta)));
elseif theta> deg2rad(135) && theta<=deg2rad(180)
s_bar = l/(2*abs(cos(theta)));
elseif theta>=-deg2rad(180) && theta<=-deg2rad(135)
s_bar = l/(2*abs(cos(theta)));
elseif theta>=-deg2rad(135) && theta<=-deg2rad(90)
s_bar = l/(2*abs(sin(theta)));
end
elseif percorso==0
theta=0;
s_bar = l/(2*abs(cos(theta)));
end
N=250; %frequenza di campionamento (ho 150 campioni)
Delta_s0 = s_bar/N;
Delta_s2 = Delta_s0;
epsilon=l/100;
Delta_s1 = epsilon*(pi/2)/N;
s0a =0;
s0b = s_bar-epsilon;
s1a=s0b+Delta_s1;
s1b= s0b+epsilon*(pi/2);
s2a=s1b+Delta_s2;
s2b=s1b+s_bar-epsilon;
s0=[s0a:Delta_s0:s0b];
s1=[s1a:Delta_s1:s1b];
s2=[s2a:Delta_s2:s2b];
%ascisse plot: k1_ad;
s_cat = [s0 s1 s2];
tratto = zeros(1,size(s_cat,2));
for k=1:size(s0,2)
tratto(:,k)=1;
end
for k=size(s0,2)+1:size(s0,2)+size(s1,2)
tratto(:,k)=2;
end
for k=size(s0,2)+size(s1,2)+1:size(s0,2)+size(s1,2)+size(s2,2)
tratto(:,k)=3;
end
primo_tratto = find(tratto==1);
secondo_tratto = find(tratto==2);
terzo_tratto = find(tratto==3);
conto1 = 1;
conto2 =1;
%%% SBAGLIATO IL TRATTO??? (è rimasto 0 da qualche parte??)
for m=1:size(s_cat,2) %numero di elementi di s
if m<=primo_tratto(size(primo_tratto,2)) %qui devo mettere m! (devo mettere un find fino a quando tratto è ==1)
k1_ad(m)=s0(m);
k2_ad(m)=0;
elseif m>primo_tratto(size(primo_tratto,2)) && m<=secondo_tratto(size(secondo_tratto,2))
k1_ad(m)=s0b+(epsilon)*cos(((s_cat(m)-s0b)/epsilon)-(pi/2));
k2_ad(m)=epsilon+(epsilon)*sin(((s_cat(m)-s0b)/epsilon)-(pi/2));
conto1=conto1+1;
elseif m>secondo_tratto(size(secondo_tratto,2)) && m<=terzo_tratto(size(terzo_tratto,2))
k1_ad(m)=k1_ad(secondo_tratto(size(secondo_tratto,2))); %perchè sono spostato di un tratto s_bar dall'asse y
k2_ad(m)=s2(conto2)-s1b+epsilon;
conto2=conto2+1;
end
end
What I would like to do is written on the image and is basically reproducing the "smoothed angle" on the top right corner also on the top so that the image looks like this (red curved line with, however radius epsilon as in the mwe. It shoul basically be exactly the same angle as the smoothed below but "reversed"):
  2 Comments
darova
darova on 20 Sep 2021
Is this the result you want to achieve?
federico nutarelli
federico nutarelli on 20 Sep 2021
Edited: federico nutarelli on 20 Sep 2021
@darova thank you for replying. Yes but the angle above, differently from the one below is 45 degrees. Also the angle in the top left should be smoothed. Basically, I am striving at finding the correct angle for the polar coordinates. Thank you very much

Sign in to comment.

Answers (1)

darova
darova on 20 Sep 2021
Edited: darova on 20 Sep 2021
What about this
a = 30; % left corner angle
L = 10; % triangle size
r = 1; % arc radius
t1 = 0:90+a; % top corner arc
t2 = 90+a:270; % left corner arc
t3 = 270:360; % bottom right corner arc
[x1,y1] = pol2cart(deg2rad(t1),r);
[x2,y2] = pol2cart(deg2rad(t2),r);
[x3,y3] = pol2cart(deg2rad(t3),r);
y1 = y1 + L*sind(a); % translate first arc to top
x2 = x2 - L*cosd(a); % translate second arc to right
x = [x1 x2 x3 x1(1)];
y = [y1 y2 y3 y1(1)];
plot(x,y,'.-r')
axis equal
  1 Comment
federico nutarelli
federico nutarelli on 20 Sep 2021
thank you @darova. COuld you please try out with my code? Since I am working in a team I should align with the notation used. Thank you very much

Sign in to comment.

Categories

Find more on Curve Fitting Toolbox in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!