How to draw a 2-dim Brownian motion into a disk
I should draw a Brownian motion starting into a disk until the first exit time from this disk in my LaTeX work (and after i should do similar things with SLE_k), how can i do?
EDIT:
I draw some planar Brownian motion using the following code, the only thing i don't know how to do is to make a circle and find an intersection
documentclass[parskip]{scrartcl}
usepackage[margin=15mm]{geometry}
usepackage{tikz}
begin{document}
newcommand{Emmett}[5]{% points, advance, rand factor, options, end label
draw[#4] (0,0)
foreach x in {1,...,#1}
{ -- ++(rand*#2,rand*#3)
}
node[right] {#5};
}
begin{tikzpicture}
Emmett{750}{0.1}{0.1}{red}{first one}
Emmett{750}{0.1}{0.1}{green}{second one}
Emmett{750}{0.1}{0.1}{blue}{third one}
end{tikzpicture}
end{document}
tikz-pgf draw
|
show 5 more comments
I should draw a Brownian motion starting into a disk until the first exit time from this disk in my LaTeX work (and after i should do similar things with SLE_k), how can i do?
EDIT:
I draw some planar Brownian motion using the following code, the only thing i don't know how to do is to make a circle and find an intersection
documentclass[parskip]{scrartcl}
usepackage[margin=15mm]{geometry}
usepackage{tikz}
begin{document}
newcommand{Emmett}[5]{% points, advance, rand factor, options, end label
draw[#4] (0,0)
foreach x in {1,...,#1}
{ -- ++(rand*#2,rand*#3)
}
node[right] {#5};
}
begin{tikzpicture}
Emmett{750}{0.1}{0.1}{red}{first one}
Emmett{750}{0.1}{0.1}{green}{second one}
Emmett{750}{0.1}{0.1}{blue}{third one}
end{tikzpicture}
end{document}
tikz-pgf draw
2
Welcome to TeX.SX! Please help us help you by providing a minimal compilable code example of what you've tried so far (MWE).
– TeXnician
Feb 16 at 15:42
2
... and a sketch to show what you want clearer.
– JouleV
Feb 16 at 15:45
I wrote a paper in .tex ( on overleaf) and i should draw a 2-dim Brownian motion into it, or maybe using some kind of program to make this image (i am a newbie of latex, i'm sorry ):
– Claudio Delfino
Feb 16 at 15:48
I don't want a grafic of a function but a draw of a possible 2-dim Brownian motion, i.e., a grafic in the plane of (B_1(t),B_2(t)) where B_1(t),B_2(t) are two Brownian motion starting at a point |z|<1, until the time that B_1(t)^2 + B_2(t)^2=1, i don't know if it is possible directly on latex
– Claudio Delfino
Feb 16 at 15:54
@ClaudioDelfino Just to note that if you want to modify people, use @ and their username, as I use here.
– JouleV
Feb 16 at 16:17
|
show 5 more comments
I should draw a Brownian motion starting into a disk until the first exit time from this disk in my LaTeX work (and after i should do similar things with SLE_k), how can i do?
EDIT:
I draw some planar Brownian motion using the following code, the only thing i don't know how to do is to make a circle and find an intersection
documentclass[parskip]{scrartcl}
usepackage[margin=15mm]{geometry}
usepackage{tikz}
begin{document}
newcommand{Emmett}[5]{% points, advance, rand factor, options, end label
draw[#4] (0,0)
foreach x in {1,...,#1}
{ -- ++(rand*#2,rand*#3)
}
node[right] {#5};
}
begin{tikzpicture}
Emmett{750}{0.1}{0.1}{red}{first one}
Emmett{750}{0.1}{0.1}{green}{second one}
Emmett{750}{0.1}{0.1}{blue}{third one}
end{tikzpicture}
end{document}
tikz-pgf draw
I should draw a Brownian motion starting into a disk until the first exit time from this disk in my LaTeX work (and after i should do similar things with SLE_k), how can i do?
EDIT:
I draw some planar Brownian motion using the following code, the only thing i don't know how to do is to make a circle and find an intersection
documentclass[parskip]{scrartcl}
usepackage[margin=15mm]{geometry}
usepackage{tikz}
begin{document}
newcommand{Emmett}[5]{% points, advance, rand factor, options, end label
draw[#4] (0,0)
foreach x in {1,...,#1}
{ -- ++(rand*#2,rand*#3)
}
node[right] {#5};
}
begin{tikzpicture}
Emmett{750}{0.1}{0.1}{red}{first one}
Emmett{750}{0.1}{0.1}{green}{second one}
Emmett{750}{0.1}{0.1}{blue}{third one}
end{tikzpicture}
end{document}
tikz-pgf draw
tikz-pgf draw
edited Feb 17 at 12:17
JouleV
4,0801938
4,0801938
asked Feb 16 at 15:41
Claudio DelfinoClaudio Delfino
112
112
2
Welcome to TeX.SX! Please help us help you by providing a minimal compilable code example of what you've tried so far (MWE).
– TeXnician
Feb 16 at 15:42
2
... and a sketch to show what you want clearer.
– JouleV
Feb 16 at 15:45
I wrote a paper in .tex ( on overleaf) and i should draw a 2-dim Brownian motion into it, or maybe using some kind of program to make this image (i am a newbie of latex, i'm sorry ):
– Claudio Delfino
Feb 16 at 15:48
I don't want a grafic of a function but a draw of a possible 2-dim Brownian motion, i.e., a grafic in the plane of (B_1(t),B_2(t)) where B_1(t),B_2(t) are two Brownian motion starting at a point |z|<1, until the time that B_1(t)^2 + B_2(t)^2=1, i don't know if it is possible directly on latex
– Claudio Delfino
Feb 16 at 15:54
@ClaudioDelfino Just to note that if you want to modify people, use @ and their username, as I use here.
– JouleV
Feb 16 at 16:17
|
show 5 more comments
2
Welcome to TeX.SX! Please help us help you by providing a minimal compilable code example of what you've tried so far (MWE).
– TeXnician
Feb 16 at 15:42
2
... and a sketch to show what you want clearer.
– JouleV
Feb 16 at 15:45
I wrote a paper in .tex ( on overleaf) and i should draw a 2-dim Brownian motion into it, or maybe using some kind of program to make this image (i am a newbie of latex, i'm sorry ):
– Claudio Delfino
Feb 16 at 15:48
I don't want a grafic of a function but a draw of a possible 2-dim Brownian motion, i.e., a grafic in the plane of (B_1(t),B_2(t)) where B_1(t),B_2(t) are two Brownian motion starting at a point |z|<1, until the time that B_1(t)^2 + B_2(t)^2=1, i don't know if it is possible directly on latex
– Claudio Delfino
Feb 16 at 15:54
@ClaudioDelfino Just to note that if you want to modify people, use @ and their username, as I use here.
– JouleV
Feb 16 at 16:17
2
2
Welcome to TeX.SX! Please help us help you by providing a minimal compilable code example of what you've tried so far (MWE).
– TeXnician
Feb 16 at 15:42
Welcome to TeX.SX! Please help us help you by providing a minimal compilable code example of what you've tried so far (MWE).
– TeXnician
Feb 16 at 15:42
2
2
... and a sketch to show what you want clearer.
– JouleV
Feb 16 at 15:45
... and a sketch to show what you want clearer.
– JouleV
Feb 16 at 15:45
I wrote a paper in .tex ( on overleaf) and i should draw a 2-dim Brownian motion into it, or maybe using some kind of program to make this image (i am a newbie of latex, i'm sorry ):
– Claudio Delfino
Feb 16 at 15:48
I wrote a paper in .tex ( on overleaf) and i should draw a 2-dim Brownian motion into it, or maybe using some kind of program to make this image (i am a newbie of latex, i'm sorry ):
– Claudio Delfino
Feb 16 at 15:48
I don't want a grafic of a function but a draw of a possible 2-dim Brownian motion, i.e., a grafic in the plane of (B_1(t),B_2(t)) where B_1(t),B_2(t) are two Brownian motion starting at a point |z|<1, until the time that B_1(t)^2 + B_2(t)^2=1, i don't know if it is possible directly on latex
– Claudio Delfino
Feb 16 at 15:54
I don't want a grafic of a function but a draw of a possible 2-dim Brownian motion, i.e., a grafic in the plane of (B_1(t),B_2(t)) where B_1(t),B_2(t) are two Brownian motion starting at a point |z|<1, until the time that B_1(t)^2 + B_2(t)^2=1, i don't know if it is possible directly on latex
– Claudio Delfino
Feb 16 at 15:54
@ClaudioDelfino Just to note that if you want to modify people, use @ and their username, as I use here.
– JouleV
Feb 16 at 16:17
@ClaudioDelfino Just to note that if you want to modify people, use @ and their username, as I use here.
– JouleV
Feb 16 at 16:17
|
show 5 more comments
2 Answers
2
active
oldest
votes
This adds circles around the Brownian motions.
documentclass[parskip]{scrartcl}
usepackage[margin=15mm]{geometry}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
newcommand{Emmett}[5]{% points, advance, rand factor, options, end label
begin{scope}[local bounding box=Emmett]
draw[#4] (0,0)
foreach x in {1,...,#1}
{ -- ++(rand*#2,rand*#3)
} coordinate(Emmett-last);
end{scope}
node[anchor=west,#4] at (Emmett-last) {#5};
node[circle,draw,#4,fit=(Emmett.south west) (Emmett.north east),inner sep=0.5pt]{};
}
begin{tikzpicture}
Emmett{750}{0.1}{0.1}{red}{first one}
Emmett{750}{0.1}{0.1}{green}{second one}
Emmett{750}{0.1}{0.1}{blue}{third one}
end{tikzpicture}

I do, however, not quite understand what you mean by intersections. Something like this perhaps?
documentclass[parskip]{scrartcl}
usepackage[margin=15mm]{geometry}
usepackage{tikz}
usetikzlibrary{fit,intersections}
begin{document}
newcommand{Emmett}[6]{% points, advance, rand factor, options, end label
begin{scope}[local bounding box=Emmett]
draw[#4] (0,0)
foreach x in {1,...,#1}
{ -- ++(rand*#2,rand*#3)
} coordinate(Emmett-last);
end{scope}
node[anchor=west,#4] at (Emmett-last) {#5};
node[name path=#6,circle,draw,#4,fit=(Emmett.south west) (Emmett.north east),inner sep=0.5pt]{};
}
begin{tikzpicture}
Emmett{750}{0.1}{0.1}{red}{first one}{first}
Emmett{750}{0.1}{0.1}{green}{second one}{second}
Emmett{750}{0.1}{0.1}{blue}{third one}{third}
fill[name intersections={of=first and second}] (intersection-1) circle(1pt)
(intersection-2) circle(1pt);
end{tikzpicture}
end{document}

add a comment |
I've put together a command using the basic layer of pgf (the front end tikz didn't provide quite enough flexibility for your problem). When called from a pgfpicture environment, it starts the Brownian motion from the centre of the disc and continues until an intersection occurs. The coordinates of the intersection point are then printed. A number of walks can be run on the same disc (in different colours).
I hadn't done any work with the pgf basic layer before so it is quite likely that improvements can be made to the code (open to suggestions here).
I've tried to comment the code but will admit the pgf layer syntax can appear quite alien if you are only familiar with the front end. Here I will summarise the salient points:
- The tikz
intersectionslibrary is used to calculate the intersection of two paths (the disc and a walk). See p.1058 of the tikz manual (V. 3.1). - The pgf command
pgfgetlastxyprovides access to the last coordinates of a path, and is the key player in theforeachloop used to construct the walk - At each step, the distance of the walk from the origin can be calculated, allowing us to terminate the walk if it has gone outside of the disc.
The code:
documentclass{article}
usepackage{geometry}
usepackage{tikz} % Includes the basic layer (pgf) and mathematical engine
% Library to determine points of intersection of two paths
usetikzlibrary{intersections} % See manual p.1058
% Command to be used inside a pgfpicture. Requires tikz, tikz.intersections
newcommanddiscmotion[4]
{ % #1: Walk number (currently only used to make sure intersection points are printed in different places)
% #2: Number of steps in walk
% #3: If 1, Terminate after first intersection. 0 (or any other integer): Always complete walk.
% #4: Path color (intersections always circled in red)
pgfintersectionsortbyfirstpath % If multiple intersections, order according to first path (the random walk)
pgfintersectionofpaths % Record intersections between the following two paths pgfintersectionofpaths{PATH 1}{PATH 2}
{
pgfpathmoveto{pgfpointorigin} % Start path at origin
foreach x in {1,...,#2} % Walk loop
{
pgfgetlastxy{macrox}{macroy} % Get coordinates from last step
pgfmathsetlengthmacro{dist}{veclen(macrox,macroy)} % Calculate distance from origin (pt)
ifnum#3=1relax % Only check if outside disc if #3 has a value of 1
ifdim dist < 50pt % Check whether path has gone outside disc
pgfpathlineto{pgfpointadd{pgfpoint{macrox}{macroy}}{pgfpoint{rand*10}{rand*10}}} % Add random vector onto path
fi
else % Otherwise always continue path
pgfpathlineto{pgfpointadd{pgfpoint{macrox}{macroy}}{pgfpoint{rand*10}{rand*10}}}
fi
}
% Now actually draw the path
color{#4} % Change color temporarily
pgfgetpathtemppath
pgfusepath{stroke}
pgfsetpathtemppath
color{black} % Restore color (for circle)
}
{
% Path for disc
pgfpathcircle{pgfpointorigin}{50pt}
pgfgetpathtemppath
pgfusepath{stroke}
pgfsetpathtemppath
}
% Lengths to store intersections points (origin = centre of disc), in pt.
newdimenxintersect
newdimenyintersect
pgfintersectionsortbyfirstpath % Repeat of earlier command to be sure :)
foreach s in {1,...,pgfintersectionsolutions} % Iterate through intersection object (list of coordinates)
{
pgfpathcircle{pgfpointintersectionsolution{s}}{2pt} % Circle the intersection point
pgfextractx{xintersect}{pgfpointintersectionsolution{s}} % Get x coordinate of current intersection
pgfextractx{yintersect}{pgfpointintersectionsolution{s}} % Get y coordinate of current intersection
% Add a text object to right of disc, using pgfmathparse to change the coordinates in pt to cm (precision 4)
pgftext[at=pgfpointscale{0.5}{% Just some scaling
pgfpointadd{pgfpointadd{pgfpoint{0cm}{6cm}}{pgfpoint{0cm}{-#1 cm}}}{pgfpoint{12cm}{-s cm}}}] % {test}
{small#4: $x=$pgfmathparse{xintersect/28.45274}pgfmathprintnumber[fixed,precision=4]{pgfmathresult} $y=$pgfmathparse{yintersect/28.45274}pgfmathprintnumber[fixed,precision=4]{pgfmathresult}}
}
color{red}
% pgfusepath{fill} % Fill intersection circles (instead of stroke)
pgfusepath{stroke} % Draw intersection paths pgfusepath{fill} could be used here
color{black} % Restore color
}
begin{document}
begin{pgfpicture}
discmotion{1}{250}{1}{black}
discmotion{2}{250}{1}{blue}
discmotion{3}{250}{1}{orange}
end{pgfpicture}
end{document}
Example output with above code:

Note that the step sizes are quite large (rand*10); you may want to reduce this. You may also want to add additional arguments, specifying the radius of the disc, for example (currently fixed at 50pt). Lastly, there is also the option to not stop at the firsrt intersection, but always complete the prescribed number of steps (recording all intersections). Change the first argument from 1 to use this. For example,
begin{pgfpicture}
discmotion{1}{200}{0}{black} % Don't stop until 200!
end{pgfpicture}
just produced

add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f475202%2fhow-to-draw-a-2-dim-brownian-motion-into-a-disk%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
This adds circles around the Brownian motions.
documentclass[parskip]{scrartcl}
usepackage[margin=15mm]{geometry}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
newcommand{Emmett}[5]{% points, advance, rand factor, options, end label
begin{scope}[local bounding box=Emmett]
draw[#4] (0,0)
foreach x in {1,...,#1}
{ -- ++(rand*#2,rand*#3)
} coordinate(Emmett-last);
end{scope}
node[anchor=west,#4] at (Emmett-last) {#5};
node[circle,draw,#4,fit=(Emmett.south west) (Emmett.north east),inner sep=0.5pt]{};
}
begin{tikzpicture}
Emmett{750}{0.1}{0.1}{red}{first one}
Emmett{750}{0.1}{0.1}{green}{second one}
Emmett{750}{0.1}{0.1}{blue}{third one}
end{tikzpicture}

I do, however, not quite understand what you mean by intersections. Something like this perhaps?
documentclass[parskip]{scrartcl}
usepackage[margin=15mm]{geometry}
usepackage{tikz}
usetikzlibrary{fit,intersections}
begin{document}
newcommand{Emmett}[6]{% points, advance, rand factor, options, end label
begin{scope}[local bounding box=Emmett]
draw[#4] (0,0)
foreach x in {1,...,#1}
{ -- ++(rand*#2,rand*#3)
} coordinate(Emmett-last);
end{scope}
node[anchor=west,#4] at (Emmett-last) {#5};
node[name path=#6,circle,draw,#4,fit=(Emmett.south west) (Emmett.north east),inner sep=0.5pt]{};
}
begin{tikzpicture}
Emmett{750}{0.1}{0.1}{red}{first one}{first}
Emmett{750}{0.1}{0.1}{green}{second one}{second}
Emmett{750}{0.1}{0.1}{blue}{third one}{third}
fill[name intersections={of=first and second}] (intersection-1) circle(1pt)
(intersection-2) circle(1pt);
end{tikzpicture}
end{document}

add a comment |
This adds circles around the Brownian motions.
documentclass[parskip]{scrartcl}
usepackage[margin=15mm]{geometry}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
newcommand{Emmett}[5]{% points, advance, rand factor, options, end label
begin{scope}[local bounding box=Emmett]
draw[#4] (0,0)
foreach x in {1,...,#1}
{ -- ++(rand*#2,rand*#3)
} coordinate(Emmett-last);
end{scope}
node[anchor=west,#4] at (Emmett-last) {#5};
node[circle,draw,#4,fit=(Emmett.south west) (Emmett.north east),inner sep=0.5pt]{};
}
begin{tikzpicture}
Emmett{750}{0.1}{0.1}{red}{first one}
Emmett{750}{0.1}{0.1}{green}{second one}
Emmett{750}{0.1}{0.1}{blue}{third one}
end{tikzpicture}

I do, however, not quite understand what you mean by intersections. Something like this perhaps?
documentclass[parskip]{scrartcl}
usepackage[margin=15mm]{geometry}
usepackage{tikz}
usetikzlibrary{fit,intersections}
begin{document}
newcommand{Emmett}[6]{% points, advance, rand factor, options, end label
begin{scope}[local bounding box=Emmett]
draw[#4] (0,0)
foreach x in {1,...,#1}
{ -- ++(rand*#2,rand*#3)
} coordinate(Emmett-last);
end{scope}
node[anchor=west,#4] at (Emmett-last) {#5};
node[name path=#6,circle,draw,#4,fit=(Emmett.south west) (Emmett.north east),inner sep=0.5pt]{};
}
begin{tikzpicture}
Emmett{750}{0.1}{0.1}{red}{first one}{first}
Emmett{750}{0.1}{0.1}{green}{second one}{second}
Emmett{750}{0.1}{0.1}{blue}{third one}{third}
fill[name intersections={of=first and second}] (intersection-1) circle(1pt)
(intersection-2) circle(1pt);
end{tikzpicture}
end{document}

add a comment |
This adds circles around the Brownian motions.
documentclass[parskip]{scrartcl}
usepackage[margin=15mm]{geometry}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
newcommand{Emmett}[5]{% points, advance, rand factor, options, end label
begin{scope}[local bounding box=Emmett]
draw[#4] (0,0)
foreach x in {1,...,#1}
{ -- ++(rand*#2,rand*#3)
} coordinate(Emmett-last);
end{scope}
node[anchor=west,#4] at (Emmett-last) {#5};
node[circle,draw,#4,fit=(Emmett.south west) (Emmett.north east),inner sep=0.5pt]{};
}
begin{tikzpicture}
Emmett{750}{0.1}{0.1}{red}{first one}
Emmett{750}{0.1}{0.1}{green}{second one}
Emmett{750}{0.1}{0.1}{blue}{third one}
end{tikzpicture}

I do, however, not quite understand what you mean by intersections. Something like this perhaps?
documentclass[parskip]{scrartcl}
usepackage[margin=15mm]{geometry}
usepackage{tikz}
usetikzlibrary{fit,intersections}
begin{document}
newcommand{Emmett}[6]{% points, advance, rand factor, options, end label
begin{scope}[local bounding box=Emmett]
draw[#4] (0,0)
foreach x in {1,...,#1}
{ -- ++(rand*#2,rand*#3)
} coordinate(Emmett-last);
end{scope}
node[anchor=west,#4] at (Emmett-last) {#5};
node[name path=#6,circle,draw,#4,fit=(Emmett.south west) (Emmett.north east),inner sep=0.5pt]{};
}
begin{tikzpicture}
Emmett{750}{0.1}{0.1}{red}{first one}{first}
Emmett{750}{0.1}{0.1}{green}{second one}{second}
Emmett{750}{0.1}{0.1}{blue}{third one}{third}
fill[name intersections={of=first and second}] (intersection-1) circle(1pt)
(intersection-2) circle(1pt);
end{tikzpicture}
end{document}

This adds circles around the Brownian motions.
documentclass[parskip]{scrartcl}
usepackage[margin=15mm]{geometry}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
newcommand{Emmett}[5]{% points, advance, rand factor, options, end label
begin{scope}[local bounding box=Emmett]
draw[#4] (0,0)
foreach x in {1,...,#1}
{ -- ++(rand*#2,rand*#3)
} coordinate(Emmett-last);
end{scope}
node[anchor=west,#4] at (Emmett-last) {#5};
node[circle,draw,#4,fit=(Emmett.south west) (Emmett.north east),inner sep=0.5pt]{};
}
begin{tikzpicture}
Emmett{750}{0.1}{0.1}{red}{first one}
Emmett{750}{0.1}{0.1}{green}{second one}
Emmett{750}{0.1}{0.1}{blue}{third one}
end{tikzpicture}

I do, however, not quite understand what you mean by intersections. Something like this perhaps?
documentclass[parskip]{scrartcl}
usepackage[margin=15mm]{geometry}
usepackage{tikz}
usetikzlibrary{fit,intersections}
begin{document}
newcommand{Emmett}[6]{% points, advance, rand factor, options, end label
begin{scope}[local bounding box=Emmett]
draw[#4] (0,0)
foreach x in {1,...,#1}
{ -- ++(rand*#2,rand*#3)
} coordinate(Emmett-last);
end{scope}
node[anchor=west,#4] at (Emmett-last) {#5};
node[name path=#6,circle,draw,#4,fit=(Emmett.south west) (Emmett.north east),inner sep=0.5pt]{};
}
begin{tikzpicture}
Emmett{750}{0.1}{0.1}{red}{first one}{first}
Emmett{750}{0.1}{0.1}{green}{second one}{second}
Emmett{750}{0.1}{0.1}{blue}{third one}{third}
fill[name intersections={of=first and second}] (intersection-1) circle(1pt)
(intersection-2) circle(1pt);
end{tikzpicture}
end{document}

edited Feb 17 at 12:13
answered Feb 17 at 11:51
marmotmarmot
103k4121233
103k4121233
add a comment |
add a comment |
I've put together a command using the basic layer of pgf (the front end tikz didn't provide quite enough flexibility for your problem). When called from a pgfpicture environment, it starts the Brownian motion from the centre of the disc and continues until an intersection occurs. The coordinates of the intersection point are then printed. A number of walks can be run on the same disc (in different colours).
I hadn't done any work with the pgf basic layer before so it is quite likely that improvements can be made to the code (open to suggestions here).
I've tried to comment the code but will admit the pgf layer syntax can appear quite alien if you are only familiar with the front end. Here I will summarise the salient points:
- The tikz
intersectionslibrary is used to calculate the intersection of two paths (the disc and a walk). See p.1058 of the tikz manual (V. 3.1). - The pgf command
pgfgetlastxyprovides access to the last coordinates of a path, and is the key player in theforeachloop used to construct the walk - At each step, the distance of the walk from the origin can be calculated, allowing us to terminate the walk if it has gone outside of the disc.
The code:
documentclass{article}
usepackage{geometry}
usepackage{tikz} % Includes the basic layer (pgf) and mathematical engine
% Library to determine points of intersection of two paths
usetikzlibrary{intersections} % See manual p.1058
% Command to be used inside a pgfpicture. Requires tikz, tikz.intersections
newcommanddiscmotion[4]
{ % #1: Walk number (currently only used to make sure intersection points are printed in different places)
% #2: Number of steps in walk
% #3: If 1, Terminate after first intersection. 0 (or any other integer): Always complete walk.
% #4: Path color (intersections always circled in red)
pgfintersectionsortbyfirstpath % If multiple intersections, order according to first path (the random walk)
pgfintersectionofpaths % Record intersections between the following two paths pgfintersectionofpaths{PATH 1}{PATH 2}
{
pgfpathmoveto{pgfpointorigin} % Start path at origin
foreach x in {1,...,#2} % Walk loop
{
pgfgetlastxy{macrox}{macroy} % Get coordinates from last step
pgfmathsetlengthmacro{dist}{veclen(macrox,macroy)} % Calculate distance from origin (pt)
ifnum#3=1relax % Only check if outside disc if #3 has a value of 1
ifdim dist < 50pt % Check whether path has gone outside disc
pgfpathlineto{pgfpointadd{pgfpoint{macrox}{macroy}}{pgfpoint{rand*10}{rand*10}}} % Add random vector onto path
fi
else % Otherwise always continue path
pgfpathlineto{pgfpointadd{pgfpoint{macrox}{macroy}}{pgfpoint{rand*10}{rand*10}}}
fi
}
% Now actually draw the path
color{#4} % Change color temporarily
pgfgetpathtemppath
pgfusepath{stroke}
pgfsetpathtemppath
color{black} % Restore color (for circle)
}
{
% Path for disc
pgfpathcircle{pgfpointorigin}{50pt}
pgfgetpathtemppath
pgfusepath{stroke}
pgfsetpathtemppath
}
% Lengths to store intersections points (origin = centre of disc), in pt.
newdimenxintersect
newdimenyintersect
pgfintersectionsortbyfirstpath % Repeat of earlier command to be sure :)
foreach s in {1,...,pgfintersectionsolutions} % Iterate through intersection object (list of coordinates)
{
pgfpathcircle{pgfpointintersectionsolution{s}}{2pt} % Circle the intersection point
pgfextractx{xintersect}{pgfpointintersectionsolution{s}} % Get x coordinate of current intersection
pgfextractx{yintersect}{pgfpointintersectionsolution{s}} % Get y coordinate of current intersection
% Add a text object to right of disc, using pgfmathparse to change the coordinates in pt to cm (precision 4)
pgftext[at=pgfpointscale{0.5}{% Just some scaling
pgfpointadd{pgfpointadd{pgfpoint{0cm}{6cm}}{pgfpoint{0cm}{-#1 cm}}}{pgfpoint{12cm}{-s cm}}}] % {test}
{small#4: $x=$pgfmathparse{xintersect/28.45274}pgfmathprintnumber[fixed,precision=4]{pgfmathresult} $y=$pgfmathparse{yintersect/28.45274}pgfmathprintnumber[fixed,precision=4]{pgfmathresult}}
}
color{red}
% pgfusepath{fill} % Fill intersection circles (instead of stroke)
pgfusepath{stroke} % Draw intersection paths pgfusepath{fill} could be used here
color{black} % Restore color
}
begin{document}
begin{pgfpicture}
discmotion{1}{250}{1}{black}
discmotion{2}{250}{1}{blue}
discmotion{3}{250}{1}{orange}
end{pgfpicture}
end{document}
Example output with above code:

Note that the step sizes are quite large (rand*10); you may want to reduce this. You may also want to add additional arguments, specifying the radius of the disc, for example (currently fixed at 50pt). Lastly, there is also the option to not stop at the firsrt intersection, but always complete the prescribed number of steps (recording all intersections). Change the first argument from 1 to use this. For example,
begin{pgfpicture}
discmotion{1}{200}{0}{black} % Don't stop until 200!
end{pgfpicture}
just produced

add a comment |
I've put together a command using the basic layer of pgf (the front end tikz didn't provide quite enough flexibility for your problem). When called from a pgfpicture environment, it starts the Brownian motion from the centre of the disc and continues until an intersection occurs. The coordinates of the intersection point are then printed. A number of walks can be run on the same disc (in different colours).
I hadn't done any work with the pgf basic layer before so it is quite likely that improvements can be made to the code (open to suggestions here).
I've tried to comment the code but will admit the pgf layer syntax can appear quite alien if you are only familiar with the front end. Here I will summarise the salient points:
- The tikz
intersectionslibrary is used to calculate the intersection of two paths (the disc and a walk). See p.1058 of the tikz manual (V. 3.1). - The pgf command
pgfgetlastxyprovides access to the last coordinates of a path, and is the key player in theforeachloop used to construct the walk - At each step, the distance of the walk from the origin can be calculated, allowing us to terminate the walk if it has gone outside of the disc.
The code:
documentclass{article}
usepackage{geometry}
usepackage{tikz} % Includes the basic layer (pgf) and mathematical engine
% Library to determine points of intersection of two paths
usetikzlibrary{intersections} % See manual p.1058
% Command to be used inside a pgfpicture. Requires tikz, tikz.intersections
newcommanddiscmotion[4]
{ % #1: Walk number (currently only used to make sure intersection points are printed in different places)
% #2: Number of steps in walk
% #3: If 1, Terminate after first intersection. 0 (or any other integer): Always complete walk.
% #4: Path color (intersections always circled in red)
pgfintersectionsortbyfirstpath % If multiple intersections, order according to first path (the random walk)
pgfintersectionofpaths % Record intersections between the following two paths pgfintersectionofpaths{PATH 1}{PATH 2}
{
pgfpathmoveto{pgfpointorigin} % Start path at origin
foreach x in {1,...,#2} % Walk loop
{
pgfgetlastxy{macrox}{macroy} % Get coordinates from last step
pgfmathsetlengthmacro{dist}{veclen(macrox,macroy)} % Calculate distance from origin (pt)
ifnum#3=1relax % Only check if outside disc if #3 has a value of 1
ifdim dist < 50pt % Check whether path has gone outside disc
pgfpathlineto{pgfpointadd{pgfpoint{macrox}{macroy}}{pgfpoint{rand*10}{rand*10}}} % Add random vector onto path
fi
else % Otherwise always continue path
pgfpathlineto{pgfpointadd{pgfpoint{macrox}{macroy}}{pgfpoint{rand*10}{rand*10}}}
fi
}
% Now actually draw the path
color{#4} % Change color temporarily
pgfgetpathtemppath
pgfusepath{stroke}
pgfsetpathtemppath
color{black} % Restore color (for circle)
}
{
% Path for disc
pgfpathcircle{pgfpointorigin}{50pt}
pgfgetpathtemppath
pgfusepath{stroke}
pgfsetpathtemppath
}
% Lengths to store intersections points (origin = centre of disc), in pt.
newdimenxintersect
newdimenyintersect
pgfintersectionsortbyfirstpath % Repeat of earlier command to be sure :)
foreach s in {1,...,pgfintersectionsolutions} % Iterate through intersection object (list of coordinates)
{
pgfpathcircle{pgfpointintersectionsolution{s}}{2pt} % Circle the intersection point
pgfextractx{xintersect}{pgfpointintersectionsolution{s}} % Get x coordinate of current intersection
pgfextractx{yintersect}{pgfpointintersectionsolution{s}} % Get y coordinate of current intersection
% Add a text object to right of disc, using pgfmathparse to change the coordinates in pt to cm (precision 4)
pgftext[at=pgfpointscale{0.5}{% Just some scaling
pgfpointadd{pgfpointadd{pgfpoint{0cm}{6cm}}{pgfpoint{0cm}{-#1 cm}}}{pgfpoint{12cm}{-s cm}}}] % {test}
{small#4: $x=$pgfmathparse{xintersect/28.45274}pgfmathprintnumber[fixed,precision=4]{pgfmathresult} $y=$pgfmathparse{yintersect/28.45274}pgfmathprintnumber[fixed,precision=4]{pgfmathresult}}
}
color{red}
% pgfusepath{fill} % Fill intersection circles (instead of stroke)
pgfusepath{stroke} % Draw intersection paths pgfusepath{fill} could be used here
color{black} % Restore color
}
begin{document}
begin{pgfpicture}
discmotion{1}{250}{1}{black}
discmotion{2}{250}{1}{blue}
discmotion{3}{250}{1}{orange}
end{pgfpicture}
end{document}
Example output with above code:

Note that the step sizes are quite large (rand*10); you may want to reduce this. You may also want to add additional arguments, specifying the radius of the disc, for example (currently fixed at 50pt). Lastly, there is also the option to not stop at the firsrt intersection, but always complete the prescribed number of steps (recording all intersections). Change the first argument from 1 to use this. For example,
begin{pgfpicture}
discmotion{1}{200}{0}{black} % Don't stop until 200!
end{pgfpicture}
just produced

add a comment |
I've put together a command using the basic layer of pgf (the front end tikz didn't provide quite enough flexibility for your problem). When called from a pgfpicture environment, it starts the Brownian motion from the centre of the disc and continues until an intersection occurs. The coordinates of the intersection point are then printed. A number of walks can be run on the same disc (in different colours).
I hadn't done any work with the pgf basic layer before so it is quite likely that improvements can be made to the code (open to suggestions here).
I've tried to comment the code but will admit the pgf layer syntax can appear quite alien if you are only familiar with the front end. Here I will summarise the salient points:
- The tikz
intersectionslibrary is used to calculate the intersection of two paths (the disc and a walk). See p.1058 of the tikz manual (V. 3.1). - The pgf command
pgfgetlastxyprovides access to the last coordinates of a path, and is the key player in theforeachloop used to construct the walk - At each step, the distance of the walk from the origin can be calculated, allowing us to terminate the walk if it has gone outside of the disc.
The code:
documentclass{article}
usepackage{geometry}
usepackage{tikz} % Includes the basic layer (pgf) and mathematical engine
% Library to determine points of intersection of two paths
usetikzlibrary{intersections} % See manual p.1058
% Command to be used inside a pgfpicture. Requires tikz, tikz.intersections
newcommanddiscmotion[4]
{ % #1: Walk number (currently only used to make sure intersection points are printed in different places)
% #2: Number of steps in walk
% #3: If 1, Terminate after first intersection. 0 (or any other integer): Always complete walk.
% #4: Path color (intersections always circled in red)
pgfintersectionsortbyfirstpath % If multiple intersections, order according to first path (the random walk)
pgfintersectionofpaths % Record intersections between the following two paths pgfintersectionofpaths{PATH 1}{PATH 2}
{
pgfpathmoveto{pgfpointorigin} % Start path at origin
foreach x in {1,...,#2} % Walk loop
{
pgfgetlastxy{macrox}{macroy} % Get coordinates from last step
pgfmathsetlengthmacro{dist}{veclen(macrox,macroy)} % Calculate distance from origin (pt)
ifnum#3=1relax % Only check if outside disc if #3 has a value of 1
ifdim dist < 50pt % Check whether path has gone outside disc
pgfpathlineto{pgfpointadd{pgfpoint{macrox}{macroy}}{pgfpoint{rand*10}{rand*10}}} % Add random vector onto path
fi
else % Otherwise always continue path
pgfpathlineto{pgfpointadd{pgfpoint{macrox}{macroy}}{pgfpoint{rand*10}{rand*10}}}
fi
}
% Now actually draw the path
color{#4} % Change color temporarily
pgfgetpathtemppath
pgfusepath{stroke}
pgfsetpathtemppath
color{black} % Restore color (for circle)
}
{
% Path for disc
pgfpathcircle{pgfpointorigin}{50pt}
pgfgetpathtemppath
pgfusepath{stroke}
pgfsetpathtemppath
}
% Lengths to store intersections points (origin = centre of disc), in pt.
newdimenxintersect
newdimenyintersect
pgfintersectionsortbyfirstpath % Repeat of earlier command to be sure :)
foreach s in {1,...,pgfintersectionsolutions} % Iterate through intersection object (list of coordinates)
{
pgfpathcircle{pgfpointintersectionsolution{s}}{2pt} % Circle the intersection point
pgfextractx{xintersect}{pgfpointintersectionsolution{s}} % Get x coordinate of current intersection
pgfextractx{yintersect}{pgfpointintersectionsolution{s}} % Get y coordinate of current intersection
% Add a text object to right of disc, using pgfmathparse to change the coordinates in pt to cm (precision 4)
pgftext[at=pgfpointscale{0.5}{% Just some scaling
pgfpointadd{pgfpointadd{pgfpoint{0cm}{6cm}}{pgfpoint{0cm}{-#1 cm}}}{pgfpoint{12cm}{-s cm}}}] % {test}
{small#4: $x=$pgfmathparse{xintersect/28.45274}pgfmathprintnumber[fixed,precision=4]{pgfmathresult} $y=$pgfmathparse{yintersect/28.45274}pgfmathprintnumber[fixed,precision=4]{pgfmathresult}}
}
color{red}
% pgfusepath{fill} % Fill intersection circles (instead of stroke)
pgfusepath{stroke} % Draw intersection paths pgfusepath{fill} could be used here
color{black} % Restore color
}
begin{document}
begin{pgfpicture}
discmotion{1}{250}{1}{black}
discmotion{2}{250}{1}{blue}
discmotion{3}{250}{1}{orange}
end{pgfpicture}
end{document}
Example output with above code:

Note that the step sizes are quite large (rand*10); you may want to reduce this. You may also want to add additional arguments, specifying the radius of the disc, for example (currently fixed at 50pt). Lastly, there is also the option to not stop at the firsrt intersection, but always complete the prescribed number of steps (recording all intersections). Change the first argument from 1 to use this. For example,
begin{pgfpicture}
discmotion{1}{200}{0}{black} % Don't stop until 200!
end{pgfpicture}
just produced

I've put together a command using the basic layer of pgf (the front end tikz didn't provide quite enough flexibility for your problem). When called from a pgfpicture environment, it starts the Brownian motion from the centre of the disc and continues until an intersection occurs. The coordinates of the intersection point are then printed. A number of walks can be run on the same disc (in different colours).
I hadn't done any work with the pgf basic layer before so it is quite likely that improvements can be made to the code (open to suggestions here).
I've tried to comment the code but will admit the pgf layer syntax can appear quite alien if you are only familiar with the front end. Here I will summarise the salient points:
- The tikz
intersectionslibrary is used to calculate the intersection of two paths (the disc and a walk). See p.1058 of the tikz manual (V. 3.1). - The pgf command
pgfgetlastxyprovides access to the last coordinates of a path, and is the key player in theforeachloop used to construct the walk - At each step, the distance of the walk from the origin can be calculated, allowing us to terminate the walk if it has gone outside of the disc.
The code:
documentclass{article}
usepackage{geometry}
usepackage{tikz} % Includes the basic layer (pgf) and mathematical engine
% Library to determine points of intersection of two paths
usetikzlibrary{intersections} % See manual p.1058
% Command to be used inside a pgfpicture. Requires tikz, tikz.intersections
newcommanddiscmotion[4]
{ % #1: Walk number (currently only used to make sure intersection points are printed in different places)
% #2: Number of steps in walk
% #3: If 1, Terminate after first intersection. 0 (or any other integer): Always complete walk.
% #4: Path color (intersections always circled in red)
pgfintersectionsortbyfirstpath % If multiple intersections, order according to first path (the random walk)
pgfintersectionofpaths % Record intersections between the following two paths pgfintersectionofpaths{PATH 1}{PATH 2}
{
pgfpathmoveto{pgfpointorigin} % Start path at origin
foreach x in {1,...,#2} % Walk loop
{
pgfgetlastxy{macrox}{macroy} % Get coordinates from last step
pgfmathsetlengthmacro{dist}{veclen(macrox,macroy)} % Calculate distance from origin (pt)
ifnum#3=1relax % Only check if outside disc if #3 has a value of 1
ifdim dist < 50pt % Check whether path has gone outside disc
pgfpathlineto{pgfpointadd{pgfpoint{macrox}{macroy}}{pgfpoint{rand*10}{rand*10}}} % Add random vector onto path
fi
else % Otherwise always continue path
pgfpathlineto{pgfpointadd{pgfpoint{macrox}{macroy}}{pgfpoint{rand*10}{rand*10}}}
fi
}
% Now actually draw the path
color{#4} % Change color temporarily
pgfgetpathtemppath
pgfusepath{stroke}
pgfsetpathtemppath
color{black} % Restore color (for circle)
}
{
% Path for disc
pgfpathcircle{pgfpointorigin}{50pt}
pgfgetpathtemppath
pgfusepath{stroke}
pgfsetpathtemppath
}
% Lengths to store intersections points (origin = centre of disc), in pt.
newdimenxintersect
newdimenyintersect
pgfintersectionsortbyfirstpath % Repeat of earlier command to be sure :)
foreach s in {1,...,pgfintersectionsolutions} % Iterate through intersection object (list of coordinates)
{
pgfpathcircle{pgfpointintersectionsolution{s}}{2pt} % Circle the intersection point
pgfextractx{xintersect}{pgfpointintersectionsolution{s}} % Get x coordinate of current intersection
pgfextractx{yintersect}{pgfpointintersectionsolution{s}} % Get y coordinate of current intersection
% Add a text object to right of disc, using pgfmathparse to change the coordinates in pt to cm (precision 4)
pgftext[at=pgfpointscale{0.5}{% Just some scaling
pgfpointadd{pgfpointadd{pgfpoint{0cm}{6cm}}{pgfpoint{0cm}{-#1 cm}}}{pgfpoint{12cm}{-s cm}}}] % {test}
{small#4: $x=$pgfmathparse{xintersect/28.45274}pgfmathprintnumber[fixed,precision=4]{pgfmathresult} $y=$pgfmathparse{yintersect/28.45274}pgfmathprintnumber[fixed,precision=4]{pgfmathresult}}
}
color{red}
% pgfusepath{fill} % Fill intersection circles (instead of stroke)
pgfusepath{stroke} % Draw intersection paths pgfusepath{fill} could be used here
color{black} % Restore color
}
begin{document}
begin{pgfpicture}
discmotion{1}{250}{1}{black}
discmotion{2}{250}{1}{blue}
discmotion{3}{250}{1}{orange}
end{pgfpicture}
end{document}
Example output with above code:

Note that the step sizes are quite large (rand*10); you may want to reduce this. You may also want to add additional arguments, specifying the radius of the disc, for example (currently fixed at 50pt). Lastly, there is also the option to not stop at the firsrt intersection, but always complete the prescribed number of steps (recording all intersections). Change the first argument from 1 to use this. For example,
begin{pgfpicture}
discmotion{1}{200}{0}{black} % Don't stop until 200!
end{pgfpicture}
just produced

answered Feb 17 at 13:18
Pippip19Pippip19
1,3288
1,3288
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f475202%2fhow-to-draw-a-2-dim-brownian-motion-into-a-disk%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Welcome to TeX.SX! Please help us help you by providing a minimal compilable code example of what you've tried so far (MWE).
– TeXnician
Feb 16 at 15:42
2
... and a sketch to show what you want clearer.
– JouleV
Feb 16 at 15:45
I wrote a paper in .tex ( on overleaf) and i should draw a 2-dim Brownian motion into it, or maybe using some kind of program to make this image (i am a newbie of latex, i'm sorry ):
– Claudio Delfino
Feb 16 at 15:48
I don't want a grafic of a function but a draw of a possible 2-dim Brownian motion, i.e., a grafic in the plane of (B_1(t),B_2(t)) where B_1(t),B_2(t) are two Brownian motion starting at a point |z|<1, until the time that B_1(t)^2 + B_2(t)^2=1, i don't know if it is possible directly on latex
– Claudio Delfino
Feb 16 at 15:54
@ClaudioDelfino Just to note that if you want to modify people, use @ and their username, as I use here.
– JouleV
Feb 16 at 16:17