我在编写折线交叉功能方面遇到了问题。这就是我到目前为止所做的:
type Line = float*float
let LinesIntersection x y =
if x.a <> y.a then
Some ((x.b - y.b)/(y.a - x.a), (y.a*x.b - x.a*y.b)/(y.a - x.a))
else None
let l1 = (2.0,-3.0)
let l2 = (-3.0, 2.0)
let l3 = (2.0, 4.0)
LinesIntersection l1 l2 |> printfn "%A"
LinesIntersection l1 l3 |> printfn "%A"
输出:
stdin(73,19): error FS0001: This expression was expected to have type
Line
but here has type
float * float
任何帮助?
答案 0 :(得分:0)
使用此:
type Line = {a:float; b:float}
let LinesIntersection x y =
if x.a <> y.a then
Some ((x.b - y.b)/(y.a - x.a), (y.a*x.b - x.a*y.b)/(y.a - x.a))
else None
let l1 = {a=2.0; b=3.0}
let l2 = {a= -3.0; b=2.0}
let l3 = {a=2.0; b=4.0}
LinesIntersection l1 l2 |> printfn "%A"
LinesIntersection l1 l3 |> printfn "%A"