1module Math.Vector3 where
2{-| A high performance linear algebra library using native JS arrays. Geared
3towards 3D graphics and use with `Graphics.WebGL`. All vectors are immutable.
9The set functions create a new copy of the vector, updating a single field.
11@docs getX, getY, getZ, setX, setY, setZ
14@docs add, sub, negate, scale, dot, cross, normalize, direction,
15 length, lengthSquared, distance, distanceSquared
18@docs toTuple, fromTuple, toRecord, fromRecord
25{-| Creates a new 3-element vector with the given values.
27v3 : Float -> Float -> Float -> Vec3
30{-| The unit vector î which points in the x direction: `v3 1 0 0` -}
32i = Native.MJS.v3 1 0 0
34{-| The unit vector ĵ which points in the y direction: `v3 0 1 0` -}
36j = Native.MJS.v3 0 1 0
38{-| The unit vector &kcirc; which points in the z direction: `v3 0 0 1` -}
40k = Native.MJS.v3 0 0 1
42{-| Extract the x component of a vector. -}
44getX = Native.MJS.v3getX
46{-| Extract the y component of a vector. -}
48getY = Native.MJS.v3getY
50{-| Extract the z component of a vector. -}
52getZ = Native.MJS.v3getZ
54{-| Update the x component of a vector, returning a new vector. -}
55setX : Float -> Vec3 -> Vec3
56setX = Native.MJS.v3setX
58{-| Update the y component of a vector, returning a new vector. -}
59setY : Float -> Vec3 -> Vec3
60setY = Native.MJS.v3setY
62{-| Update the z component of a vector, returning a new vector. -}
63setZ : Float -> Vec3 -> Vec3
64setZ = Native.MJS.v3setZ
66{-| Convert a vector to a tuple. -}
67toTuple : Vec3 -> (Float,Float,Float)
68toTuple = Native.MJS.toTuple3
70{-| Convert a vector to a record. -}
71toRecord : Vec3 -> { x:Float, y:Float, z:Float }
72toRecord = Native.MJS.toRecord3
74{-| Convert a tuple to a vector. -}
75fromTuple : (Float,Float,Float) -> Vec3
76fromTuple = Native.MJS.fromTuple3
78{-| Convert a record to a vector. -}
79fromRecord : { x:Float, y:Float, z:Float } -> Vec3
80fromRecord = Native.MJS.fromRecord3
82{-| Vector addition: a + b -}
83add : Vec3 -> Vec3 -> Vec3
86{-| Vector subtraction: a - b -}
87sub : Vec3 -> Vec3 -> Vec3
90{-| Vector negation: -a -}
92negate = Native.MJS.v3neg
94{-| The normalized direction from a to b: (a - b) / |a - b| -}
95direction : Vec3 -> Vec3 -> Vec3
96direction = Native.MJS.v3direction
98{-| The length of the given vector: |a| -}
100length = Native.MJS.v3length
102{-| The square of the length of the given vector: |a| * |a| -}
103lengthSquared : Vec3 -> Float
104lengthSquared = Native.MJS.v3lengthSquared
106{-| The distance between two vectors. -}
107distance : Vec3 -> Vec3 -> Float
108distance = Native.MJS.v3distance
110{-| The square of the distance between two vectors. -}
111distanceSquared : Vec3 -> Vec3 -> Float
112distanceSquared = Native.MJS.v3distanceSquared
114{-| A unit vector with the same direction as the given vector: a / |a| -}
115normalize : Vec3 -> Vec3
116normalize = Native.MJS.v3normalize
118{-| Multiply the vector by a scalar: a * k -}
119scale : Vec3 -> Float -> Vec3
120scale = Native.MJS.v3scale
122{-| The dot product of a and b -}
123dot : Vec3 -> Vec3 -> Float
124dot = Native.MJS.v3dot
126{-| The cross product of a and b -}
127cross : Vec3 -> Vec3 -> Vec3
128cross = Native.MJS.v3cross
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list