APSF //- Find the closest approach of two objects (obviously at least one of them must be a solar system object). //- After the script ends, the plan will have the date/time fixed to that of the closest approach, within //- the time precision specified. //- The plan must have at least two objects in it. Certain assumptions are made: //- 1. If there is more than one close approach during the specified period, any one of those close //- approaches will be found. //- 2. If no close approach is found during the period, the closest approach will be reported, which //- will be at one of the period end points. //- 3. No check is made to see that at least one of the objects is a solar-system object. //- //- Inspired by the article on Page 72 of the March 2008 issue of Sky & Telescope. //- //- Paul Rodman, Feb 2008 //- //- Version 1.0 24 Feb 2008 //- Initial release //------------------------------------------------------------------------ function DistanceOn(d as double, first as integer, second as integer) as double PlanLocalDateTime=d return AngleBetween(obj(first),obj(second)) end function //------------------------------------------------------------------------ function FindMinimum(startDate as double, endDate as double, periods as integer, byref iprogress as integer, _ first as integer, second as integer) as double dim d,dist,mindist,mind as double, i as integer for i=0 to periods if UpdateProgress(iprogress) then return -1.0 iprogress=iprogress+1 d=startDate+i*(endDate-startDate)/periods dist=DistanceOn(d,first,second) if i=0 or dist"" then s=s+" ("+Obj(i).Name+")" ids.Append s next startDate = currentDate endDate = startDate+31.0*3600.0*24.0 SetCheckListParameter("Select two objects",osel,ids,true,10) SetDateParameter("Period start",startDate) SetDateParameter("Period end",endDate) SetChoiceParameter("Precision",precision,"1 day","1 hour","1 minute","1 second") if not EditParameters("Closest Approach") then return osel=GetCheckListParameter("Select two objects") first=-1 second=-1 for i=0 to ubound(osel) if osel(i)=1 then if first<0 then first=i+1 elseif second<0 then second=i+1 else print "Only select two objects!" return end if end if next if first<0 or second<0 then print "Choose two objects!" return end if startDate=GetDateParameter("Period start") endDate=GetDateParameter("Period end") precision=GetChoiceParameter("Precision") midDate = (startDate+endDate)*0.5 period = abs(startDate-endDate)*0.1 select case precision case 0 delta=3600.0*24.0 case 1 delta=3600.0 case 2 delta=60.0 case 3 delta=1.0 end select n=0 while true n=n+11 if period=0 then print "Close Approach at "+DoubleToDate(midDate)+" "+DoubleToTime(midDate)+" Distance = "+format(dist,"0.0000")+DegreeSymbol+" ("+format(dist*3600.0,"0.000")+""")" end if if isel>0 then obj(isel).Selected=true