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 = forall (f :: * -> *) a. (Additive f, Num a) => f a
zero forall a b. a -> (a -> b) -> b
& forall (t :: * -> *) a. R1 t => Lens' (t a) a
_x 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 = forall (f :: * -> *) a. (Additive f, Num a) => f a
zero forall a b. a -> (a -> b) -> b
& forall (t :: * -> *) a. R1 t => Lens' (t a) a
_x 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 = forall (f :: * -> *) a. (Additive f, Num a) => f a
zero forall a b. a -> (a -> b) -> b
& forall (t :: * -> *) a. R2 t => Lens' (t a) a
_y 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 = forall (f :: * -> *) a. (Additive f, Num a) => f a
zero forall a b. a -> (a -> b) -> b
& forall (t :: * -> *) a. R2 t => Lens' (t a) a
_y 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 = forall (v :: * -> *) n. v n -> Direction v n
dir 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 = forall (v :: * -> *) n. v n -> Direction v n
dir 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 = forall (v :: * -> *) n. v n -> Direction v n
dir forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall a. Floating a => a -> V2 a
angle forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall n. Iso' (Angle n) n
rad
e :: Floating n => Angle n -> V2 n
e :: forall n. Floating n => Angle n -> V2 n
e = 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 forall (f :: * -> *) a. (Metric f, Num a) => f a -> f a -> a
`dot` forall a. Num a => V2 a -> V2 a
perp V2 n
v2) forall a. Ord a => a -> a -> Bool
< n
0
cross2 :: Num n => V2 n -> V2 n -> n
cross2 :: forall n. Num n => V2 n -> V2 n -> n
cross2 (V2 n
x1 n
y1) (V2 n
x2 n
y2) = n
x1 forall a. Num a => a -> a -> a
* n
y2 forall a. Num a => a -> a -> a
- n
y1 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 forall s a. s -> Getting a s a -> a
^. forall (t :: * -> *) n.
(HasTheta t, RealFloat n) =>
Lens' (t n) (Angle n)
_theta) forall (f :: * -> *) a. (Additive f, Num a) => f a -> f a -> f a
^-^ (V2 n
v forall s a. s -> Getting a s a -> a
^. 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 forall s a. s -> Getting a s a -> a
^. forall (t :: * -> *) n.
(HasTheta t, RealFloat n) =>
Lens' (t n) (Angle n)
_theta) forall (f :: * -> *) a. (Additive f, Num a) => f a -> f a -> f a
^-^ (Direction V2 n
v forall s a. s -> Getting a s a -> a
^. forall (t :: * -> *) n.
(HasTheta t, RealFloat n) =>
Lens' (t n) (Angle n)
_theta)