How to interpolate an ellipse given data points?
18 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
manoj saladi
il 5 Apr 2019
Modificato: Cris LaPierre
il 5 Apr 2019
Hi,
I plotted number of concentric ellipses using contour function, where each ellipse represents a flux level which is a function of two currents.
But the matrix which I obatained using contour function contains some x, y coordinates which when plotted gives me an approximate ellipse shape. For example let's say a small ellipse and matlab gives me a diamond shape for it, like in the picure shown
So, my intention is to make all these ellipses more smooth by increasing the number of data points in each ellipse.
I have tried using the code below
and it gives me a weird plots like shown below
I have also removed level,vertices column but still the plot looks weird.
So, is there any way to to get good ellipse shapes, also I should be able to access x and y datapoints after interpolation
Thank you.
2 Commenti
Cris LaPierre
il 5 Apr 2019
It is much more preferrable you copy/paste your code rather than include screenshots. Motivation to transcribe code from an image is often pretty low...
You can't interp an ellipse as is because there are 2 y values for most x values. You'd have to reparametize your curves.
John D'Errico
il 5 Apr 2019
DON'T send me direct e-mail to get me to answer your question. Don't send me multiple e-mails, as you actually did. In fact, you had to send me e-mail through my profile, where you should have seen that explicit statement to not send direct e-mail.
I would have answered your question in depth otherwise, as I would have seen it, and found it to be of some interest.
Risposta accettata
Cris LaPierre
il 5 Apr 2019
Modificato: Cris LaPierre
il 5 Apr 2019
The challenge is to get your x to be unique and increasing. If I create a new variable that is the cumulative distance of each point from the first point, that satisfies that condition. I use that as my new x and use it to interp both x and y.
By default, interp1 is linearly adding points between known data points (same slope). To get a more rounded shape, set the interp style to spline.
% https://www.mathworks.com/matlabcentral/answers/86615-how-to-plot-an-ellipse#answer_96122
a=10; % horizontal radius
b=5; % vertical radius
x0=0; % x0,y0 ellipse centre coordinates
y0=0;
t=linspace(-pi,pi,11);
x=x0+a*cos(t);
y=y0+b*sin(t);
plot(x,y)
axis equal
% Now that we have x, y vals, reparameterize and interp.
% Assuming linear interpolation adequately represents the ellipse
dist = sqrt(diff(x).^2+diff(y).^2);
%Reparameterize
tm = cumsum([0 dist]);
t = linspace(0,tm(end));
xInt = interp1(tm,x,t,"spline");
yInt = interp1(tm,y,t,"spline");
hold on
plot(xInt,yInt)
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Contour Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!