我有對應于一組 2D 輪廓的坐標,每個輪廓對應于不同的高度。這些輪廓不會在 3D 中繪制出完美的橢球體,而是我想做的是找到最合適的橢球體。我對這個橢球的起源一無所知。
我的第一個想法是結合某種型別的最小二乘演算法,在那里我找到了最小化點之間距離的橢球引數。我想這將非常昂貴,并且與蠻力方法相距不遠。我相信有一種更優雅、更有效的方法來做到這一點。如果有一個現有的庫可以處理這個問題(最好是在 Python 中),那就更好了。
我已經看到了一個相關的問題(
最佳擬合橢圓由一般方程描述
A x^2 B y^2 2 C xy 2 D x 2 E y = 1
并且一旦(A,B,C,D,E)找到系數,就可以完全描述橢圓。(x,y)請參閱下文,了解如何從系數和引數中找到曲線坐標t=0 .. 1。
要找到橢圓的系數,請形成 5 個向量,每個向量是一個 ×5 矩陣的列Q
for i = 1 to n
Q(i,1) = x(i)^2
Q(i,2) = y(i)^2
Q(i,3) = 2*x(i)*y(i)
Q(i,4) = 2*x(i)
Q(i,5) = 2*y(i)
next i
和右側K填充的向量1
for i = 1 to n
K(i) = 1.0
next i

使用帶有一些線性代數的最小二乘擬合找到系數
[A,B,C,D,E] = inv(tr(Q)*Q)*tr(Q)*K
哪里tr(Q)是轉置Q并且*是矩陣/向量積

Now we need to extract the geometric properties of the ellipse from the coefficient. I want to have a the semi-major axis, b the semi-minor axis, φ the rotation angle, xc the x-axis center, yc the y-axis center.
xc = -(B*D-C*E)/(A*B-(C^2))
yc = -(A*E-C*D)/(A*B-(C^2))
φ = atan( 2*C/(A-B) )/2
a = SQRT(2*(A*(B E^2) B*D^2-C*(C 2*D*E))/((A*B-C^2)*(A B-SQRT((A-B)^2 4*C^2))))
b = SQRT(2*(A*(B E^2) B*D^2-C*(C 2*D*E))/((A*B-C^2)*(A B SQRT((A-B)^2 4*C^2))))
Finally to plot the ellipse you need to generate a set of points (x,y) from the curve parameter t=0..1 using the above 5 coefficients.
Generate the centered aligned coordinates
(u,v)withu = a*cos(2*π*t) v = b*sin(2*π*t)Generate the centered rotated coordinates
(x',y')withx' = u*cos(φ) - v*sin(φ) y' = u*sin(φ) v*cos(φ)Generate the ellipse coordinates
(x,y)withx = x' xc y = y' yc
The result is observed above in the first picture.

Now for the total solution, each 2D slice would have its own ellipse. But all the slices would not generate an ellipsoid this way.
Extending the above into 3D coordinates (x,y,z) is doable, but the math is quite involved and I feel [SO] is not a good place to develop such an algorithm. You can hack it together, by finding the average center for each slice (weighted by the ellipse area π*a*b). Additionally, the rotation angle should be the same for all contours, and so another averaging is needed. Finally, the major and minor axis values would fall on an elliptical curve along the z-axis and it would require another least-fit solution. This one is driven by the equation
(x/a)^2 (y/b)^2 (z/c)^2 = 1
but rather in the aligned coordinates (u,v,w)
(u/a)^2 (v/b)^2 (w/c)^2 = 1
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/441759.html
上一篇:Java二維陣列語法包裝邊框
