I need to draw arrows between two arbitrary "nodes". The arrow ends needs to enter or exit the nodes from one of the four cardinal directions: N, S, E, W.
data Dir = N | S | E | W
deriving (Eq, Ord, Show)
cir, circles :: Diagram B
cir = circle 0.3 # showOrigin # lw thick
circles = (cir # named "1") ||| strutX 3 ||| (cir # named "2")
ctrlPoint :: Dir -> V2 Double
ctrlPoint N = r2 (0, 1)
ctrlPoint S = r2 (0, -1)
ctrlPoint E = r2 (1, 0)
ctrlPoint W = r2 (-1, 0)
-- This function should specify an arrow shaft entering nodes from directions dir1 and dir2
shaft :: Dir -> Dir -> Trail V2 Double
shaft dir1 dir2 = trailFromSegments [bézier3 (controlPoint dir1) (controlPoint dir2) (r2 (3, 0))]
example = circles # connect' (with ... & arrowShaft .~ shaft N S ) "1" "2"
In the picture above, the arrow enters correctly from North in the first circle, and South in the second. However, if I setup the points vertically, everything is rotated:
circles = (cir # named "1") === strutY 3 === (cir # named "2")
This is not correct, because I wanted the arrow to enter from North and South, respectively. It seems the shaft of the arrow is rotated altogether...
How to write my function shaft :: Dir -> Dir -> Trail V2 Double?
Thanks


I found an answer using
arrowFromLocatedTrail'instead:This version performs the necessary transformations:
Here is the signature of
bézier:It takes 3 vectors, named here V1, V2 and V3. bézier curve are by default not located in Diagrams, they just specify how to move.
So, to draw the bézier curve, we set:
The resulting bézier curve will located
atp.