## Help with "advanced" maths :O

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Forboding Angel
Evolution RTS Developer
Posts: 14657
Joined: 17 Nov 2005, 02:43

### Help with "advanced" maths :O

This block causes 7 control points to be placed in a big circle all the way around the map

Code: Select all

``````			--Since no config file is found, we create 7 points spaced out in a circle on the map
local angle = math.random() * math.pi * 2
points = {}
for i=1,7 do
local angle = angle + i * math.pi * 2/7
points[i] = {
x=mapx/2 + mapx * .4 * math.sin(angle),
y=0,
z=mapz/2 + mapz * .4 * math.cos(angle),
owner=nil,
aggressor=nil,
capture=0,
}
end``````
What I would like is for there to be 6 circles in a circle around the map and one circle be directly in the center. I can has halp?
LordMuffe
Posts: 284
Joined: 13 Mar 2005, 15:39

### Re: Help with "advanced" maths :O

not sure about the syntax, but isnt it just :

local angle = math.random() * math.pi * 2
points = {}
for i=1,6 do
local angle = angle + i * math.pi * 2/6
points = {
x=mapx/2 + mapx * .4 * math.sin(angle),
y=0,
z=mapz/2 + mapz * .4 * math.cos(angle),
owner=nil,
aggressor=nil,
capture=0,
}
und

points[7] = {
x=mapx/2,
y=0,
z=mapz/2,
}
Jools
XTA Developer
Posts: 2814
Joined: 23 Feb 2009, 16:29

### Re: Help with "advanced" maths :O

This isn't advanced math. When I saw the topic I thought: finally someone wanting to discuss Hilbert's space. But it was just trigonometry.

But advanced was in quotation marks so I guess it's all right.
Silentwings
Moderator
Posts: 3696
Joined: 25 Oct 2008, 00:23

### Re: Help with "advanced" maths :O

Next question, how to achieve the same result in projective space.
PicassoCT
Journeywar Developer & Mapper
Posts: 10382
Joined: 24 Jan 2006, 21:12

### Re: Help with "advanced" maths :O

?
Scale all the resulting bitmaps with matrices?
8611z
Posts: 169
Joined: 08 Jul 2015, 20:20

### Re: Help with "advanced" maths :O

how to change one number
PicassoCT
Journeywar Developer & Mapper
Posts: 10382
Joined: 24 Jan 2006, 21:12

### Re: Help with "advanced" maths :O

Oh, a philosophical Question. You cant change a number, you can reduce it with itself to the identity (1) and then multiply it back to another number, but you never can change it.
LordMuffe
Posts: 284
Joined: 13 Mar 2005, 15:39

### Re: Help with "advanced" maths :O

PicassoCT wrote:Oh, a philosophical Question. You cant change a number, you can reduce it with itself to the identity (1) and then multiply it back to another number, but you never can change it.
If you dance with the number, the number doesn't change. The number changes you...
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6238
Joined: 29 Apr 2005, 01:14

### Re: Help with "advanced" maths :O

Forboding Angel wrote: What I would like is for there to be 6 circles in a circle around the map and one circle be directly in the center. I can has halp?
Do you mean 6 control points in a circle with one in the centre (as LordMuffe provided) or do you literally mean multiple control points in a circle, 6 of those circles of control points (lets call them groups) and another group in the centre of the map?
LordMuffe
Posts: 284
Joined: 13 Mar 2005, 15:39

### Re: Help with "advanced" maths :O

Don´t know how lua handels for-cycles, but it could look like this for the second case:

Code: Select all

``````         local angle = math.random() * math.pi * 2
points = {}

for j=1,6 do

for i=1,6 do

local anglesmall = anglesmall + i * math.pi * 2/6
local angelbig = angelbig + j * math.pi * 2/6

points[i+(j-1)*6] = {
x=mapx/2 + mapx * .04 * math.sin(anglesmall) + mapx * .4 * math.sin(anglebig),
y=0,
z=mapz/2 + mapz * .04 * math.cos(angle) + mapx * .4 * math.cos(anglebig),
owner=nil,
aggressor=nil,
capture=0,
}

for i=37,42 do

local anglesmall = anglesmall + (i-36) * math.pi * 2/6

points[i] = {
x=mapx/2 + mapx * .04 * math.sin(anglesmall),
y=0,
z=mapz/2 + mapz * .04 * math.cos(anglesmall),
owner=nil,
aggressor=nil,
capture=0,
}
end``````
Forboding Angel
Evolution RTS Developer
Posts: 14657
Joined: 17 Nov 2005, 02:43

### Re: Help with "advanced" maths :O

FLOZi wrote:
Forboding Angel wrote: What I would like is for there to be 6 circles in a circle around the map and one circle be directly in the center. I can has halp?
Do you mean 6 control points in a circle with one in the centre (as LordMuffe provided) or do you literally mean multiple control points in a circle, 6 of those circles of control points (lets call them groups) and another group in the centre of the map?
What lordmuffe provided was what I was looking for. A little while after I posted this thread It occurred to me that that answer to the question was simple and I did it myself, doah.

I do have another issue though. For some reason, allowunitcreation is only working for configs and not for autogenerated points. Which is weird because as far as I can tell, they use the same table.

For example:

Here the config is read, and each point is put into a table called points: https://github.com/EvolutionRTS/Evoluti ... y.lua#L279

Then if the config isn't found, they are autogenerated, and put in a table called points: https://github.com/EvolutionRTS/Evoluti ... y.lua#L291

Then later on, allowcommand does it's thing on the points table, but it only works for config points: https://github.com/EvolutionRTS/Evoluti ... y.lua#L459

Any ideas why?