Created
August 13, 2015 06:23
-
-
Save FreekPaans/48d8fc404fad7be1ca8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Vector = | |
type PolarVector = { | |
r: double; | |
a: double; | |
} | |
type RectangularVector = { | |
x: double; | |
y: double; | |
} | |
type Vector = private Polar of PolarVector | Rectangle of RectangularVector | |
let createRectangular x y = | |
Rectangle { x = x; y = y;} | |
let createPolar r a = | |
Polar { r=r;a=a } | |
let private polar2Rect v = | |
Rectangle { x = (cos v.a) * v.r; y = (sin v.a) * v.r } | |
let rec Add v1 v2 = | |
match v1 with | |
| Rectangle v1xy -> | |
match v2 with | |
| Rectangle v2xy -> Rectangle { x = v1xy.x + v2xy.x; y = v1xy.y + v2xy.y } | |
| Polar polar -> Add v1 (polar2Rect polar) | |
| Polar polar -> | |
Add (polar2Rect polar) v2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment