Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
1  
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. – Louis Feb 25 at 18:55
1  
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! – Louis Feb 25 at 18:55
up vote 35 down vote accepted
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

share|improve this answer
3  
Wow, what an amazing answer! – C. Woods Feb 25 at 18:38
2  
@C.Woods Thank you! – MarcoB Feb 25 at 18:47
    
Wow. Amazing, much more than I expected. Thank you very much! – DCB Feb 26 at 0:02
    
@DCB I'm very glad I could help – MarcoB Feb 26 at 4:46
1  
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! – murray Feb 26 at 15:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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