How to draw an Elliptical Arc by given radius (rx and ry) and start/end points ?
Show older comments
Hello Everybody
I tried to draw an Elliptical Arc on a graph by giving the radius (rx and ry) and start/end points.
-- start point [11,56], and end point [-11, -18], and Center of arc [11, 18]. --
But the arc I made is away from the start/end points. not meet the points. (this below code is only valid for circular arc)
(I used the code from "matlabcentral/answers/367126-plot-an-arc-on-a-2d-grid-by-given-radius-and-end-points")
Please let me know how to make the Elliptical Arc on a graph by giving the radius (rx and ry) and start/end points.
A = [11, 56]; % start point [x,y] of Arc
B = [-11, -18]; % end point [x,y] of Arc
C = [11, 18]; % x, y-radius of arc [rx,ry]
d = norm(B-A);
r = d/2; % Choose R radius = d/2
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,50);
x = C(1)+r*cos(t);
y = C(2)+r*sin(t);
plot(x,y,'k-',A(1),A(2),'k*',B(1),B(2),'k*')
axis equal
3 Comments
The code you used is for the case of a Circular arc.
That is not the case here. The center point C is not equidistant to end-points A and B.
A = [11, 56]; % start point [x,y] of Arc
B = [-11, -18]; % end point [x,y] of Arc
C = [11, 18]; % Center of arc [x,y]
d = norm(B-A);
norm(C-A)
norm(C-B)
r = d/2; % Choose R radius = d/2
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,50);
x = C(1)+r*cos(t);
y = C(2)+r*sin(t);
plot(x,y,'k-',A(1),A(2),'k*',B(1),B(2),'k*')
hold on
plot(C(1),C(2), 'k*')
axis equal
Smithy
on 15 Dec 2022
@Smithy, are you looking for the Parametric Equation of an Elliptic Arc?
If you have the math, then you can replace Parametric Equation of a Circle below:
x = C(1) + r*cos(t);
y = C(2) + r*sin(t);
with
x = C(1) + a*cos(t);
y = C(2) + b*sin(t);
where a is the length of the semi-major axis and b is the length of the semi-minor axis of an ellipse.
Accepted Answer
More Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
