Fit ellipse in 3D space

57 次查看(过去 30 天)
I have xy coordinates of the ellipse in 2D space and its coordinate center (0.1427, -0.4418).
I would like to fit this ellipse xy coordinates in to the 3D space to replace the one which is not correct/perfect. The coordinate center in 3D space should be (0.1427, -0.4418, -0.0564) and the plane is defined in attachment.
How can I calculate the missing z axis data to draw the ellipse in 3D space on the desired plane?
  2 个评论
Matt J
Matt J 2022-9-27
编辑:Matt J 2022-9-27
You must have performed a rotation to obtain the 2D coordinates from the 3D coordinates. Can't you just rotate back?
RoboTomo
RoboTomo 2022-9-27
No, I did not perform any rotations before. I am searching for intersection of plane and ellipsoid with this function: https://www.mathworks.com/matlabcentral/fileexchange/48613-surface-intersection
The output of intersection is ellipse with xyz data, however in some cases the output does not return the perfect xyz for the ellipse curve (see Fig. bad 3d ellipse). If somebody knows why this happens, it would also solve the problem.
I put above xy (in attachment) data to other function to obtain ellipse semi axis. This function calculates good ellipse fit even though the curve was not perfect: https://www.mathworks.com/matlabcentral/fileexchange/3215-fit_ellipse
I wanna use xy data of the fitted ellipse curve back in 3D space.

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2022-9-28
编辑:Matt J 2022-9-28
Another possibility is to use this FEX download,
to fit the 3D data directly.
load('xyz');
xyz=xyz';
fobj=planarFit(xyz); %Fit a plane to xyz data
R=fobj.R(:,[2,3,1])';
Rxyz=R*xyz; %Rotate xyz coordinates to be parallel to xy plane
z0=mean(Rxyz(3,:),2);
fobj=ellipticalFit(Rxyz(1:2,:)); %ellipse fit to the rotated data (ignoring z-coordinate)
Rxyz=cell2mat(fobj.sample(0:2:360)); %Generate 'evenly' spaced samples around the ellipse
Rxyz(3,:)=z0; %re-insert z-coordinate
xyzFit=R'*Rxyz; %rotate back to 3D
%Visualize
scatter3(xyz(1,:),xyz(2,:),xyz(3,:),'filled'); hold on
scatter3(xyzFit(1,:),xyzFit(2,:),xyzFit(3,:)); hold off
xlabel X; ylabel Y; zlabel Z
legend('Original','Fit')
view(50,30)
  2 个评论
RoboTomo
RoboTomo 2022-9-28
Of course... I had incomplete xyz data of the original ellipse in 3D and I didn't know such function for direct 3D data fitting exist. This fit looks great! Thank you very much for your answer and the code.
VIGNESH BALAJI
VIGNESH BALAJI 2023-7-20
@Matt J the tool you mentioned looks great. Is there any tool to fit 3D data of a catenary (looks like a parabola but a hyperbolic cosine function) directly. please let me know.

请先登录,再进行评论。

更多回答(1 个)

Matt J
Matt J 2022-9-27
编辑:Matt J 2022-9-27
I am searching for intersection of plane and ellipsoid
If that is the ultimate goal, you should just rewrite the ellipsoid equation in a rotated coordinate system where the intersection plane is the xy plane. That will result in a 2D equation for the intersection ellipse directly.
The appropriate basis vectors xaxis, yaxis, and zaxis can be obtained as,
zaxis=[A,B,C]';
xy=null(zaxis');
xaxis=xy(:,1);
yaxis=cross(zaxis,xaxis);
and the 4x4 coordinate transform matrix needed to apply and invert the transformation is,
T=eye(4);
T(1:3,1:3)=[xaxis,yaxis,zaxis]';
T=T*makehgtform('translate',-[0.1427, -0.4418, -0.0564]);
  2 个评论
RoboTomo
RoboTomo 2022-9-27
Thank you for your answer. To be fair I already lost some good amount of time trying to get this intersection mathematically with conic ellipsoid equation and plane but was unsuccessful... I was using this function: https://www.mathworks.com/matlabcentral/fileexchange/52958-intersection-arbitrary-ellipsoid-and-a-plane?tab=discussions, and you can see in the comments what my problem was. Probably I just don't understand this field enough... so I don't know how to put your answer into action yet - how can I calculate intersection? I am sending the program where I define ellipsoid and plane, maybe you can check if it is even possible to do that with my dataset. Of course this way of calculating intersection would be more efficient.
Then I went with this intersection based purely on surfaces, which works great apart from the problem of some missing points mentioned above. So is there no solution for my original question? There must be a way on how to map this 2d ellipse data onto 3d plane.
Matt J
Matt J 2022-9-27
An alternative approach is to use the transform T that I derived above to map the 3D points that the surface intersection code gave you to 2D. In 2D, you can perform the ellipse fit and generate as many points on the ellipse as you wish. Then you can map back to 3D with inv(T).

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Spline Postprocessing 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by