# File generated by Wizard 2.9.0 on Dec 22, 2024.
processor randomCirclePoint WSF_SCRIPT_PROCESSOR 

   script_variables
      string centerPoint = "";
      double Radius = 50000;
      bool isOver = false;
   end_script_variables
   
   script Array<WsfGeoPoint> generateCirclePoints(string Center , double radius)
      WsfGeoPoint center= WsfGeoPoint.Construct(Center);
      Array<WsfGeoPoint>circlePoints={};
      double earthRadius =6371000.0;
      double angularDistance =radius /earthRadius;
      Array<double>angles ={0.0,120,240};
      foreach(double angle in angles)
      {
         double latCenter=center.Latitude()* MATH.PI()/ 180.0;
         double loncenter= center.Longitude()* MATH.PI()/ 180.0;
         double lat= MATH.ASin(MATH.Sin(latCenter)
                              * MATH.Cos(angularDistance)
                              + MATH.Cos(latCenter)
                              * MATH.Sin(angularDistance)
                              * MATH.Cos(angle));
         
         double lon = loncenter +MATH.ATan2(MATH.Sin(angle)
                                          * MATH.Sin(angularDistance)
                                          * MATH.Cos(latCenter)
                                          , MATH.Cos(angularDistance)
                                          - MATH.Sin(latCenter)
                                          * MATH.Sin(lat));
         circlePoints.PushBack(WsfGeoPoint.Construct(lat*180.0/MATH.PI() , lon *180.0 / MATH.PI(),5000));
      }
      return circlePoints;
   end_script

   script void executecircularPatrol()
      Array<WsfGeoPoint> circlePoints = generateCirclePoints(centerPoint,Radius);
      WsfRoute route;
      WsfRoute r1= route.Create("lx");
      foreach(WsfGeoPoint vertex in circlePoints)
      {
         vertex.SetAltitudeHAE(10000);
         r1.Append(vertex,1500);
      }
      
      r1.Waypoint(0).SetLabel("start");
      r1 .Waypoint(r1.Size()-1).SetGoToLabel("start");
      PLATFORM.FollowRoute(r1);
   #   r1.Print();
      isOver =true;
   end_script
   
   
   update_interval 1 sec 
   on_update
      if(isOver != true)
      {
         executecircularPatrol();
      }
   end_on_update
end_processor