Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Returns the intersection of two Line2Ds that are known to intersect.
- static member public IntersectionOf(a:Line2D, b:Line2D) =
- //Returns A, B, C for: AX + BX = C
- //as a Treble(A, B, C)
- let GetABC(working:Line2D) =
- let A = working.End.Y - working.Start.Y
- let B = working.End.X - working.Start.X
- let C = (A * working.End.X) + (B * working.Start.Y)
- A, B, C
- let lineA_data = GetABC a
- let lineB_data = GetABC b
- //TODO: How to get data out of Tuples/Trebles without fun vars?
- let GetDeterminant (a1, b1, c1) (a2, b2, c2) =
- (a1*b2) - (a2*b1)
- let determinant =
- GetDeterminant lineA_data lineB_data
- if determinant = float32(0) then
- raise(Exception("Lines were parallel!"))
- let GetResultX (a1, b1, c1) (a2, b2, c2) d =
- ((b2*c1)-(b1*c2)) / d
- let GetResultY (a1, b1, c1) (a2, b2, c2) d =
- ((a1*c2) - (a2*c1)) / d
- new Vector2(
- GetResultX lineA_data lineB_data determinant,
- GetResultY lineA_data lineB_data determinant)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement