module Diagrams.TwoD.Vector
(
unitX, unitY, unit_X, unit_Y
, xDir, yDir
, angleV, angleDir, e, signedAngleBetween, signedAngleBetweenDirs
, perp, leftTurn, cross2
) where
import Control.Lens (view, (&), (.~), (^.))
import Diagrams.Angle
import Diagrams.Direction
import Diagrams.TwoD.Types
import Linear.Metric
import Linear.V2
import Linear.Vector
unitX :: (R1 v, Additive v, Num n) => v n
unitX :: forall (v :: * -> *) n. (R1 v, Additive v, Num n) => v n
unitX = v n
forall a. Num a => v a
forall (f :: * -> *) a. (Additive f, Num a) => f a
zero v n -> (v n -> v n) -> v n
forall a b. a -> (a -> b) -> b
& (n -> Identity n) -> v n -> Identity (v n)
forall a. Lens' (v a) a
forall (t :: * -> *) a. R1 t => Lens' (t a) a
_x ((n -> Identity n) -> v n -> Identity (v n)) -> n -> v n -> v n
forall s t a b. ASetter s t a b -> b -> s -> t
.~ n
1
unit_X :: (R1 v, Additive v, Num n) => v n
unit_X :: forall (v :: * -> *) n. (R1 v, Additive v, Num n) => v n
unit_X = v n
forall a. Num a => v a
forall (f :: * -> *) a. (Additive f, Num a) => f a
zero v n -> (v n -> v n) -> v n
forall a b. a -> (a -> b) -> b
& (n -> Identity n) -> v n -> Identity (v n)
forall a. Lens' (v a) a
forall (t :: * -> *) a. R1 t => Lens' (t a) a
_x ((n -> Identity n) -> v n -> Identity (v n)) -> n -> v n -> v n
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (-n
1)
unitY :: (R2 v, Additive v, Num n) => v n
unitY :: forall (v :: * -> *) n. (R2 v, Additive v, Num n) => v n
unitY = v n
forall a. Num a => v a
forall (f :: * -> *) a. (Additive f, Num a) => f a
zero v n -> (v n -> v n) -> v n
forall a b. a -> (a -> b) -> b
& (n -> Identity n) -> v n -> Identity (v n)
forall a. Lens' (v a) a
forall (t :: * -> *) a. R2 t => Lens' (t a) a
_y ((n -> Identity n) -> v n -> Identity (v n)) -> n -> v n -> v n
forall s t a b. ASetter s t a b -> b -> s -> t
.~ n
1
unit_Y :: (R2 v, Additive v, Num n) => v n
unit_Y :: forall (v :: * -> *) n. (R2 v, Additive v, Num n) => v n
unit_Y = v n
forall a. Num a => v a
forall (f :: * -> *) a. (Additive f, Num a) => f a
zero v n -> (v n -> v n) -> v n
forall a b. a -> (a -> b) -> b
& (n -> Identity n) -> v n -> Identity (v n)
forall a. Lens' (v a) a
forall (t :: * -> *) a. R2 t => Lens' (t a) a
_y ((n -> Identity n) -> v n -> Identity (v n)) -> n -> v n -> v n
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (-n
1)
xDir :: (R1 v, Additive v, Num n) => Direction v n
xDir :: forall (v :: * -> *) n. (R1 v, Additive v, Num n) => Direction v n
xDir = v n -> Direction v n
forall (v :: * -> *) n. v n -> Direction v n
dir v n
forall (v :: * -> *) n. (R1 v, Additive v, Num n) => v n
unitX
yDir :: (R2 v, Additive v, Num n) => Direction v n
yDir :: forall (v :: * -> *) n. (R2 v, Additive v, Num n) => Direction v n
yDir = v n -> Direction v n
forall (v :: * -> *) n. v n -> Direction v n
dir v n
forall (v :: * -> *) n. (R2 v, Additive v, Num n) => v n
unitY
angleDir :: Floating n => Angle n -> Direction V2 n
angleDir :: forall n. Floating n => Angle n -> Direction V2 n
angleDir = V2 n -> Direction V2 n
forall (v :: * -> *) n. v n -> Direction v n
dir (V2 n -> Direction V2 n)
-> (Angle n -> V2 n) -> Angle n -> Direction V2 n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Angle n -> V2 n
forall n. Floating n => Angle n -> V2 n
angleV
angleV :: Floating n => Angle n -> V2 n
angleV :: forall n. Floating n => Angle n -> V2 n
angleV = n -> V2 n
forall a. Floating a => a -> V2 a
angle (n -> V2 n) -> (Angle n -> n) -> Angle n -> V2 n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting n (Angle n) n -> Angle n -> n
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting n (Angle n) n
forall n (p :: * -> * -> *) (f :: * -> *).
(Profunctor p, Functor f) =>
p n (f n) -> p (Angle n) (f (Angle n))
rad
e :: Floating n => Angle n -> V2 n
e :: forall n. Floating n => Angle n -> V2 n
e = Angle n -> V2 n
forall n. Floating n => Angle n -> V2 n
angleV
leftTurn :: (Num n, Ord n) => V2 n -> V2 n -> Bool
leftTurn :: forall n. (Num n, Ord n) => V2 n -> V2 n -> Bool
leftTurn V2 n
v1 V2 n
v2 = (V2 n
v1 V2 n -> V2 n -> n
forall a. Num a => V2 a -> V2 a -> a
forall (f :: * -> *) a. (Metric f, Num a) => f a -> f a -> a
`dot` V2 n -> V2 n
forall a. Num a => V2 a -> V2 a
perp V2 n
v2) n -> n -> Bool
forall a. Ord a => a -> a -> Bool
< n
0
cross2 :: Num n => V2 n -> V2 n -> n
cross2 :: forall a. Num a => V2 a -> V2 a -> a
cross2 (V2 n
x1 n
y1) (V2 n
x2 n
y2) = n
x1 n -> n -> n
forall a. Num a => a -> a -> a
* n
y2 n -> n -> n
forall a. Num a => a -> a -> a
- n
y1 n -> n -> n
forall a. Num a => a -> a -> a
* n
x2
signedAngleBetween :: RealFloat n => V2 n -> V2 n -> Angle n
signedAngleBetween :: forall n. RealFloat n => V2 n -> V2 n -> Angle n
signedAngleBetween V2 n
u V2 n
v = (V2 n
u V2 n -> Getting (Angle n) (V2 n) (Angle n) -> Angle n
forall s a. s -> Getting a s a -> a
^. Getting (Angle n) (V2 n) (Angle n)
forall n. RealFloat n => Lens' (V2 n) (Angle n)
Lens' (V2 n) (Angle n)
forall (t :: * -> *) n.
(HasTheta t, RealFloat n) =>
Lens' (t n) (Angle n)
_theta) Angle n -> Angle n -> Angle n
forall a. Num a => Angle a -> Angle a -> Angle a
forall (f :: * -> *) a. (Additive f, Num a) => f a -> f a -> f a
^-^ (V2 n
v V2 n -> Getting (Angle n) (V2 n) (Angle n) -> Angle n
forall s a. s -> Getting a s a -> a
^. Getting (Angle n) (V2 n) (Angle n)
forall n. RealFloat n => Lens' (V2 n) (Angle n)
Lens' (V2 n) (Angle n)
forall (t :: * -> *) n.
(HasTheta t, RealFloat n) =>
Lens' (t n) (Angle n)
_theta)
signedAngleBetweenDirs :: RealFloat n => Direction V2 n -> Direction V2 n -> Angle n
signedAngleBetweenDirs :: forall n.
RealFloat n =>
Direction V2 n -> Direction V2 n -> Angle n
signedAngleBetweenDirs Direction V2 n
u Direction V2 n
v = (Direction V2 n
u Direction V2 n
-> Getting (Angle n) (Direction V2 n) (Angle n) -> Angle n
forall s a. s -> Getting a s a -> a
^. Getting (Angle n) (Direction V2 n) (Angle n)
forall n. RealFloat n => Lens' (Direction V2 n) (Angle n)
Lens' (Direction V2 n) (Angle n)
forall (t :: * -> *) n.
(HasTheta t, RealFloat n) =>
Lens' (t n) (Angle n)
_theta) Angle n -> Angle n -> Angle n
forall a. Num a => Angle a -> Angle a -> Angle a
forall (f :: * -> *) a. (Additive f, Num a) => f a -> f a -> f a
^-^ (Direction V2 n
v Direction V2 n
-> Getting (Angle n) (Direction V2 n) (Angle n) -> Angle n
forall s a. s -> Getting a s a -> a
^. Getting (Angle n) (Direction V2 n) (Angle n)
forall n. RealFloat n => Lens' (Direction V2 n) (Angle n)
Lens' (Direction V2 n) (Angle n)
forall (t :: * -> *) n.
(HasTheta t, RealFloat n) =>
Lens' (t n) (Angle n)
_theta)