How to draw an Arc in the direction you want? (with known radius, centre and angle)

조회 수: 67 (최근 30일)
I'm trying to draw an arc between 350º and 0º angles, but the point is that I would like to draw it in counter-clock wise. What is the general method of drawing an arc in matlab in the direction you want?
The code I have written is the following:
hold on
grid
axis equal
angini=350; %initial angle of the arc in degrees
angfin=0; %final angle of the arc in degrees
rangini=deg2rad(angini); %initial angle of the arc in radians
rangfin=deg2rad(angfin); %final angle of the arc in radians
centre=[0;0]; %centre of the arc
radius=10; %radius of the arc
teta = linspace(rangini,rangfin);
xco = centre(1)+radius*cos(teta); %x coordinates
yco = centre(2)+radius*sin(teta); % y coordinates
plot(xco,yco,'g') %plot the arc
And the result, as you can see, is the following:
It drew the arc in a clockwise direction, not in a counterclock one. What is the general method of drawing an arc in matlab in the direction that you like?

답변 (1개)

Steven Lord
Steven Lord 2020년 11월 9일
Use an ending angle of 360 degrees rather than an angle of 0 degrees. You can skip the deg2rad calls by using the degree-based trig functions cosd and sind. I also chose to change some of the variable names to make them a bit more descriptive. With those names you could argue the comments are unnecessary.
hold on
grid
axis equal
angleInitial=350; %initial angle of the arc in degrees
angleFinal=360; %final angle of the arc in degrees
centre=[0;0]; %centre of the arc
radius=10; %radius of the arc
theta = linspace(angleInitial,angleFinal);
xcoords = centre(1)+radius*cosd(theta); %x coordinates
ycoords = centre(2)+radius*sind(theta); % y coordinates
plot(xcoords,ycoords,'g') %plot the arc
  댓글 수: 1
ErikJon Pérez Mardaras
ErikJon Pérez Mardaras 2020년 11월 9일
편집: ErikJon Pérez Mardaras 2020년 11월 9일
Thanks for the repply, but I am looking for a general answer for a general issue. Imagine that, instead of wanting to draw an arc from 350º to 0º(or 360º) I would like to draw an arc from 170º to 220º but in a clockwise direction instead of a counterclock one (which is what Matlab would do in this case).
As you can see in the following image, Matlab draws me that arc in a counterclock wise direction.
Is the same case as before. How I could draw arcs in the directions I want? Is there any way?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by