« first day (1971 days earlier)      last day (2503 days later) » 

12:37 AM
Consider this equation system:
trajectories[{pt1_, pt2_, pt3_}] := NDSolveValue[{
   {x1'[t], y1'[t]} == -Normalize[{x2[t], y2[t]} - {x1[t], y1[t]}],
   {x2'[t], y2'[t]} == -Normalize[{x3[t], y3[t]} - {x2[t], y2[t]}],
   {x3'[t], y3'[t]} == -Normalize[{x1[t], y1[t]} - {x3[t], y3[t]}],
   {x1[0], y1[0]} == pt1,
   {x2[0], y2[0]} == pt2,
   {x3[0], y3[0]} == pt3
   }, {x1, y1, x2, y2, x3, y3}, {t, 0, 1}]

pos = Partition[
   Through[trajectories[{{0.2916, 0.2916}, {0.7083, 0.2916}, {0.5,
        0.5}}][t]], 2];

Graphics[{
  Red, Line@Transpose[Table[pos, {t, 0, 1, 0.05}]],
As the image shows, point 2 moves away from point 1, point 3 moves away from point 2, and point 1 moves away from point 3. But I want point 2 to moves towards point 1, point 3 to move towards point 2, and point 1 to move towards point 3.
Changing -Normalize[{x2[t], y2[t]} - {x1[t], y1[t]}] to Normalize[{x2[t], y2[t]} - {x1[t], y1[t]}], and so on, i.e. removing the minus signs, makes NDSolve throw error messages and it doesn't work.
So how can I do it?
 
12:52 AM
I guess I need to decrease the size of the derivative, e.g. 0.1 Normalize[{x2[t], y2[t]} - {x1[t], y1[t]}]
But it doesn't seem to work well. The trajectories don't converge to a point in the middle. I get an error message saying that the maximum number of steps have been reached..
 
1:21 AM
@C.E. The problem is the normalization when points get closer.
 
@halirutan yeah, that's it. I put it in because I want the points to move a uniform rate, do you know if this can be done?
 
@C.E. I'm not sure this makes sense. Assume the following:
You cannot keep the speed at a uniform rate. If you do this, the solver needs to make smaller and smaller steps as he reaches the center. Otherwise the solution would "overshoot" and it tries to cope with that.
When I see this right then at the very center, the time will increase at a uniform rate, but there is absolutely not way that the points move at a uniform speed.
As t->infinity the solution converges to the center. What you ask for is IMO not possible.
I guess what you want is t=0 points are at the triangle vertices, t=1 points meet in the center, right?
 
@halirutan Thank you. You have convinced me. Yes, that is what I want. It does not necessarily have to reach the center before t = 1, that endpoint is arbitrary. For some context I was looking at the mice problem.
 
@C.E. There must be a solution to this that contains the arclength... hmm.
I think I know the solution. Let me see..
 
1:39 AM
@halirutan Actually, I am realizing now that I might just as well remove Normalize. I had it in there because I didn't know it would be a problem. I thought it had some advantages, turns out it's just a problem.
 
@C.E. Yes, that is how I obtained the gif.
 
yeah, thank you. I feel confident that I can solve the problem I was working on now :)
 
2:18 AM
@C.E. In case you are still interested in an answer.
It works like I said. Calculate your solutions pos that run from say t=0..10. Then you calculate integrand of the arclength say from the first curve with something along (forgive my wrong naming)
arcLengh = With[{dx = D[pos[[1]], t]},
  Sqrt[dx.dx]
  ]
The overall length of the curve can be calculated by
NIntegrate[arcLengh, {t, 0, 10}]
Now, you create a "reverse lookup" for your time values
ip = Interpolation@
  Table[{NIntegrate[arcLengh, {t, 0, tend}]/0.2474225222626625`,
    tend}, {tend, 0.0, 10, .2}]
The function ip takes values from 0..1 and gives you the correct times 0...10 that you need to use inside your curve function. So if you move the slider for ip[t] with constant speed, your curve will increase its length with constantly.
@C.E. A good feeling that I can pay back some of my "let me ask a stupid web-dev question" debts.
@C.E. Finally, since we now know how we want to scale our velocity:
trajectories[{pt1_, pt2_, pt3_}] := NDSolveValue[{
   {x1'[t], y1'[t]}*
     Sqrt[Derivative[1][x1][t]^2 + Derivative[1][y1][t]^2] == ({x2[t],
        y2[t]} - {x1[t], y1[t]}), {x2'[t], y2'[t]}*
     Sqrt[Derivative[1][x2][t]^2 + Derivative[1][y2][t]^2] == ({x3[t],
        y3[t]} - {x2[t], y2[t]}), {x3'[t], y3'[t]}*
     Sqrt[Derivative[1][x3][t]^2 + Derivative[1][y3][t]^2] == ({x1[t],
        y1[t]} - {x3[t], y3[t]}),
   {x1[0], y1[0]} == pt1,
   {x2[0], y2[0]} == pt2,
   {x3[0], y3[0]} == pt3},
The speed is not exactly linear and in the center there seem to be numerical instabilities, but it's almost linear outside the very center.
 
2:51 AM
@halirutan thank you!
 
@C.E. np
 
3:11 AM
@C.E. Here's my take:
trajectories[{pt1_, pt2_, pt3_}] := NDSolveValue[{
   {x1'[t], y1'[t]} == Normalize[{x2[t], y2[t]} - {x1[t], y1[t]}],
   {x2'[t], y2'[t]} == Normalize[{x3[t], y3[t]} - {x2[t], y2[t]}],
   {x3'[t], y3'[t]} == Normalize[{x1[t], y1[t]} - {x3[t], y3[t]}],
   {x1[1], y1[1]} == pt1, {x2[1], y2[1]} == pt2, {x3[1], y3[1]} == pt3,
   WhenEvent[Norm[{x2[t], y2[t]} - {x1[t], y1[t]}] < 1*^-8,
    "StopIntegration"]},
  {x1, y1, x2, y2, x3, y3}, {t, 1, 10}]

pos = Partition[
   Through[trajectories[{{0.2916, 0.2916}, {0.7083, 0.2916}, {0.5,
The WhenEvent[] stops the trouble just before the mice collide.
 
3:27 AM
@MichaelE2 Nice. That's the visualization I was going for as well. Posted a version without normalization here:
0
A: Filling Space with Pursuit Polygons

C. E.The reason that these are called "pursuit polygons" is because they are formed from a dynamical system in which different agents pursue each other. Example: In this image, one agent starts in each corner of the triangle. The agent starting in the lower right corner pursues the agent starting i...

Don't know if I will add something about normalization, but in any case I learned things about NDSolve and about Normalization in differential equations. Much appreciated.
 
4:16 AM
@C.E. I did it with and without Normalize...which...long story...is why I started it at t == 1. Just realized I forgot to change it back. -- Note that without Normalize the speed decreases exponentially and the trajectories meet at the centroid.
 
 
11 hours later…
2:50 PM
@C.E. Now I finally looked at the answer you were writing. Very nice indeed and I just noticed that I have exactly one blogpost on my webpage
 
 
7 hours later…
9:58 PM
@halirutan Nice blog post.
@MichaelE2 @halirutan Considering the qualitative difference in that the agents do not meet at the centroid when they move at unit speed, I now also include that in my answer.
 
@C.E. If you "post-process" your solution like I did in my first approach, they still meet at the center.
But as Michael showed, when you force them to run at constant speed, the solution is different.
 
@halirutan Yeah, that's the case that I added. Where they always move at unit speed.
 
Btw, I consider (when you make the plot with all the lines) it more beautiful when the lines get denser in the center.
 
@halirutan I don't dispute that, I was a little bit lazy and did not play much with how many/which lines to draw.
 
@C.E. Btw 2, when I see this right, then what I describe in the blog-post seems to be a solution for the differential equation with an explicit very crude method that processes all "mice" sequenctially one after another.
Although I never looked at it that way and just understood it after you showed your example.
 
10:15 PM
@halirutan Yes, I agree. You may not have thought about it as agents chasing one another, but it is essentially Euler integration of that system except that, as you say, the agents are updated sequentially.
 

« first day (1971 days earlier)      last day (2503 days later) »