Illustrating the tangent and normal vectors to a point on a curve.
import Diagrams.Backend.SVG.CmdLine
import Diagrams.Prelude
Some arbitrary points, with a cubic curve passing through them.
= map p2 [(0,0), (1,1), (2,1), (3,0), (3.5,0)]
pts
spline :: Located (Trail V2 Double)
= cubicSpline False pts spline
Computing tangent and normal vectors at a particular point on the curve.
= 0.45 -- parameter on the curve where the tangent and normal are drawn
param = atParam spline param
pt = tangentAtParam spline param
tangentVector = normalAtParam spline param normalVector
We can draw the tangent and normal vectors with lines of twice their length, with a square in between them to denote the right angle.
= fromOffsets [2 *^ v] # center
symmetricLine v = symmetricLine tangentVector
tangentLine = symmetricLine normalVector
normalLine
= square 0.1 # alignBL # rotate (signedAngleBetween tangentVector unitX) rightAngleSquare
Putting it all together, with some labels.
example :: Diagram B
= frame 0.5 $
example
strokeLocTrail spline<> mconcat
[ tangentLine"tangent" # translate tangentVector
, baselineText
, normalLine"normal" # translate normalVector
, topLeftText
, rightAngleSquare# moveTo pt # fontSize large ]
= mainWith (example :: Diagram B) main