Page 1 of 1

[lua] drawing circles script

Posted: Fri Sep 30, 2016 1:18 pm
by Michal Pielaszkiewicz
Hi,
Recently I was frustrated witch placing SAM's and assigning for it areas, trying to make it circle...
I've found code on Baloogan forum (unfortunately now I can not enter his forum?) that creates "circles" from RP's, unfortunately that script works only on equator and with increasing deviation shape of circles is getting werid, so I've modified original code to include nav. deviation - now circles are nice at any latitude, I've also changed inputs, so now you have to provide unit which is center of area, radius in Nm and number of verticals.

How to use,

First paste this code to script console and run:

Code: Select all

 -- RP.01
 -- Written by Baloogan
 -- Modified draw_circle by Yautay
  
 function draw_circle(a,b,t,txt)
     if txt == nil then
        txt = ""
     end
     t = t
     tg = t - 1
     lat1 = a.latitude
     lon1 = a.longitude
     r = b / 60 
  
     for i=0,tg do
         th = 2 * math.pi * i / t 
 	rlat = lat1 + r * math.cos(th)
         rlon = lon1 + r * math.sin(th) / math.cos(math.rad(lat1))
         ScenEdit_AddReferencePoint({
             side='PlayerSide',
             lat=rlat,
             lon=rlon,
             name=txt,
             highlighted="yes"})
     end
  
 end
 
 


Now paste this code, change red syntax for your own side/unit name (here is Red and test), change radius (350) and desired number of verticals (24). Run it...

Code: Select all

  
 local unit = ScenEdit_GetUnit({side="Red", name="test"})
 draw_circle({latitude=unit.latitude, longitude=unit.longitude}, 350, 24, "RP")
 
 

RE: [lua] drawing circles script

Posted: Fri Sep 30, 2016 9:08 pm
by thewood1
That is a big contribution for someone with only 13 posts in two years. Well done. And you are the god of lurkers.

RE: [lua] drawing circles script

Posted: Mon Oct 03, 2016 12:51 am
by temkc5
Thank you Michal [&o]

RE: [lua] drawing circles script

Posted: Tue Oct 04, 2016 6:36 am
by Michal Pielaszkiewicz
temkc5, does it work now?
M

RE: [lua] drawing circles script

Posted: Tue Oct 04, 2016 8:18 pm
by temkc5
Yes it work.

Wish I could say perfectly but it seems to has you said "not like spaces in the name" ie: Osama Bin Laden Airbase [:D]

But Trump Airport should work [8D]

Overall it's like that muscle car grandad is trying to restore once you get the engine going all the blood sweat and tears feels worth it

Keep Up The Great Work CMANO Community

(I only cut and paste the script and tried to enter the side & name to how the Lua prefers)

RE: [lua] drawing circles script

Posted: Wed Oct 05, 2016 12:21 pm
by U6443
Hi

Yes it works, for units...
Could somebody try to include Reference Points as source?

That would be great
Thank's
Andy

RE: [lua] drawing circles script

Posted: Wed Oct 05, 2016 1:00 pm
by stilesw
U6443,
I do not think you can use a reference point as the origin point. However you can create a temporary unit, say a small building on land or oil platform at sea, and use it as the center point. After the points are created just delete the building/platform and the RPs remain.

-Wayne Stiles

RE: [lua] drawing circles script

Posted: Wed Oct 05, 2016 2:38 pm
by U6443
Thank's

I would use this script for playing, not for creating scenarios.....

I hope in future it would be possible to create circles from reference points.