Arrows of a vector field.
import Diagrams.Backend.SVG.CmdLine
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE FlexibleContexts #-}
import Diagrams.Prelude
= [(x, y) | x <- [0.1, 0.3 .. 3.25], y <- [0.1, 0.3 .. 3.25]] locs
Create a list of points where the vectors will be placed.
= map p2 locs points
The function to use to create the vector field.
= r2 (sin (y + 1), sin (x + 1))
vectorField (x, y)
= map arrowAtPoint locs
arrows
= arrowAt' opts (p2 (x, y)) (sL *^ vf) # alignTL
arrowAtPoint (x, y) where
= vectorField (x, y)
vf = norm $ vectorField (x, y)
m
-- Head size is a function of the length of the vector
-- as are tail size and shaft length.
= 0.02 * m
hs = 0.004 * m
sW = 0.05 + 0.1 * m
sL = (with & arrowHead .~ spike
opts & headLength .~ normalized hs
& shaftStyle %~ lwN sW)
= position $ zip points arrows
field
= ( field # translateY 0.05
example <> ( square 3.5 # lw none # alignBL))
= mainWith (example :: Diagram B) main