hgeometry-0.5.0.0: Geometric Algorithms, Data structures, and Data types.

Data.Geometry.Vector

Synopsis

# Documentation

class Additive (Diff p) => Affine p where

An affine space is roughly a vector space in which we have forgotten or at least pretend to have forgotten the origin.

```a .+^ (b .-. a)  =  b@
(a .+^ u) .+^ v  =  a .+^ (u ^+^ v)@
(a .-. b) ^+^ v  =  (a .+^ v) .-. q@```

Minimal complete definition

Associated Types

type Diff p :: * -> *

Methods

(.-.) :: Num a => p a -> p a -> Diff p a infixl 6

Get the difference between two points as a vector offset.

(.+^) :: Num a => p a -> Diff p a -> p a infixl 6

Add a vector offset to a point.

(.-^) :: Num a => p a -> Diff p a -> p a infixl 6

Subtract a vector offset from a point.

Instances

 Affine [] Affine ((->) b) Ord k => Affine (Map k) (Eq k, Hashable k) => Affine (HashMap k) Additive f => Affine (Point f) Arity d => Affine (Vector d) Arity d => Affine (Point d) Dim * n => Affine (V * n)

qdA :: (Affine p, Foldable (Diff p), Num a) => p a -> p a -> a

Compute the quadrance of the difference (the square of the distance)

distanceA :: (Floating a, Foldable (Diff p), Affine p) => p a -> p a -> a

Distance between two points in an affine space

dot :: Metric f => forall a. Num a => f a -> f a -> a

Compute the inner product of two vectors or (equivalently) convert a vector `f a` into a covector `f a -> a`.

````>>> ````V2 1 2 `dot` V2 3 4
```11
```

norm :: Metric f => forall a. Floating a => f a -> a

Compute the norm of a vector in a metric space

isScalarMultipleOf :: (Eq r, Fractional r, Arity d) => Vector d r -> Vector d r -> Bool Source

Test if v is a scalar multiple of u.

````>>> ````v2 1 1 `isScalarMultipleOf` v2 10 10
```True
`>>> ````v2 1 1 `isScalarMultipleOf` v2 10 1
```False
`>>> ````v2 1 1 `isScalarMultipleOf` v2 11.1 11.1
```True
`>>> ````v2 1 1 `isScalarMultipleOf` v2 11.1 11.2
```False
`>>> ````v2 2 1 `isScalarMultipleOf` v2 11.1 11.2
```False
`>>> ````v2 2 1 `isScalarMultipleOf` v2 4 2
```True
`>>> ````v2 2 1 `isScalarMultipleOf` v2 4 0
```False
```

scalarMultiple :: (Eq r, Fractional r, Arity d) => Vector d r -> Vector d r -> Maybe r Source

Get the scalar labmda s.t. v = lambda * u (if it exists)