4

I'm having a problem with drawing a sample path of a standard Brownian motion process showing the reflection property. At the point where the red dashed line and the blue line meet I would like to mirror the blue line over the red one. Since I generate the blue line randomly I have no idea how to accomplish this.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}

\begin{figure}[h] \centering \begin{tikzpicture} \pgfmathsetseed{952} \draw[->] (-1,0) -- (6,0) node[right] {$t$}; \draw[->] (0,-1) -- (0,4) node[above] {$B_t$}; \draw[-, red, dashed] (0,0.75) -- (6,0.75);

\draw[blue] (0,0) \foreach \x in {1,...,500} { -- ++(0.01,rand*-0.2) } node[right, black] {$(t,B_t)$} \end{tikzpicture} \end{figure} \end{document}

the code generate the following picture

cfr
  • 198,882
  • 2
    At the point where the red and blue line meet? So a point reflection? Or do you want to reflect the blue path over the red dashed line? Eitherway, set the same seed again and then draw the blue line again but with the active transformation you need. Another possibility is to save the blue path and transform it with spath3 but that shouldn't be necessary here. – Qrrbrbirlbel Dec 26 '23 at 00:11
  • Welcome! Please remember to start \documentclass{<class>}. – cfr Dec 26 '23 at 00:43
  • Thank you, I didn't know you could set the random seed multiple times. But I'm still having trouble with determining how to actually mirror the blue graph from the intersection onward. I mirrored the path over the red line but I have to delete the part before the intersection. I don't know how to do that. – VlakecTomaz Dec 26 '23 at 10:55

1 Answers1

2

If you want to mirror only part of the path, I believe the usage of the libraries spath3 and intersections is the easiest approach:

  1. Name/save both the blue squiggly and the red dashed path.
  2. Split the squiggly path at the intersection with the red dashed one.
  3. Remove the component before the intersection.
  4. Draw the remaining path with the reflection transformation.

I'm using the ext.transformations.mirror library of my tikz-ext package but feel free to use any solutions provided to Can we mirror a part in tikz ("axial symmetry", "reflection")?


We could also set the same seed and draw the blue path again but this time clipped so that everything left of the intersection is clipped away but the clipping area needs to be chosen properly.


I've set line join=round so that it doesn't flip-flop between miter and bevel.

You will find that the reflected path sits on top of the original path. If this is not wanted we can change the order of drawing.

Code

\documentclass[tikz]{standalone}
%\documentclass{article}
%\usepackage{tikz}
\usetikzlibrary{
  arrows.meta,                % arrow tips
  ext.transformations.mirror, % reflect over axis
  intersections,              % find intersection between paths
  spath3}                     % split and transform paths
\begin{document}
\begin{tikzpicture}[line join=round]
\pgfmathsetseed{952}
\draw[->] (-1,0) -- (6,0) node[right] {$t$};
\draw[->] (0,-1) -- (0,4) node[above] {$B_t$};
\draw[spath/save=horiz, red, dashed] (0,0.75) -- (6,0.75);

\draw[blue, spath/save=squiggly] (0,0) foreach \x in {1,...,500}{ -- ++(0.01,rand*-0.2) } node[right, black] {$(t,B_t)$};

\draw[ draw=blue!50, spath/.cd, split at intersections with={squiggly}{horiz}, remove components={squiggly}{1}, use={squiggly, transform={ymirror=0.75}} ] node[anchor=base west] {$(t,B'_t)$}; \end{tikzpicture} \end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821
  • Thank you for the reply, everything works for me except with the transform={ymirror=0.75} parameter i got an error, so I checked out the link you referenced, but with \begin{scope}[yscale=-1, yshift=1.5] "code block" \end{scope} it didn't accomplish anything. I tried the same approach on a line and it reflected it so I'm stuck again. – VlakecTomaz Dec 26 '23 at 18:01
  • @VlakecTomaz You want to do shift=(up:1.5) since yshift=1.5 only shifts about 1.5pt. – Qrrbrbirlbel Dec 26 '23 at 19:29
  • Ok I understand now. For anyone else reading this: If ext.transformations.mirror, doen't work for you simply putting transform={yshift=1.5cm,yscale=-1} should work for you. – VlakecTomaz Dec 26 '23 at 20:56