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.
- type Scalar = Double
- class Vector v where
- vdot :: Vector v => v -> v -> Scalar
- vmag :: Vector v => v -> Scalar
- (|*) :: Vector v => Scalar -> v -> v
- (*|) :: Vector v => v -> Scalar -> v
- vnormalise :: Vector v => v -> v
- data Vector2 = Vector2 {}
- vector2X :: Vector2
- vector2Y :: Vector2
- data Vector3 = Vector3 {}
- vcross :: Vector3 -> Vector3 -> Vector3
- vector3X :: Vector3
- vector3Y :: Vector3
- vector3Z :: Vector3
Documentation
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.
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).
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.)
The type of 3-dimensional vectors. Similar to Vector2
.
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
.
Note also that vector3X
vector3Y
= vector3Z
vcross w v = negate (vcross v w)
.