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 :: v n
unitX = v n
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 (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 :: v n
unit_X = v n
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 (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 :: v n
unitY = v n
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 (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 :: v n
unit_Y = v n
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 (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 :: 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 :: 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 :: 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 :: 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. Iso' (Angle n) n
rad
e :: Floating n => Angle n -> V2 n
e :: 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 :: V2 n -> V2 n -> Bool
leftTurn V2 n
v1 V2 n
v2 = (V2 n
v1 V2 n -> V2 n -> n
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 :: V2 n -> V2 n -> n
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 :: 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 (t :: * -> *) n.
(HasTheta t, RealFloat n) =>
Lens' (t n) (Angle n)
_theta) Angle n -> Angle n -> Angle n
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 (t :: * -> *) n.
(HasTheta t, RealFloat n) =>
Lens' (t n) (Angle n)
_theta)
signedAngleBetweenDirs :: RealFloat n => Direction V2 n -> Direction V2 n -> Angle n
signedAngleBetweenDirs :: 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 (t :: * -> *) n.
(HasTheta t, RealFloat n) =>
Lens' (t n) (Angle n)
_theta) Angle n -> Angle n -> Angle n
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 (t :: * -> *) n.
(HasTheta t, RealFloat n) =>
Lens' (t n) (Angle n)
_theta)