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
- 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).
(*<>) :: 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 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)
.