AC-Vector-1.2.2: Efficient geometric vectors.

Data.Vector

Description

This module provides several small vectors over `Double` values. All fields are strict and unpacked, so using these should be fairly efficient. Each size of vector is a seperate type. It also provides a few vector constants to save you some typing now and then.

Synopsis

# Documentation

type Scalar = DoubleSource

The type of `Vector` fields.

class Vector v whereSource

The `Vector` class. All vectors are members of this class, and it provides ways to apply functions over vectors. Typically this methods aren't used directly; rather, the other class instances for each vector are implemented in terms of these.

Methods

fromScalar :: Scalar -> vSource

vmap :: (Scalar -> Scalar) -> v -> vSource

vzip :: (Scalar -> Scalar -> Scalar) -> v -> v -> vSource

vfold :: (Scalar -> Scalar -> Scalar) -> v -> ScalarSource

Instances

 Vector Vector3 Vector Vector2

vdot :: Vector v => v -> v -> ScalarSource

Takes the dot product of two vectors [of the same dimension]. If you remember your highschool linear algebra, the dot product of two vectors V and W is equal to |V| * |W| * cos k, where |V| is the length of vector V, and k is the minimum angle between the two vectors.

vmag :: Vector v => v -> ScalarSource

Returns the magnitude of a vector (that is, it's length). Note that this is always positive or zero (never negative).

(|*) :: Vector v => Scalar -> v -> vSource

Multiply a vector by a scalar. This scales the magnitude (length) of the vector, but leaves its length unchanged. (Except in the case of a negative scalar, in which case the vector's direction is reversed.)

The operators `|*` and `*|` are identical, just with their arguments flipped.

(*|) :: Vector v => v -> Scalar -> vSource

Multiply a vector by a scalar. This scales the magnitude (length) of the vector, but leaves its length unchanged. (Except in the case of a negative scalar, in which case the vector's direction is reversed.)

The operators `*|` and `|*` are identical, just with their arguments flipped.

vnormalise :: Vector v => v -> vSource

Adjust a vector so that its length is exactly one. (Or, if the vector's length was zero, it stays zero.)

data Vector2 Source

The type of 2-dimensional vectors. It provides various class instances such as `Eq`, `Num`, `Show`, etc.

Constructors

 Vector2 Fieldsv2x :: !Scalar v2y :: !Scalar

Instances

 Eq Vector2 Fractional Vector2 Num Vector2 Ord Vector2 Show Vector2 Vector Vector2

Constant: The unit-length X vector, (1, 0).

Constant: The unit-length Y vector, (0, 1).

data Vector3 Source

The type of 3-dimensional vectors. Similar to `Vector2`.

Constructors

 Vector3 Fieldsv3x :: !Scalar v3y :: !Scalar v3z :: !Scalar

Instances

 Eq Vector3 Fractional Vector3 Num Vector3 Ord Vector3 Show Vector3 Vector Vector3

Takes the cross product of two [3D] vectors. Again, from highschool linear algebra, the cross product of vector V and W is a new vector P such that |P| = |V| * |W| * sin k (where k is the minimum angle between V and W), and the direction of P is perpendicular to both V and W. For example, `vcross vector3X vector3Y = vector3Z`. Note also that `vcross w v = negate (vcross v w)`.

Constant: The unit-length X vector, (1, 0, 0).

Constant: The unit-length Y vector, (0, 1, 0).

Constant: The unit-length Z vector, (0, 0, 1).