Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
General functions applicable to all vector types.
Synopsis
- type Scalar = Double
- class BasicVector v where
- class (BasicVector v, Num v, Fractional v) => Vector v
- (*|) :: Vector v => Scalar -> v -> v
- (|*) :: Vector v => v -> Scalar -> v
- (|/) :: Vector v => v -> Scalar -> v
- (/|) :: Vector v => Scalar -> v -> v
- vdot :: Vector v => v -> v -> Scalar
- vmag :: Vector v => v -> Scalar
- vnormalise :: Vector v => v -> v
- vlinear :: Vector v => Scalar -> v -> v -> v
Documentation
class BasicVector v where Source #
All vector types belong to this class. Aside from vpack
and vunpack
, these methods aren't especially useful to end-users; they're used internally by the vector arithmetic implementations.
vmap :: (Scalar -> Scalar) -> v -> v Source #
Apply a function to all vector fields.
vzip :: (Scalar -> Scalar -> Scalar) -> v -> v -> v Source #
Zip two vectors together field-by-field using the supplied function (in the style of Data.List.zipWith
).
vfold :: (Scalar -> Scalar -> Scalar) -> v -> Scalar Source #
Reduce a vector down to a single value using the supplied binary operator. The ordering in which this happens isn't guaranteed, so the operator should probably be associative and commutative.
vpack :: [Scalar] -> Maybe v Source #
Pack a list of values into a vector. Extra values are ignored, too few values yields Nothing
.
vunpack :: v -> [Scalar] Source #
Unpack a vector into a list of values. (Always succeeds.)
vpromote :: Scalar -> v Source #
Convert a Scalar
to a vector (with all components the same).
Instances
BasicVector Vector1 Source # | |
Defined in Data.Vector.V1 | |
BasicVector Vector2 Source # | |
Defined in Data.Vector.V2 | |
BasicVector Vector3 Source # | |
Defined in Data.Vector.V3 | |
BasicVector Vector4 Source # | |
Defined in Data.Vector.V4 |
class (BasicVector v, Num v, Fractional v) => Vector v Source #
Dummy class that enables you to request a vector in a type signature without needing to explicitly list Num
or Fractional
as well.
Instances
Vector Vector1 Source # | |
Defined in Data.Vector.V1 | |
Vector Vector2 Source # | |
Defined in Data.Vector.V2 | |
Vector Vector3 Source # | |
Defined in Data.Vector.V3 | |
Vector Vector4 Source # | |
Defined in Data.Vector.V4 |
(*|) :: Vector v => Scalar -> v -> v infixl 7 Source #
Scale a vector (i.e., change its length but not its direction). This operator has the same precedence as the usual (*)
operator.
The (*|)
and (|*)
operators are identical, but with their argument flipped. Just remember that the '|
' denotes the scalar part.
(|*) :: Vector v => v -> Scalar -> v infixl 7 Source #
Scale a vector (i.e., change its length but not its direction). This operator has the same precedence as the usual (*)
operator.
The (*|)
and (|*)
operators are identical, but with their argument flipped. Just remember that the '|
' denotes the scalar part.
(|/) :: Vector v => v -> Scalar -> v infixl 7 Source #
Scale a vector (i.e., change its length but not its direction). This operator has the same precedence as the usual (/)
operator.
The (/|)
and (|/)
operators are identical, but with their argument flipped. Just remember that the '|
' denotes the scalar part.
(/|) :: Vector v => Scalar -> v -> v infixl 7 Source #
Scale a vector (i.e., change its length but not its direction). This operator has the same precedence as the usual (/)
operator.
The (/|)
and (|/)
operators are identical, but with their argument flipped. Just remember that the '|
' denotes the scalar part.
vdot :: Vector v => v -> v -> Scalar Source #
Take the dot product of two vectors. This is a scalar equal to the cosine of the angle between the two vectors multiplied by the length of each vectors.
vmag :: Vector v => v -> Scalar Source #
Return the length or magnitude of a vector. (Note that this involves a slow square root operation.)
vnormalise :: Vector v => v -> v Source #
Normalise a vector. In order words, return a new vector with the same direction, but a length of exactly one. (If the vector's length is zero or very near to zero, the vector is returned unchanged.)