In Matlab is there any special function to draw arc with user defined radius, points and angle. If it is not there how is it possible to draw a curve in a figure using user defined radius,angles, points etc. Thank you

 Réponse acceptée

Star Strider
Star Strider le 27 Mar 2016

8 votes

There are no such functions in core MATLAB, but they’re easy enough to write.
This code plots an arc of stars:
circr = @(radius,rad_ang) [radius*cos(rad_ang); radius*sin(rad_ang)]; % Circle Function For Angles In Radians
circd = @(radius,deg_ang) [radius*cosd(deg_ang); radius*sind(deg_ang)]; % Circle Function For Angles In Degrees
N = 25; % Number Of Points In Complete Circle
r_angl = linspace(pi/4, 3*pi/4, N); % Angle Defining Arc Segment (radians)
radius = 1.5; % Arc Radius
xy_r = circr(radius,r_angl); % Matrix (2xN) Of (x,y) Coordinates
figure(1)
plot(xy_r(1,:), xy_r(2,:), 'bp') % Draw An Arc Of Blue Stars
axis([-1.25*radius 1.25*radius 0 1.25*radius]) % Set Axis Limits
axis equal % No Distortion With ‘axis equal’

9 commentaires

rupam baruah
rupam baruah le 28 Mar 2016
Thanks a Lot. Can u calculate the length of the arc in Pixel unit?
Star Strider
Star Strider le 28 Mar 2016
My pleasure.
Calculating the length of the arc mathematically is straightforward.
Calculating it in pixels depends on a number of characteristics of the image. Perhaps the regionprops function will do what you want. Experiment with it.
kei mcqueen
kei mcqueen le 11 Juil 2018
Hello thank you for your awesome code, it has helped me with a problem I was having. Is it possible to modify the origin point of the arc? When I try modifying it myself it keeps the origin at 0,0. Thank You.
Star Strider
Star Strider le 11 Juil 2018
My pleasure.
Add the origin as a third argument:
circr = @(radius,rad_ang,p0) [radius*cos(rad_ang)+p0(1); radius*sin(rad_ang)+p0(2)]; % Circle Function For Angles In Radians
Here, ‘p0(1)’ is the x-coordinate of the origin, ‘p0(2)’ is the y-coordinate. Change ‘circd’ similarly.
A vote for my Answer would be appreciated!
Ram W
Ram W le 17 Mai 2019
sorry, I have a qestion regarding your last comment, how can I modiy the origin with 3 coordinates (x,y,z) ?
Amal Fennich
Amal Fennich le 17 Mar 2020
r_angl = linspace(pi/4, 3*pi/4, N);
what does this meanis beacause I have an angle of 3.433 degree and I do not know haow to implement it here ! any help ?
Sean Brennan
Sean Brennan le 31 Mar 2020
In this line, linspace produces a vector of N points, equally spaced (linearly - hence the name), starting from pi/4 to 3pi/4.
If you have an angle of 3.433 degrees to start, and say 90 degrees to end, and you wanted 100 points between these start and end angles, then your command would be
r_angl = linspace(3.433*pi/180, 90*pi/180,100)
Hope this helps!
Audrey Fernandes
Audrey Fernandes le 16 Juil 2020
How can this arc be repeated into a series of arcs? Like the one this the image below?
Matheus Sousa
Matheus Sousa le 26 Mar 2021
Adding the center points of each circle to xy_r should do it, in the example abova nothing was added so the center is in [0,0], but if you add 3 on xy_r(1,:) and 0 to xy_r(2,:) the position of the arc will change as well.

Connectez-vous pour commenter.

Plus de réponses (2)

Ade Ade
Ade Ade le 9 Juil 2019

0 votes

%Equation of a circle with centre (a,b) is (x-a)^2+ (y-b)^2 = r^2
%Circle Centre (1,1), radius = 10
k=1; %counter
c =1 ; % value of x at the centre of the circle
while c <=11
x(k) = c ;
vv = (c-1)^2 ;
y (k) = 1 + real (sqrt (100 - vv) );
c= c + 0.02;
k=k+1;
end
plot (x, y, 'r')
axis equal
arc.jpg
Sudhir S
Sudhir S le 28 Avr 2022

0 votes

Hello everyone, I'm currently working on a project that requires MATLAB code. This is a 2D blade profile which was design using CATIA V5. I was able to code up till this point, but I got stuck on the arc creation. The radius of the arc is given, and the beginning point is fixed for that arc. The inlet angle is used to determine the finishing point. Could someone assist me in locating a solution?

Community Treasure Hunt

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

Start Hunting!

Translated by