simple-affine-space-0.1.1: A simple library for affine and vector spaces.

Copyright (c) Antony Courtney and Henrik Nilsson Yale University 2003 BSD-style (see the LICENSE file in the distribution) ivan.perez@keera.co.uk provisional non-portable (GHC extensions) Safe Haskell98

Data.VectorSpace

Description

Vector space type relation and basic instances.

There can be other implementations of VectorSpace, for example you could implement it with linear like this:

{--}
{--}

import FRP.Yampa
import Linear    as L

instance (Eq a, Floating a) => VectorSpace (V2 a) a where
zeroVector = L.zero
(*^) = (L.*^)
(^) = (L.^)
negateVector = L.negated
(^+^) = (L.^+^)
(^-^) = (L.^-^)
dot = L.dot


Using this you could benefit from more advanced vector operators and the improved performance linear brings while keeping a simple type class interface with few dependencies.

Synopsis

# Documentation

class (Eq a, Floating a) => VectorSpace v a | v -> a where #

Vector space type relation.

A vector space is a set (type) closed under addition and multiplication by a scalar. The type of the scalar is the field of the vector space, and it is said that v is a vector space over a.

The encoding uses a type class |VectorSpace| v a, where v represents the type of the vectors and a represents the types of the scalars.

Minimal complete definition

Methods

zeroVector :: v #

Vector with no magnitude (unit for addition).

(*^) :: a -> v -> v infixr 9 #

Multiplication by a scalar.

(^/) :: v -> a -> v infixl 9 #

Division by a scalar.

(^+^) :: v -> v -> v infixl 6 #

(^-^) :: v -> v -> v infixl 6 #

Vector subtraction

negateVector :: v -> v #

Vector negation. Addition with a negated vector should be same as subtraction.

dot :: v -> v -> a infix 7 #

Dot product (also known as scalar or inner product).

For two vectors, mathematically represented as a = a1,a2,...,an and b = b1,b2,...,bn, the dot product is a . b = a1*b1 + a2*b2 + ... + an*bn.

Some properties are derived from this. The dot product of a vector with itself is the square of its magnitude (norm), and the dot product of two orthogonal vectors is zero.

norm :: v -> a #

Vector's norm (also known as magnitude).

For a vector represented mathematically as a = a1,a2,...,an, the norm is the square root of a1^2 + a2^2 + ... + an^2.

normalize :: v -> v #

Return a vector with the same origin and orientation (angle), but such that the norm is one (the unit for multiplication by a scalar).

Instances
 # Vector space instance for Doubles, with Double scalars. Instance detailsDefined in Data.VectorSpace Methods(*^) :: Double -> Double -> Double #(^/) :: Double -> Double -> Double #(^+^) :: Double -> Double -> Double #(^-^) :: Double -> Double -> Double #dot :: Double -> Double -> Double # # Vector space instance for Floats, with Float scalars. Instance detailsDefined in Data.VectorSpace Methods(*^) :: Float -> Float -> Float #(^/) :: Float -> Float -> Float #(^+^) :: Float -> Float -> Float #(^-^) :: Float -> Float -> Float #dot :: Float -> Float -> Float #norm :: Float -> Float # RealFloat a => VectorSpace (Vector3 a) a # Instance detailsDefined in Data.Vector3 Methods(*^) :: a -> Vector3 a -> Vector3 a #(^/) :: Vector3 a -> a -> Vector3 a #(^+^) :: Vector3 a -> Vector3 a -> Vector3 a #(^-^) :: Vector3 a -> Vector3 a -> Vector3 a #negateVector :: Vector3 a -> Vector3 a #dot :: Vector3 a -> Vector3 a -> a #norm :: Vector3 a -> a #normalize :: Vector3 a -> Vector3 a # RealFloat a => VectorSpace (Vector2 a) a # Instance detailsDefined in Data.Vector2 Methods(*^) :: a -> Vector2 a -> Vector2 a #(^/) :: Vector2 a -> a -> Vector2 a #(^+^) :: Vector2 a -> Vector2 a -> Vector2 a #(^-^) :: Vector2 a -> Vector2 a -> Vector2 a #negateVector :: Vector2 a -> Vector2 a #dot :: Vector2 a -> Vector2 a -> a #norm :: Vector2 a -> a #normalize :: Vector2 a -> Vector2 a # (Eq a, Floating a) => VectorSpace (a, a) a # Vector space instance for pairs of Floating point numbers. Instance detailsDefined in Data.VectorSpace MethodszeroVector :: (a, a) #(*^) :: a -> (a, a) -> (a, a) #(^/) :: (a, a) -> a -> (a, a) #(^+^) :: (a, a) -> (a, a) -> (a, a) #(^-^) :: (a, a) -> (a, a) -> (a, a) #negateVector :: (a, a) -> (a, a) #dot :: (a, a) -> (a, a) -> a #norm :: (a, a) -> a #normalize :: (a, a) -> (a, a) # (Eq a, Floating a) => VectorSpace (a, a, a) a # Vector space instance for triplets of Floating point numbers. Instance detailsDefined in Data.VectorSpace MethodszeroVector :: (a, a, a) #(*^) :: a -> (a, a, a) -> (a, a, a) #(^/) :: (a, a, a) -> a -> (a, a, a) #(^+^) :: (a, a, a) -> (a, a, a) -> (a, a, a) #(^-^) :: (a, a, a) -> (a, a, a) -> (a, a, a) #negateVector :: (a, a, a) -> (a, a, a) #dot :: (a, a, a) -> (a, a, a) -> a #norm :: (a, a, a) -> a #normalize :: (a, a, a) -> (a, a, a) # (Eq a, Floating a) => VectorSpace (a, a, a, a) a # Vector space instance for tuples with four Floating point numbers. Instance detailsDefined in Data.VectorSpace MethodszeroVector :: (a, a, a, a) #(*^) :: a -> (a, a, a, a) -> (a, a, a, a) #(^/) :: (a, a, a, a) -> a -> (a, a, a, a) #(^+^) :: (a, a, a, a) -> (a, a, a, a) -> (a, a, a, a) #(^-^) :: (a, a, a, a) -> (a, a, a, a) -> (a, a, a, a) #negateVector :: (a, a, a, a) -> (a, a, a, a) #dot :: (a, a, a, a) -> (a, a, a, a) -> a #norm :: (a, a, a, a) -> a #normalize :: (a, a, a, a) -> (a, a, a, a) # (Eq a, Floating a) => VectorSpace (a, a, a, a, a) a # Vector space instance for tuples with five Floating point numbers. Instance detailsDefined in Data.VectorSpace MethodszeroVector :: (a, a, a, a, a) #(*^) :: a -> (a, a, a, a, a) -> (a, a, a, a, a) #(^/) :: (a, a, a, a, a) -> a -> (a, a, a, a, a) #(^+^) :: (a, a, a, a, a) -> (a, a, a, a, a) -> (a, a, a, a, a) #(^-^) :: (a, a, a, a, a) -> (a, a, a, a, a) -> (a, a, a, a, a) #negateVector :: (a, a, a, a, a) -> (a, a, a, a, a) #dot :: (a, a, a, a, a) -> (a, a, a, a, a) -> a #norm :: (a, a, a, a, a) -> a #normalize :: (a, a, a, a, a) -> (a, a, a, a, a) #