필터 지우기
필터 지우기

Plot an Arc on a 2D Grid by given radius and end points

조회 수: 87 (최근 30일)
TS Low
TS Low 2017년 11월 15일
답변: Navinda Wickramasinghe 2020년 9월 17일
I have one question, how do I plot the arc on a graph by giving the radius and it end points? It start points is the points set by me take example (2,2). I need draw an arc with radius 3 and end point (5,5) How to write the code for this

답변 (5개)

Roger Stafford
Roger Stafford 2017년 11월 15일
편집: Roger Stafford 2017년 11월 15일
(Correction made)
Point vectors A and B must be column vectors
A = randn(2,1); % Point A to be on circle circumference
B = randn(2,1); % Same with point B
d = norm(B-A);
R = d/2+rand; % Choose R radius >= d/2
C = (B+A)/2+sqrt(R^2-d^2/4)/d*[0,-1;1,0]*(B-A); % Center of circle
a = atan2(A(2)-C(2),A(1)-C(1));
b = atan2(B(2)-C(2),B(1)-C(1));
b = mod(b-a,2*pi)+a; % Ensure that arc moves counterclockwise
t = linspace(a,b,1000);
x = C(1)+R*cos(t);
y = C(2)+R*sin(t);
plot(x,y,'y-',C(1),C(2),'w*')
axis equal
Note that another possible center can be obtained by
C2 = (B+A)/2-sqrt(R^2-d^2/4)/d*[0,-1;1,0]*(B-A);
Note 2: If C is chosen, the arc will be <= pi. If C2 is used, arc will be >= pi
  댓글 수: 5
Roger Stafford
Roger Stafford 2017년 11월 15일
For two given points, A and B, to lie on a circular arc with a given radius, there are two possible centers that can be used. One, in this case C, places the center to the left as you face from A toward B. The other, in this case C2, places the center to the right as you face from A toward B. The way this code is written, the arc always starts at point A with angle a and goes counterclockwise as t increases until reaching point B with angle b, which is always greater than or equal to a. That means if you use center C, you will always get an arc of less than or equal to pi radians. If you use center C2, you will always get an arc of greater than or equal to pi radians.
The user needs to be prompted for three things: point A, point B, and radius R. In this code A and B are each required to be a two-element column vector, that is, a vector with two rows and one column. The first element is to be the x-coordinate and the second the y-coordinate of a point on the circular arc that is to be created. The radius, R, is of course a scalar.
TS Low
TS Low 2017년 11월 19일
편집: TS Low 2017년 11월 19일
Where is the point A? in term of X1 and Y1
A = randn(2,1);?
And how about radius?
I didn use your solution because i replace the value with other but cant solve.

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


KSSV
KSSV 2017년 11월 15일

Image Analyst
Image Analyst 2017년 11월 19일
  댓글 수: 1
TS Low
TS Low 2017년 11월 19일
yes, it is an arc
by i need prompt user for start point end point and radius
so this might be no work for me

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


Ade Ade
Ade Ade 2019년 7월 9일
%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

Navinda Wickramasinghe
Navinda Wickramasinghe 2020년 9월 17일
The solution was perfect. As Roger mentions, just make sure to provide the endpoint coordinates in the counterclockwise direction.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by