Borrar filtros
Borrar filtros

How to find the vertical height of an ellipse/y axis length of ellipse.

5 visualizaciones (últimos 30 días)
How do I get the vertical height/ y axis length on an ellipse if I have values of the centeroid, orientation, major-axis length and minor axis length?

Respuesta aceptada

Vladimir Sovkov
Vladimir Sovkov el 25 de Dic. de 2019
In fact, the height and the width of an ellipse can be easily and more accurately found analytically. Here is Matlab program realizing such a computation
function h = elhw(ax,bx,q,ifplot)
% Estimates the spans (width and height) of an ellipse
% ax - 1st principal axis halflength
% bx - 2nd principal axis halflength
% q - rotational angle
% ifplot - set it to true if you want to check the result graphically
% h - a vector with the calculated spans (width and height) of the ellipse
%%
st =ax/1000; % sample step for graphical representation; only used with ifplot=true
%
R=[[cos(q),-sin(q)];[sin(q),cos(q)]]; % rotation matrix
D=zeros(2); % ellipse equation in the coordinates of principal axes is [x y] * D^(-1) * [x ; y] = 1
D(1,1)=ax^2;
D(2,2)=bx^2;
DD = R*D*R'; % ellipse equation in the actual coordinates is [x y] * DD^(-1) * [x ; y] = 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% THESE ARE THE VALUES OF INTEREST
h = sqrt(diag(DD));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% check the consistency of the result graphically
if nargin>3 && ~isempty(ifplot) && ifplot(1)
a = max(ax,bx);
xD=(-ax:st:ax);
yD1=sqrt((1-xD.^2/D(1,1))*D(2,2));
yD2=-yD1;
A=R*[xD;yD1];
xDD1 = A(1,:);
yDD1=A(2,:);
A=R*[xD;yD2];
xDD2 = A(1,:);
yDD2=A(2,:);
% figure;
plot(xD,yD1,'--b',xD,yD2,'--b',xDD1,yDD1,'-k',xDD2,yDD2,'-k',[-a a],[-h(2) -h(2)],'-r',[-a a],[h(2) h(2)],'-r',[-h(1) -h(1)],[-a a],'-r',[h(1) h(1)],[-a a],'-r');
legend('non-rotated ellipse','','rotated ellipse','','computed spans');
end
return;
end
And this is the script to check its functionallity
%% define sample parameters randomly and check elwh.m with them
ax=rand; % the 1st axis length
bx=rand; % the 2nd axis length
q=rand*pi; % rotation angle
h = elhw(ax,bx,q,true); % estimate the ellipse width, height, and check the results graphically

Más respuestas (1)

Image Analyst
Image Analyst el 25 de Dic. de 2019
Does not seem like a MATLAB question. But anyway, if you digitize it into an x array and y array, you can then find the y range of the digitized values.
height = max(y(:)) - min(y(:));
If you don't have any y, then it's just an analytical geometry problem and you should ask it in some general mathematics forum rather than a MATLAB language forum.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by