How to build a graph like the triangle of velocity vectors

20 ビュー (過去 30 日間)
Beket
Beket 2023 年 4 月 25 日
回答済み: Kanishk 2024 年 11 月 11 日 10:39
Hello, I going to make an interface in App Designer, so I have to build in Axes the graph of the triangle of velocity vectors. Examples:
Interface should be like this and graph displayed in axes here:
Input components: Q, H, n, D_1. Calculation with input components: k_1 = 1.34; % 1.15-.1.3 k_2 = 1.1; % 1.05-1.15 k = 0.8; u_1 = D_1 * pi * n / 60; % c_0 = 0.06 * power(Q * n * n, 1 / 3); c_1m = k_1 * c_0; c_2m = k_2 * c_0; dbetta = 2 * pi / 180; c_1u = 0; betta_1 = atan(c_1m / (u_1 - c_1u)) + dbetta; w_1 = c_1m / sin(betta_1); % w_2inf = 0.7 * w_1; betta_2 = asin((w_1/w_2inf) * c_2m * k_2 * sin(betta_1) / (c_1m * k_1)); w_2 = c_2m / sin(betta_2); % He = H / (eta_g * k); u_2 = (c_2m/(2*tan(betta_2))+power(((c_2m/(2*tan(betta_2)))^2) + g*He + c_1u*u_1, 1 / 2)); % c_1 = power(u_1^2 + w_1^2 - 2 * u_1 * w_1 * cos(betta_1), 1/2); % c_2 = power(u_2^2 + w_2^2 - 2 * u_2 * w_2 * cos(betta_2), 1/2);
Graph should show this components: u1, w1, c1, cm1, beta1, u2, w2, c2, cm2, beta2
Can you help me with this issue?

回答 (1 件)

Kanishk
Kanishk 2024 年 11 月 11 日 10:39
Dear @Beket,
To make triangle in MATLAB figures you can write a function which takes the length of two sides and two angles of the triangle as the input. Using some algebra, we can easily calculate the length of the third side and the angle.
After deciding the base point, the length and angle can be used to determine the coordinates of the points. The ‘arrow’ function from MATLAB File Exchange can then be used to plot the lines with arrows on MATLAB Figure.
Here is the demo code for the same.
function plotTriangle(u, w, beta, alpha)
% Convert angles from degrees to radians
beta_rad = deg2rad(beta);
alpha_rad = deg2rad(alpha);
% Calculate the third side using the law of cosines
c = sqrt(u^2 + w^2 - 2 * u * w * cos(beta_rad));
% Calculate the coordinates of the points
A = [0, 0]; % Starting point A
B = [-u, 0]; % Point B along the x-axis
% Calculate coordinates of point C using trigonometry
Cx = u - (w * cos(beta_rad));
Cy = w * sin(beta_rad);
C = [-Cx, Cy];
% Plot the triangle using arrows
figure;
hold on;
axis('manual');
arrow([A(1), A(2)], [B(1), B(2)], 'Length', 150); % u
arrow([B(1), B(2)], [C(1), C(2)], 'Length', 150); % w
arrow([A(1), A(2)], [C(1), C(2)], 'Length', 150); % c
% Add labels to the sides
text((A(1) + B(1))/2, (A(2) + B(2))/2 - 0.2, 'u', 'FontSize', 12, 'HorizontalAlignment', 'center');
text((B(1) + C(1))/2 - 0.2, (B(2) + C(2))/2, 'w', 'FontSize', 12, 'HorizontalAlignment', 'center');
text((A(1) + C(1))/2 + 0.2, (A(2) + C(2))/2, 'c', 'FontSize', 12, 'HorizontalAlignment', 'center');
text(A(1) - 0.6, A(2) + 0.6, '\alpha', 'FontSize', 12);
text(B(1) + 0.6, B(2) + 0.6, '\beta', 'FontSize', 12);
% Set plot limits
axis equal;
xlim([B(1)-1, A(1)+1])
ylim([-1, Cy+1]);
% Add labels and grid
xlabel('X');
ylabel('Y');
title('Triangle Plot');
grid on;
hold off;
end
Here is the link to ‘arrow.m’ on MATLAB File Exchange.
Hope This Helps!
Thanks

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by