Azzera filtri
Azzera filtri

Using a newer version of plot (ezplot to fimplicit or fplot)

8 visualizzazioni (ultimi 30 giorni)
Using the answers from this question I was able to edit the code from the link above to get the general arc shape that I wanted.
However, I have a few issues, mainly down to my lack of experience:
1) ezplot isn't recommended for the type of shape, so fplot and fimplicit are suggested as alternatives, and I'm not sure how to change ezplot over and maintain the same arc image
2) I need a functionality to change the thickness of the line which it doesn't currently have
3) With this code it isn't necessary but being able to plot multiple similar arcs on the same graph is also important
I've looked through the help centre for ezplot, fplot and fimplicit and I'm really not sure where I'm going wrong.
Code is pasted below
sparse.vein = [13 28.5 2 90 45 12.1935; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0];
sparse.cross_vein = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
sf1 = 4;
sf2 = -2;
sf3 = 20;
vein1_p1 = [sf1 * sparse.vein(1,1), sf2 * sparse.vein(1,2)]; %point 1
vein1_p2 = [sf1 * sparse.vein(1,4), sf2 * sparse.vein(1,5)]; %point 2
vein1_r = sf3 * [sparse.vein(1,6)]; %radius value
%vein1_t = line thickness
limA = [0 400];
limB = [-200 0]; % [0 400 -200 0]
%first input
a=vein1_p1; %P1
b=vein1_p2; %P2
r=vein1_r; %radius
%next solution
syms x y
[x,y]=solve((x-a(1))^2+(y-a(2))^2==r^2,(x-b(1))^2+(y-b(2))^2==r^2,x,y);
%plot arc
syms X Y
ezplot((X-x(1))^2+(Y-y(1))^2==r^2,[min(52,360),max(52,360), ...
min(-200,0),max(-200,0)])
axis ([0 400 -200 0])
figure
ezplot((X-x(2))^2+(Y-y(2))^2==r^2,[min(52,360),max(52,360), ...
min(-200,0),max(-200,0)])
axis ([0 400 -200 0])

Risposta accettata

MULI
MULI il 17 Giu 2024
Modificato: MULI il 17 Giu 2024
Hi Joe,
I understand the issues you have mentioned, and they can be addressed using fimplicit function for plotting the circular arcs. This function allows adjusting the thickness of the line and plotting multiple arcs on the same graph. Below MATLAB code helps in achieving this:
% Define the vein and cross_vein arrays
sparse.vein = [13 28.5 2 90 45 12.1935; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0];
sparse.cross_vein = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
% Scaling factors
sf1 = 4;
sf2 = -2;
sf3 = 20;
% Points and radius
vein1_p1 = [sf1 * sparse.vein(1,1), sf2 * sparse.vein(1,2)]; % Point 1
vein1_p2 = [sf1 * sparse.vein(1,4), sf2 * sparse.vein(1,5)]; % Point 2
vein1_r = sf3 * [sparse.vein(1,6)]; % Radius value
% Plotting limits
limA = [0 400];
limB = [-200 0];
% First input
a = vein1_p1; % P1
b = vein1_p2; % P2
r = vein1_r; % Radius
% Solve for circle centers
syms x y
[x, y] = solve((x-a(1))^2+(y-a(2))^2==r^2, (x-b(1))^2+(y-b(2))^2==r^2, x, y);
% Circle centers
center1 = double([x(1), y(1)]);
center2 = double([x(2), y(2)]);
% Plot settings
figure;
hold on;
% Define the implicit functions for the circles
f1 = @(X, Y) (X - center1(1)).^2 + (Y - center1(2)).^2 - r^2;
f2 = @(X, Y) (X - center2(1)).^2 + (Y - center2(2)).^2 - r^2;
% Plot the circles using fimplicit
fimplicit(f1, [0 400 -200 0], 'LineWidth', 2); % Adjust LineWidth as needed
fimplicit(f2, [0 400 -200 0], 'LineWidth', 2); % Adjust LineWidth as needed
% Plot settings
axis([0 400 -200 0]);
xlabel('X');
ylabel('Y');
title('Circular Arcs');
hold off;
You may refer this link for more examples on “fimplicit” function
Hope this answers your query!

Più risposte (0)

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by