我正在尝试使用非球面透镜公式将九个点的云朵拟合成一个圆锥体。该公式如下:
点描述了一个曲率半径为4.5且轮廓常数为-0.8的圆锥曲线。我的代码无法使用ODR,它返回了R = 8(初始点)而不是4.5。你有任何想法代码可能存在什么问题吗?
谢谢您的帮助。
其中,R是曲率半径,K是圆锥常数,z(r) = r² /(R*(1+sqrt(1-(1+K)*(r²/R²))))
r = sqrt(x²+y²)
。K保持不变(已知值),我真正需要的是R。我从http://wiki.scipy.org/Cookbook/Least_Squares_Circle开始编写它的Python代码。我用于圆锥体的隐式形式是r² - 2.R.Z + (1+K).Z²
。# -*- coding: cp1252 -*-
from scipy import odr
from numpy import *
# Coordinates of the 3D points
X = [ 0, 1, -1, 0, 0, 0.5, -0.5, 0, 0 ]
Y = [ 0, 0, 0, 1, -1, 0, 0, 0.5, -0.5 ]
Z = [ 0, 0.113696489, 0.113696489, 0.113696489, 0.113696489, 0.027933838, 0.027933838, 0.027933838, 0.027933838]
#constantes
Rc = 8
K = -0.8
def calc_r(x, y):
return (x**2 + y**2)
def calc_z(r, R):
return r**2 /(R*(1+sqrt(1-(1+K)*(r**2/R**2))))
def f_3(beta, M):
r = calc_r(M[0],M[1])
Z = calc_z(r, beta[0])
return r**2 - 2*beta[0]*Z + (1+K)*Z**2
beta0 = [Rc]
lsc_data = odr.Data(row_stack([X, Y]), y=1)
lsc_model = odr.Model(f_3, implicit = True)
lsc_odr = odr.ODR(lsc_data, lsc_model, beta0)
lsc_out = lsc_odr.run()
点描述了一个曲率半径为4.5且轮廓常数为-0.8的圆锥曲线。我的代码无法使用ODR,它返回了R = 8(初始点)而不是4.5。你有任何想法代码可能存在什么问题吗?
谢谢您的帮助。