Use line design parameters to obtain coordinates

2 vues (au cours des 30 derniers jours)
Ahmed Abdulla
Ahmed Abdulla le 16 Août 2022
Réponse apportée : Tushar le 21 Sep 2023
hi everyone, I would like to obtain the coordinate points that would produce the line in black in my image, given that I have R, R2, theta 1-3 as values. any help would be appreciated and I hope the image is clear

Réponses (1)

Tushar
Tushar le 21 Sep 2023
Hi Ahmed,
I understand that you want to plot the 'black' line in the figure above.
I have reproduced the figure on my end. Here is the code snippet for it:
% Given values
R1=3; R2=0.2; theta1=60; theta2=30; theta3=45;
% Adjust the tolerance as per your requirement
tolerance=0.05;
% Define the x-domain as [0,3] with a refinement of 0.01 (define as per
% your requirement)
x = 0:0.01:3;
% plot the blue line
m1 = 1/sqrt(3); % Specify your slope
x1 = 0; % Specify your starting x
y1 = 0; % Specify your starting y
y1_ = m1*(x - x1) + y1;
hPlot1 = plot(x,y1_,'blue'); % plot the graph, and store line reference in a variable.
xlabel('x');
ylabel('y');
hold on;
% plot the purple line
m2 = sqrt(3); % Specify your slope
x2 = 0; % Specify your starting x
y2 = 0; % Specify your starting y
y2_ = m2*(x - x2) + y2;
hPlot2 = plot(x,y2_,'red'); % plot the graph, and store line reference in a variable.
hold on;
% horizontal part of the black line
y3_=0*x + 3;
% find out the intersection of black and purple line
black_purple_index=find(abs(y2_-y3_)<tolerance);
black_purple_index=black_purple_index(1);
black_purple = [x(black_purple_index),y3_(black_purple_index)];
y3_=y3_(1:black_purple_index);
hPlot3 = plot(x(1:length(y3_)),y3_,'black','LineWidth',2);
hold on;
% other part of the black line
m4 = tand(75);
x4=black_purple(1);
y4=black_purple(2);
y4_ = m4*(x - x4) + y4;
% find out the intersection of black and blue line
black_blue_index=find(abs(y4_-y1_)<tolerance);
black_blue_index=black_blue_index(1);
black_blue = [x(black_blue_index),y1_(black_blue_index)];
y4_=y4_(black_blue_index:black_purple_index);
hPlot4 = plot(x(black_blue_index:black_purple_index),y4_,'black','LineWidth',2);
hold off;
You can review the code and adjust parameters such as 'tolerance' and the 'x' refinement as needed for your specific requirements.
Hope this helps!

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by