直线交点 fsharp
line line intersection fsharp
我在编写直线相交函数时遇到问题。这是我目前所拥有的:
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
有什么帮助吗?
使用这个:
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"
我在编写直线相交函数时遇到问题。这是我目前所拥有的:
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
有什么帮助吗?
使用这个:
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"