Author 
Comment/Response 
Bill Simpson

10/02/12 9:08pm
Please check this carefully to make certain that I have not introduced any scrapenpaste errors in the process of doing this.
In[1]:= r[t_] := Piecewise[{{{1000, 1000, 1000}, t<0},
{{5*t, 0, 3*(1 + Cos[t])}, 0 <= t <= Pi},
{{5*Pi  5*Sin[t], 5 + 5*Cos[t], 0}, Pi<t<=2*Pi},
{{5*Pi  3*Sin[t], 7 + 3*Cos[t], (2*Pi + t)^2/(2*Pi)}, 2*Pi<t<=4*Pi},
{{3*((17*Pi)/3 + t), 10, 22*Pi + 10*t  t^2/Pi}, 4*Pi<t<= 5*Pi},
{{17*Pi  3*t, 10, 972*Pi + 540*t  (99*t^2)/Pi + (6*t^3)/Pi^2}, 5*Pi<t<=6*Pi},
{{Pi  3*Sin[t], (9*((20 + 18*Pi)/3  t)^2)/40, 3 + 3*Cos[t]}, 6*Pi<t<= 8*Pi},
{{25*Pi + 25*t  (19*t^2)/(4*Pi) + t^3/(4*Pi^2), (25*(140  132*Pi + 27*Pi^2))/2 + (15*(80  74*Pi + 15*Pi^2)*t)/(2*Pi)  (3*(180  164*Pi + 33*Pi^2)*t^2)/(8*Pi^2) 
((50 + 45*Pi  9*Pi^2)*t^3)/(20*Pi^3), 1056  (360*t)/Pi + (81*t^2)/(2*Pi^2)  (3*t^3)/(2*Pi^3)}, 8*Pi<t<=10*Pi},
{{1000, 1000, 1000}, 10*Pi<t}}, 0]
In[2]:= w[s_]:=Which[s<0,{1000,1000,1000},
0<=s<=10Pi,{3+s,5+2 s,0},
10Pi<s,{1000,1000,1000}];
In[3]:= NMinimize[{Norm[r[t]w[s]],0≤t,t≤10Pi,0≤s,s≤10Pi},{t,s}]
Out[3]= {1.16773,{s>2.31536,t>18.2768}}
Just because we place constraints on the variables in NMinimize does not seem to ensure that the variables will always satisfy those constraints. That can mean that one or both your functions can be undefined, and thus NMinimize fails, or that a minimum outside your conditions might confuse the process. So I augment your two functions to make certain they are defined for all possible values and that they return very large results that will never be a minimum when outside your original ranges. It might be nicer if these large results got linearly worse as we get farther outside the boundaries, but sometimes just large constants are enough.
URL: , 
