Two methods to check if a point exists within an ellipsoid
Mostra commenti meno recenti
I have a need to determine if a point, measured in [x, y, z] from the origin, is within an ellipsoid also centered at the origin with semi-axes [a1, a2, a3] that is rotated around x/y/z by tilt/roll/yaw angles. Most answers I have found suggest it is easier to rotate the point backward into a non-rotated ellipsoid rather than rotating the equation of the ellipsoid. Then after the point is rotated, I can use the new x'/y'/z' in the standard equation of an ellipsoid: (x'/a1)^2+(y'/a2)^2+(z'/a3)^2=ans. If ans is less than or equal to 1, then the point is inside or on the ellipsoid. I am using a right handed system, for reference.
This is where I started and I believe I have the solution. However, I would like to also solve the problem by rotating the ellipoid, for verification and personal curiosity reasons.
What I have now is:
% point vector measured at x/y/z
p0=[-70, -100, 300]';
% ellipsoid axes a1/a2/a3
axes=[1300, 100, 700];
% rotation angles tilt, roll, yaw degrees
r_angles=[4, -1, 120];
% rotation matrices for the ellipsoid
% rotations are intrinsic and in the order roll, tilt, yaw
Rx=rotx(r_angles(1))
Ry=roty(r_angles(2))
Rz=rotz(r_angles(3))
% total rotation matrix
R=Rz*Rx*Ry
% since rotation matrices inverses are the same as their transpose and
% the inverse of each matrix is the same as rotating in the opposite
% direction, i can apply the transpose rotation matrices in the reverse
% order to rotate the point backward.
% R'=Ry'*Rx'*Rz'
p1=R'*p0
% now I can check if the rotated point is inside the origin centered and
% aligned ellipsoid
% point in ellipsoid <=1; yes
pie=(p1(1)/axes(1))^2+(p1(2)/axes(2))^2+(p1(3)/axes(3))^2
% an answer above 1 suggests this point is not inside the ellipsoid
If I attempt to rotate the ellipsoid instead, I can start with the general equation for an ellipsoid using matrix notation.
(p-v)'*A*(p-v)=1
v is a vector with the center of the ellipsoid. Since my ellipsoid is at the origin, we can elimiante v.
p'*A*p=1
This is where my confusion comes in. I have seen some resources say that the general equation can be rotated in two ways:
1: By applying the rotation matrices as follows to A, which is defined as a square symmetric matrix with the inverse square of each axis on its diagonals.
(p-v)' * R' * A * R * (p-v) = 1
or
p' * R' * A * R * p = 1
2: Another method defines A differently. It has A defined as a positive definite matrix with eigen spaces(vectors?) as the principal axes of the ellipsoid and the eigenvalues are the squared inverses of the semiaxes. Which means that A is defined as: A=Q * D * Q'
D is the diagonal matrix with the inverse square of each axis on the diagonal. Q is the matrix with columns that represent the axes direction of the ellipsoid. I interpret this to mean that Q = R, since the ellipsoid started along the x/y/z axes. Which means:
p' * R * D * R' * p = 1
% continuing from here I can attempt both methods to see which works
% we can use p0 since it is not being rotated
% for method 1 we need to define the diagonal matrix
D=diag(axes.^(-2))
pie2=p0'*R'*D*R*p0
% for method 2 we just switch the locations of R' and R
pie3=p0'*R*D*R'*p0
Since method 2 agrees with the backward rotation method above, I am inclined to say that it is the correct method. However, I am unsure if I simply implemented the first method incorrectly. I would like some confirmation or correction of my methods. Where did I go wrong, or what am I missing to prove I did it right?
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Polar Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!