How to draw an Elliptical Arc by given radius (rx and ry) and start/end points ?

20 Ansichten (letzte 30 Tage)
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 Kommentare
Smithy
Smithy am 15 Dez. 2022
Yes, you are right. I need the Elliptical Arc to meet the start/end points. Could you let me know how to modity the code?
Sam Chak
Sam Chak am 15 Dez. 2022
Bearbeitet: Sam Chak am 15 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Fabio Freschi
Fabio Freschi am 15 Dez. 2022
Bearbeitet: Fabio Freschi am 15 Dez. 2022
I am a little lazy to do the math, so I have found this reference for the two parameters a and b that describe an ellipse.
As alternative you can try to solve a nonlinear system of equations using fsolve to calculate a, b, alpha1, alpha2 (I did it: same results, of course)
Another correction to the code is the addition of the coefficient a/b for the calculation of the minimum and maximum angles of the ellipse arc (check the calculation of alpha1 and alpha2).
clear variables, close all
% data
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]
% params according to https://www.geeksforgeeks.org/how-to-find-the-equation-of-an-ellipse-given-the-center-and-two-points/
p = A(1);
q = A(2);
m = B(1);
n = B(2);
h = C(1);
k = C(2);
% ellipse equation params
b = sqrt((p-h)^2*(n-q)*(n-q-2*k)/((p-m)*(p+m-2*h))+(q-k)^2);
a = b*sqrt((p-m)*(p+m-2*h)/((n-q)*(n+q-2*k)));
% start and end angles
alpha1 = atan2(a/b*(q-k),(p-h));
alpha2 = atan2(a/b*(n-k),(m-h));
alpha2 = mod(alpha2-alpha1,2*pi)+alpha1; % Ensure that arc moves counterclockwise
% elliptic arc
alpha = linspace(alpha1,alpha2,50);
x = h+a*cos(alpha);
y = k+b*sin(alpha);
% plot
figure, hold on, grid on, axis equal
plot(x,y)
plot(A(1),A(2),'k*')
plot(B(1),B(2),'b*')
plot(C(1),C(2), 'ro')

Weitere Antworten (0)

Tags

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by