[lua] drawing circles script

Post new mods and scenarios here.

Moderator: MOD_Command

Post Reply
Michal Pielaszkiewicz
Posts: 18
Joined: Tue Sep 23, 2014 9:37 am

[lua] drawing circles script

Post 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")
 
 
thewood1
Posts: 10092
Joined: Sun Nov 27, 2005 6:24 pm
Location: Boston

RE: [lua] drawing circles script

Post 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.
temkc5
Posts: 113
Joined: Sun Oct 11, 2015 8:30 pm

RE: [lua] drawing circles script

Post by temkc5 »

Thank you Michal [&o]
Non mihi, Non tibi, Sed nobis

Michal Pielaszkiewicz
Posts: 18
Joined: Tue Sep 23, 2014 9:37 am

RE: [lua] drawing circles script

Post by Michal Pielaszkiewicz »

temkc5, does it work now?
M
temkc5
Posts: 113
Joined: Sun Oct 11, 2015 8:30 pm

RE: [lua] drawing circles script

Post 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)
Non mihi, Non tibi, Sed nobis

U6443
Posts: 30
Joined: Fri Jul 02, 2004 5:24 pm

RE: [lua] drawing circles script

Post by U6443 »

Hi

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

That would be great
Thank's
Andy
User avatar
stilesw
Posts: 1572
Joined: Wed Jun 25, 2014 10:08 pm
Location: Hansville, WA, USA

RE: [lua] drawing circles script

Post 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
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”

Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
U6443
Posts: 30
Joined: Fri Jul 02, 2004 5:24 pm

RE: [lua] drawing circles script

Post 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.
Post Reply

Return to “Mods and Scenarios”