我写了一个小程序来找到点(x,y)相对于由点(px,py)定义的线和与x轴(在笛卡尔坐标系中)的角度(度)相关的位置.
toRadian deg = deg * (pi / 180)
lineSlope deg = tan $ toRadian deg
lineYintercept (x,y) deg = y - (x * lineSlope deg)
relativePointPosition (px,py) deg (x,y)
| s < 0 && deg>=0 && deg<90 = "Left"
| s < 0 && deg>=90 && deg<180 = "Left"
| s < 0 && deg>=180 && deg<270 = "Right"
| s < 0 && deg>=270 && deg<360 = "Right"
| s > 0 && deg>=0 && deg<90 = "Right" …
Run Code Online (Sandbox Code Playgroud) 我试图将笛卡尔三维坐标系中的一个点转换为球形三维系统.
这是我到目前为止所得到的:
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)
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
哪个没用.到底是怎么回事?
转换公式来自http://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates
我有一个文件包含这个:
(Float,Float,Float)"sometext"
(Float,Float,Float)"sometext"
(Float,Float,Float)"sometext"
...
...
Run Code Online (Sandbox Code Playgroud)
我希望我的程序从文件中读取一行,将(Float,Float,Float)放入tripple并将"sometext"放入一个String中,并将所有内容放在一个新的数据类型下,这样整个事情看起来就像这样:
SomeDataType(Float,Float,Float)"sometext"
我到目前为止得到了这个:
readFromDisc filePath = do
fileHandle <- openFile "/tmp/lala.txt" ReadMode
contents <- hGetContents fileHandle
putStrLn $ readOneLine contents
Run Code Online (Sandbox Code Playgroud)
如果文件包含:
(5.0,6.0,7.0)"faraway"
(8.0,9.0,0.0)"holdon"
Run Code Online (Sandbox Code Playgroud)
我明白了:
"(5.0,6.0,7.0)\"faraway\""
Run Code Online (Sandbox Code Playgroud)
现在,因为我把它作为一个字符串,我正在考虑使用
breakInput input = break (=='"') input
Run Code Online (Sandbox Code Playgroud)
要得到这个:
("(5.0,6.0,7.0)","\"faraway\"")
Run Code Online (Sandbox Code Playgroud)
这是一对字符串,我打算使用一些东西来解析tripple和文本,但所有这些都感觉不对.
有一个更好的方法吗?