{"id":3090,"date":"2019-02-14T11:49:13","date_gmt":"2019-02-14T16:49:13","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/?p=3090"},"modified":"2019-11-01T22:33:40","modified_gmt":"2019-11-02T02:33:40","slug":"pursuit-curves","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2019\/02\/14\/pursuit-curves\/","title":{"rendered":"Pursuit Curves"},"content":{"rendered":"<div class=\"content\"><p>Here's an interesting snippet I learned while working on today's blog post: Mathematician Jacob Bernoulli asked for a <i>logarithmic spiral<\/i> to be engraved on his tombstone. Here's an example of a such a spiral.<\/p><pre class=\"codeinput\">theta = -6*pi:0.01:6*pi;\r\nrho = 1.1.^theta;\r\npolarplot(theta,rho)\r\nrlim([0 max(rho)])\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/pursuit_curves_01.png\" alt=\"\"> <p>Sadly, the engravers of his tombstone apparently did not fully understand his request. They engraved a spiral, but it was not logarithmic.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/Basel_-_Grabstein_Bernoulli.jpg\" alt=\"\"> <\/p><p><i>[ <a href=\"https:\/\/commons.wikimedia.org\/wiki\/User:Taxiarchos228\">author<\/a>, <a href=\"https:\/\/commons.wikimedia.org\/wiki\/File:Basel_-_Grabstein_Bernoulli.jpg\">source<\/a>, <a href=\"http:\/\/artlibre.org\/licence\/lal\/en\/\">license<\/a> ]<\/i><\/p><p>I came across the concept of logarithmic spirals while looking into something called <i>pursuit curves<\/i>. Here's an example, in the form of what is sometimes called the <i>mice problem<\/i>. Start by constructing <tt>P<\/tt>, a vector of four complex-valued points, so that they form the corners of a square in the complex plane.<\/p><pre class=\"codeinput\">P = [0 1 1+1i 1i];\r\nplot(real(P),imag(P),<span class=\"string\">'*'<\/span>)\r\naxis <span class=\"string\">equal<\/span>\r\naxis([-.5 1.5 -.5 1.5])\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/pursuit_curves_02.png\" alt=\"\"> <p>Now imagine that each of these \"mice\" is chasing the next one, always running directly toward it as is moves. To illustrate the basic idea, let's have the mice take a few fixed-length steps toward their targets.<\/p><pre class=\"codeinput\">P = [0 1 1+1i 1i];\r\nstep_size = 0.1;\r\nPt = P([2 3 4 1]);\r\nV = Pt - P;\r\nP = [P ; P + step_size*V];\r\n\r\n<span class=\"comment\">% Second step<\/span>\r\nPn = P(end,:);\r\nPt = Pn(end,[2 3 4 1]);\r\nV = Pt - Pn;\r\nP = [P ; Pn + step_size*V];\r\n\r\n<span class=\"comment\">% Third step.<\/span>\r\nPn = P(end,:);\r\nPt = Pn(end,[2 3 4 1]);\r\nV = Pt - Pn;\r\nP = [P ; Pn + step_size*V];\r\n\r\n<span class=\"comment\">% Fourth step.<\/span>\r\nPn = P(end,:);\r\nPt = Pn(end,[2 3 4 1]);\r\nV = Pt - Pn;\r\nP = [P ; Pn + step_size*V];\r\n<\/pre><p>Now plot the original positions and steps taken by each mouse.<\/p><pre class=\"codeinput\">hold <span class=\"string\">on<\/span>\r\n<span class=\"keyword\">for<\/span> k = 1:4\r\n    plot(real(P(:,k)),imag(P(:,k)))\r\n<span class=\"keyword\">end<\/span>\r\nhold <span class=\"string\">off<\/span>\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/pursuit_curves_03.png\" alt=\"\"> <p>You get the idea, and you can see four spirals start to take shape.<\/p><p>I've written a function, shown at the bottom of this post, that simulates and plots pursuit curves for any collection of starting points (mice). I chose to plot 1000 steps, with each step covering 1\/100 of the remaining distance, so that the mice never quite catch their targets. The plotting function also plots the tangent lines every 10 steps. Here's the result for the four-mice-on-a-square starting configuration.<\/p><pre class=\"codeinput\">P = [0 1 1+1i 1i];\r\nclf\r\nplotPursuitCurves(P)\r\naxis([-0.1 1.1 -0.1 1.1])\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/pursuit_curves_04.png\" alt=\"\"> <p>Logarithmic spiral curves have the interesting property that, when you scale them up by a constant factor, the curve remains the same, but rotated. We can get a sense of this property by zooming in on the plot. Let's zoom in by a factor of 100.<\/p><pre class=\"codeinput\">axis([0.495 0.505 0.495 0.505])\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/pursuit_curves_05.png\" alt=\"\"> <p>You can see that the curve's overall shape has not changed. It's just been rotated.<\/p><p>The function <tt>plotPursuitCurves<\/tt> lets us explore other starting configurations, such as a triangle.<\/p><pre class=\"codeinput\">clf\r\nP1 = 0;\r\nP2 = 1;\r\nP3 = exp(1j*pi\/3);\r\nplotPursuitCurves([P1 P2 P3])\r\naxis([-0.1 1.1 -0.1 1.0])\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/pursuit_curves_06.png\" alt=\"\"> <p>Or a hexagon.<\/p><pre class=\"codeinput\">clf\r\ntheta = 0:60:330;\r\nP = cosd(theta) + 1i*sind(theta);\r\nplotPursuitCurves(P)\r\naxis([-1.1 1.1 -1.1 1.1])\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/pursuit_curves_07.png\" alt=\"\"> <p>We can even tinker with the select of targets. In this next example, the mice start at the vertices of a hexagon, but instead of chasing the next mouse over, they start out chasing <b>other<\/b> mice. We do this by reordering the vertices.<\/p><pre class=\"codeinput\">P2 = P([1 3 5 2 4 6]);\r\nclf\r\nplotPursuitCurves(P2)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/pursuit_curves_08.png\" alt=\"\"> <p>Those are some odd-looking curves. If we zoom in we can see why the curves evolve the way they do by examining the tangent lines. We can also see that the curves do appear to settle into a set of regular spirals, although I do not know whether this is a general property of such pursuit curves.<\/p><pre class=\"codeinput\">xlim([-0.147 0.103])\r\nylim([-0.129 0.069])\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/pursuit_curves_09.png\" alt=\"\"> <p>Do you like to explore mathematical visualizations like this? If you have a favorite, let us know in the comments.<\/p><pre class=\"codeinput\"><span class=\"keyword\">function<\/span> plotPursuitCurves(P)\r\nP = reshape(P,1,[]);\r\nN = length(P);\r\nd = 0.01;\r\n<span class=\"keyword\">for<\/span> k = 1:1000\r\n    V = P(end,[(2:N) 1]) - P(end,:);\r\n    P(end+1,:) = P(end,:) + d*V;\r\n<span class=\"keyword\">end<\/span>\r\n\r\nhold <span class=\"string\">on<\/span>\r\nQ = P(:,[(2:N) 1]);\r\n<span class=\"keyword\">for<\/span> k = 1:10:size(P,1)\r\n    <span class=\"keyword\">for<\/span> m = 1:N\r\n        T = [P(k,m) Q(k,m)];\r\n        plot(real(T),imag(T),<span class=\"string\">'LineWidth'<\/span>,0.5,<span class=\"string\">'Color'<\/span>,[.8 .8 .8])\r\n    <span class=\"keyword\">end<\/span>\r\n<span class=\"keyword\">end<\/span>\r\n\r\n<span class=\"keyword\">for<\/span> k = 1:N\r\n    plot(real(P(:,k)),imag(P(:,k)))\r\n<span class=\"keyword\">end<\/span>\r\nhold <span class=\"string\">off<\/span>\r\naxis <span class=\"string\">equal<\/span>\r\n<span class=\"keyword\">end<\/span>\r\n<\/pre><script language=\"JavaScript\"> <!-- \r\n    function grabCode_f725ccdd5c2b4741b373973e01d55d45() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='f725ccdd5c2b4741b373973e01d55d45 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' f725ccdd5c2b4741b373973e01d55d45';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2019 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_f725ccdd5c2b4741b373973e01d55d45()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2018b<br><\/p><\/div><!--\r\nf725ccdd5c2b4741b373973e01d55d45 ##### SOURCE BEGIN #####\r\n%%\r\n% Here's an interesting snippet I learned while working on today's blog\r\n% post: Mathematician Jacob Bernoulli asked for a _logarithmic spiral_ to\r\n% be engraved on his tombstone. Here's an example of a such a spiral.\r\n\r\ntheta = -6*pi:0.01:6*pi;\r\nrho = 1.1.^theta;\r\npolarplot(theta,rho)\r\nrlim([0 max(rho)])\r\n\r\n%%\r\n% Sadly, the engravers of his tombstone apparently did not fully understand\r\n% his request. They engraved a spiral, but it was not logarithmic.\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/steve\/files\/Basel_-_Grabstein_Bernoulli.jpg>>\r\n%\r\n% _[ <https:\/\/commons.wikimedia.org\/wiki\/User:Taxiarchos228 author>, \r\n% <https:\/\/commons.wikimedia.org\/wiki\/File:Basel_-_Grabstein_Bernoulli.jpg \r\n% source>, <http:\/\/artlibre.org\/licence\/lal\/en\/ license> ]_\r\n%\r\n% I came across the concept of logarithmic spirals while looking into\r\n% something called _pursuit curves_. Here's an example, in the form of what\r\n% is sometimes called the _mice problem_. Start by constructing |P|, a\r\n% vector of four complex-values points, so that they form the corners of a\r\n% square in the complex plane.\r\n\r\nP = [0 1 1+1i 1i];\r\nplot(real(P),imag(P),'*')\r\naxis equal\r\naxis([-.5 1.5 -.5 1.5])\r\n\r\n%%\r\n% Now imagine that each of these \"mice\" is chasing the next one, always\r\n% running directly toward it as is moves. To illustrate the basic idea,\r\n% let's have the mice take a few fixed-length steps toward their\r\n% targets.\r\n\r\nP = [0 1 1+1i 1i];\r\nstep_size = 0.1;\r\nPt = P([2 3 4 1]);\r\nV = Pt - P;\r\nP = [P ; P + step_size*V];\r\n\r\n% Second step\r\nPn = P(end,:);\r\nPt = Pn(end,[2 3 4 1]);\r\nV = Pt - Pn;\r\nP = [P ; Pn + step_size*V];\r\n\r\n% Third step.\r\nPn = P(end,:);\r\nPt = Pn(end,[2 3 4 1]);\r\nV = Pt - Pn;\r\nP = [P ; Pn + step_size*V];\r\n\r\n% Fourth step.\r\nPn = P(end,:);\r\nPt = Pn(end,[2 3 4 1]);\r\nV = Pt - Pn;\r\nP = [P ; Pn + step_size*V];\r\n\r\n%%\r\n% Now plot the original positions and steps taken by each mouse.\r\nhold on\r\nfor k = 1:4\r\n    plot(real(P(:,k)),imag(P(:,k)))\r\nend\r\nhold off\r\n\r\n%%\r\n% You get the idea, and you can see four spirals start to take shape.\r\n%\r\n% I've written a function, shown at the bottom of this post, that simulates\r\n% and plots pursuit curves for any collection of starting points (mice). I\r\n% chose to plot 1000 steps, with each step covering 1\/100 of the remaining\r\n% distance, so that the mice never quite catch their targets. The plotting\r\n% function also plots the tangent lines every 10 steps. Here's the result\r\n% for the four-mice-on-a-square starting configuration.\r\n\r\nP = [0 1 1+1i 1i];\r\nclf\r\nplotPursuitCurves(P)\r\naxis([-0.1 1.1 -0.1 1.1])\r\n\r\n%%\r\n% Logarithmic spiral curves have the interesting property that, when you\r\n% scale them up by a constant factor, the curve remains the same, but\r\n% rotated. We can get a sense of this property by zooming in on the plot.\r\n% Let's zoom in by a factor of 100.\r\n\r\naxis([0.495 0.505 0.495 0.505])\r\n\r\n%%\r\n% You can see that the curve's overall shape has not changed. It's just\r\n% been rotated.\r\n%\r\n% The function |plotPursuitCurves| lets us explore other starting\r\n% configurations, such as a triangle.\r\n\r\nclf\r\nP1 = 0;\r\nP2 = 1;\r\nP3 = exp(1j*pi\/3);\r\nplotPursuitCurves([P1 P2 P3])\r\naxis([-0.1 1.1 -0.1 1.0])\r\n\r\n%%\r\n% Or a hexagon.\r\n\r\nclf\r\ntheta = 0:60:330;\r\nP = cosd(theta) + 1i*sind(theta);\r\nplotPursuitCurves(P)\r\naxis([-1.1 1.1 -1.1 1.1])\r\n\r\n%%\r\n% We can even tinker with the select of targets. In this next example, the\r\n% mice start at the vertices of a hexagon, but instead of chasing the next\r\n% mouse over, they start out chasing the mouse that is **two** vertices\r\n% away.\r\n\r\nP2 = P([1 3 5 2 4 6]);\r\nclf\r\nplotPursuitCurves(P2)\r\n\r\n%%\r\n% Those are some odd-looking curves. If we zoom in we can see why the\r\n% curves evolve the way they do by examining the tangent lines. We can also\r\n% see that the curves do appear to settle into a set of regular spirals,\r\n% although I do not know whether this is a general property of such pursuit\r\n% curves.\r\n\r\nxlim([-0.147 0.103])\r\nylim([-0.129 0.069])\r\n\r\n%%\r\n% Do you like to explore mathematical visualizations like this? If you have\r\n% a favorite, let us know in the comments.\r\n\r\n%%\r\nfunction plotPursuitCurves(P)\r\nP = reshape(P,1,[]);\r\nN = length(P);\r\nd = 0.01;\r\nfor k = 1:1000\r\n    V = P(end,[(2:N) 1]) - P(end,:);\r\n    P(end+1,:) = P(end,:) + d*V;\r\nend\r\n\r\nhold on\r\nQ = P(:,[(2:N) 1]);\r\nfor k = 1:10:size(P,1)\r\n    for m = 1:N\r\n        T = [P(k,m) Q(k,m)];\r\n        plot(real(T),imag(T),'LineWidth',0.5,'Color',[.8 .8 .8])\r\n    end\r\nend\r\n\r\nfor k = 1:N\r\n    plot(real(P(:,k)),imag(P(:,k)))\r\nend\r\nhold off\r\naxis equal\r\nend\r\n##### SOURCE END ##### f725ccdd5c2b4741b373973e01d55d45\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/steve\/files\/pursuit_curves_07.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>Here's an interesting snippet I learned while working on today's blog post: Mathematician Jacob Bernoulli asked for a logarithmic spiral to be engraved on his tombstone. Here's an example of a such a... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2019\/02\/14\/pursuit-curves\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":3104,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[50,178,1207,508,90,202,705,122,532,68,1223,200,170,1225,1211,360,298],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/3090"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/comments?post=3090"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/3090\/revisions"}],"predecessor-version":[{"id":3116,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/3090\/revisions\/3116"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media\/3104"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=3090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=3090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=3090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}