jumping curves problem and polygon trace

8 ビュー (過去 30 日間)
Aamna Alshehhi
Aamna Alshehhi 2019 年 10 月 3 日
回答済み: Deepak 2025 年 2 月 17 日 8:47
so i got this code to plot Th2 vs Th3 and Th2 vs Th4 but i have a problem of jumping curves because i get two values of Th3 every itiration ,also for Th4 so i wanna sparate these values to get a continues curve. also i wanna plot figure 3 (patch command) from Th2=0 to 90 not to 360 but i am not sure how to do this. any suggestions?
for i=0:360
d =3.5; a = 1;b = 2; c = 4;
Th1= 0;
Z = d*exp(1i*deg2rad(Th1))- a*exp(1i*deg2rad(i));
Zc = conj(Z);
Ka = c*Zc; Kb = Z*Zc + c^2 -b^2; Kc = c*Z;
T = roots([ Ka Kb Kc]);
S = (c*T+Z)/b;
Th3(:,i+1) = rad2deg(angle(S));
Th4 (:,i+1) = rad2deg(angle(T));
P= a*exp(1i* deg2rad(Th2))+ 6*exp(1i* deg2rad(Th3-20));
B= a*exp(1i* deg2rad(Th2))+ 2*exp(1i* deg2rad(Th3));
A= a*exp(1i* deg2rad(Th2));
end
Th2 = 0:360;
figure(1)
plot (Th2,Th3(1,:));
hold on;
plot (Th2,Th3(2,:));
xlabel ('TH)')
ylabel ('TH3')
figure(2)
plot (Th2,Th4(1,:));
hold on;
plot (Th2,Th4(2,:));
xlabel ('TH2') ;
ylabel ('TH4') ;
figure (3);
patch( [real(P); real(B); real(A)] , [imag(P); imag(B); imag(A)] ,[1 1 1])
Bnew = downsample(B,5);
Anew = downsample(A,5);
Pnew = downsample(P,5);

回答 (1 件)

Deepak
Deepak 約21時間 前
We can create continuous plots of "Th3" and "Th4" by initializing their arrays with "NaN" values, which helps in breaking the plot line at discontinuities, thereby preventing curve jumps.
To restrict the patch plot to a specific range of "Th2" from 0 to 90 degrees, we adjust the loop to only iterate over this range when calculating the patch coordinates. This approach ensures that the plots are both continuous and constrained to the desired angular range, enhancing the clarity and accuracy of the visual representation.
Here is the updated MATLAB code to achieve the same:
% Initialize variables
d = 3.5; a = 1; b = 2; c = 4;
Th1 = 0;
Th2 = 0:360;
Th3 = NaN(2, length(Th2)); % Preallocate with NaN for separation
Th4 = NaN(2, length(Th2));
% Loop for Th2 from 0 to 360
for i = 1:length(Th2)
Z = d*exp(1i*deg2rad(Th1)) - a*exp(1i*deg2rad(Th2(i)));
Zc = conj(Z);
Ka = c*Zc; Kb = Z*Zc + c^2 - b^2; Kc = c*Z;
T = roots([Ka Kb Kc]);
S = (c*T + Z) / b;
Th3(:, i) = rad2deg(angle(S));
Th4(:, i) = rad2deg(angle(T));
end
% Plot Th3
figure(1);
plot(Th2, Th3(1, :), 'DisplayName', 'Th3(1)'); hold on;
plot(Th2, Th3(2, :), 'DisplayName', 'Th3(2)');
xlabel('Th2');
ylabel('Th3');
legend show;
% Plot Th4
figure(2);
plot(Th2, Th4(1, :), 'DisplayName', 'Th4(1)'); hold on;
plot(Th2, Th4(2, :), 'DisplayName', 'Th4(2)');
xlabel('Th2');
ylabel('Th4');
legend show;
% Restrict Th2 for Figure 3
Th2_patch = 0:90;
P = a*exp(1i*deg2rad(Th2_patch)) + 6*exp(1i*deg2rad(Th3(1, 1:length(Th2_patch)) - 20));
B = a*exp(1i*deg2rad(Th2_patch)) + 2*exp(1i*deg2rad(Th3(1, 1:length(Th2_patch))));
A = a*exp(1i*deg2rad(Th2_patch));
% Plot Figure 3
figure(3);
patch([real(P); real(B); real(A)], [imag(P); imag(B); imag(A)], [1 1 1]);
% Downsample for visualization if needed
Bnew = downsample(B, 5);
Anew = downsample(A, 5);
Pnew = downsample(P, 5);
Please find attached the documentation of functions used for reference:
I hope this helps in resolving the issue.

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by