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

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 

Fields

v2x :: !Scalar
 
v2y :: !Scalar
 

vector2X :: Vector2Source

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

vector2Y :: Vector2Source

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

data Vector3 Source

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

Constructors

Vector3 

Fields

v3x :: !Scalar
 
v3y :: !Scalar
 
v3z :: !Scalar
 

vcross :: Vector3 -> Vector3 -> Vector3Source

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).

vector3X :: Vector3Source

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

vector3Y :: Vector3Source

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

vector3Z :: Vector3Source

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