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$
2
  • 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$ Commented Feb 25, 2016 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 help center! 3) When you see good questions and answers, vote them up by clicking the vote 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$ Commented Feb 25, 2016 at 18:55

1 Answer 1

40
$\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$
5
  • 3
    $\begingroup$ Wow, what an amazing answer! $\endgroup$ Commented Feb 25, 2016 at 18:38
  • 2
    $\begingroup$ @C.Woods Thank you! $\endgroup$ Commented Feb 25, 2016 at 18:47
  • $\begingroup$ Wow. Amazing, much more than I expected. Thank you very much! $\endgroup$ Commented Feb 26, 2016 at 0:02
  • $\begingroup$ @DCB I'm very glad I could help $\endgroup$ Commented Feb 26, 2016 at 4:46
  • 2
    $\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$ Commented Feb 26, 2016 at 15:31

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.