I have an array contanining the position of the different objects in my scene.
To calculate the next movement step
I want to build a function like this:
f(x) = 1/(x-pos1)^2 + 1/(x-pos2)^2 + ...
^term1 ^term2 ^term_n
I don’t know how many objects are in my scene so I want to add terms in the function for each objects:
something like:
for object in scene:
add_one_term_to_the_function
return function
is there a way to program this?
Preferably in C++ or Python… the only two languages I know…
PS: thx for the answers… but a loop is not what I’m looking for. This would be extremly slow.. because it will calculate the function everytime I call a next event… but I want to calculte it only once… and then pass the events to the calculated “function”…
Why not loop over them?
It’s not going to be very much slower than otherwise.
If you really want to do it in python you can do it like this (but I beleive it’s going to be very slow)
There is no real analogue in C++, because C++ doesn’t have closures.
One could simulate it, but it won’t be the same, and then you could use a list and a loop instead anyway.