我試圖將笛卡爾三維座標系中的一個點轉換爲球形3d系統。在haskell中從笛卡爾3d轉換爲球形3d座標系
這是我走到這一步:
radialDistance3D (x,y,z) = sqrt (x*2 + y*y + z*z)
cartesian3DToPolar3D (x,y,z) = (r,alpha, beta)
where r = radialDistance3D (x,y,z)
alpha = acos(z/r)
beta = atan2(y,x)
GHCI加載代碼,但是當我嘗試用
cartesian3DToPolar3D(1.0,2.0,3.0)
執行它,我得到:
<interactive>:1:0:
No instance for (RealFloat (t, t))
arising from a use of `cartesian3DToPolar3D'
at <interactive>:1:0-33
Possible fix: add an instance declaration for (RealFloat (t, t))
In the expression: cartesian3DToPolar3D (1.0, 2.0, 3.0)
In the definition of `it':
it = cartesian3DToPolar3D (1.0, 2.0, 3.0)
這不是有幫助的。到底是怎麼回事?
轉換公式從http://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates
不要緊,我知道了:)它是atan2 yx,而不是atan2(y,x) – anybody 2010-11-10 12:29:32
不應該''radialDistance3D(x,y,z)'='sqrt(x * x + y * y + z * z)',而不是'= sqrt(x * 2 + y * y + z * z)'!? – adamse 2010-11-10 12:39:44
既然你已經知道了,爲什麼不在SO上寫一個答案呢? – 2010-11-10 12:47:12