10
$\begingroup$

I am trying to find the minimal and maximum distance between two moving points with Mathematica in an interval.

For example,

p1 = (Sin(t), Cos(t))
p2 = (Cos(3t), Sin(2t))

Interval is $0≤t≤2\pi$.

Can I use the command EuclideanDistance or should I use FindMinimum, FindMaximum, NMinimize, Maximize; and how do I use these commands in an interval?

$\endgroup$
  • 1
    $\begingroup$ Please, consider updating your question to include what you have tried and where you are getting stuck. That way, people on this site will know exactly what help you need. $\endgroup$ – user9660 Feb 25 '16 at 18:55
  • 1
    $\begingroup$ Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – user9660 Feb 25 '16 at 18:55
39
$\begingroup$
p1 = {Sin[t], Cos[t]}; p2 = {Cos[3 t], Sin[2 t]};

tAtMin = ArgMax[{EuclideanDistance[p1, p2]^2, 0 <= t <= 2 Pi}, t]
tAtMax = ArgMin[{EuclideanDistance[p1, p2]^2, 0 <= t <= 2 Pi}, t]

ParametricPlot[{p1, p2}, {t, 0, 2 Pi},
 Epilog -> {PointSize[0.02],
   Red, Thick, Dashed, Through[{Point, Line}[{p1, p2} /. t -> tAtMax]],
   Darker@Green, Thick, Dashed, Through[{Point, Line}[{p1, p2} /. t -> tAtMin]]
  }
]

Mathematica graphics


Here's a way to visualize the evolution of the distance as $t$ varies:

Animate[
 Show[{
   ParametricPlot[{p1, p2}, {t, 0, 2 Pi},
    Epilog -> {PointSize[0.02],
      Red, Thick, Dashed, 
      Through[{Point, Line}[{p1, p2} /. t -> tAtMax]],
      Darker@Green, Thick, Dashed, Through[{Point, Line}[{p1, p2} /. t -> tAtMin]]
      }
    ],
   Graphics[{
     Thick, Gray, Dashed, PointSize[0.02],
     Through[{Point, Line}[{{Sin[x], Cos[x]}, {Cos[3 x], Sin[2 x]}}]]
     }]
   }],
 {x, 0, 2 Pi},
 AnimationRate -> .05
]

enter image description here

$\endgroup$
  • 3
    $\begingroup$ Wow, what an amazing answer! $\endgroup$ – C. Woods Feb 25 '16 at 18:38
  • 2
    $\begingroup$ @C.Woods Thank you! $\endgroup$ – MarcoB Feb 25 '16 at 18:47
  • $\begingroup$ Wow. Amazing, much more than I expected. Thank you very much! $\endgroup$ – DCB Feb 26 '16 at 0:02
  • $\begingroup$ @DCB I'm very glad I could help $\endgroup$ – MarcoB Feb 26 '16 at 4:46
  • 1
    $\begingroup$ The use of Through[{Point, Line}[{p1, p2} /. t -> tAtMax]] to create simultaneously the two points and the line joining them is particularly clever (sneaky?). A tip (trick?) well worth remembering! $\endgroup$ – murray Feb 26 '16 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.