|
This is more a programming question than an algorithm question.
What languages do you know?
Silver member by constant and unflinching longevity.
|
|
|
|
|
Just a brief question. In a little demo I've got going I can have up to 300 objects floating around the screen and checking every object against every other object is painfully slow.
Using a quad tree to split the screen up and group the objects greatly speeds up checking for collisions but unfortunately rebuilding the quad tree every frame eats up quite a lot of the performance that you gain from using it.
Does anybody have any idea's on what I could do, bearing in mind that all 300 objects will constantly be moving and are all fairly close together, so trying to only update objects that have moved would cause the entire tree to be jiggled about a little bit, perhaps costing more time that a full rebuild.
My current favourite word is: Sammidge!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
why use a tree that is bound to become invalid all the time?
I would see the screen as a 2D matrix (say N*N) with N around typical screen size divided by typical object size (and not larger than say 10), so each object typically spans two rows and two columns. Each screen cell could be represented by a List containing references to the objects that (partially) lie inside it, and a timestamp.
One time step would:
- move some objects, checking them against the 2D matrix cells; resulting in possibly removing them from some lists, and possibly adding them to some lists; store current time in cells objects got added to.
- then foreach cell marked with current time, check the listed objects for overlap.
Possible optimization: give each object a list of cells it currently is in; this would speed up the removal step.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Alternative solution:
re-structure your "tree" and use a radial(gross) test
radial:
if((dist(a,b)^2-RadiusSqrd)<0)
{
}
(pathagarean therum with a bit of inside/outside circle, with small error...) it is fast.
Gross:
or iterativly restructure your list...
public static int blah(point P, point Q)
{
if(P.X>Q.x){ return 1;}
else if(P.X==Q.x){return 0}
else{return-1}
}
this way you would only need to "check" against neighbors in the tree structure.
alternativly you could use a float type(but that is basically the radial method of above)
using this method you basically only ever have a few checks,
there is one other way off hand..
I lik eto use the System.Drawing.Region (i forget the name) but it will give the union or difference of two "polygon"(regions) which is on the gpu and crazy fast.. in which case you may be able to do it brute force.. cus it is fast.. if you like this, or need more reference send me a ping and I will scrounge up the code for you.. leaving work --Hurray
|
|
|
|
|
in the name of god
hello
how can we solve this problem to find the order of it:
T(n)=sqrt(n)*(T(sqrt(n))+n
order =?
valhamdolelah.
|
|
|
|
|
There is no base case, what is T(1) ?
|
|
|
|
|
take a constant as C>0
valhamdolelah.
|
|
|
|
|
Ok then I think:
T(n) = (n * C)/(e^2) + (n * ln(ln(n))) / ln(2)
edit: that would be O(n log(log n)) I think
|
|
|
|
|
thanks
please say the way?how we can gain to this?
valhamdolelah.
|
|
|
|
|
|
solution =?
how do you solve it?
valhamdolelah.
|
|
|
|
|
Well I cheated and put it on wolfram alpha, this wasn't an exam so
|
|
|
|
|
thanks but i want to know how to solve this problems.
valhamdolelah.
|
|
|
|
|
I don't know what you mean
|
|
|
|
|
In the end, he does want the answer, but he is more interested in how you come up with the answer - the way to solve it. In effect, he does not want you to do his homework for him, he wants to know HOW to do his homework.
That is unusual for this kind of question, and I think he deserves kudos!
Unfortunately, I don't know how to solve it.
Silver member by constant and unflinching longevity.
|
|
|
|
|
Thank you for wanting to know HOW, not just wanting the answer.
.
Are you solving for the computational order of an algorithm that takes this long to process (the Big O notation), or are you looking for a numerical order of magnitude for the result of applying this equation to an arbitrary value 'n' ( eg. T(2) = sqrt(2)+T(sqrt(2))+2)?
.
T(n)=sqrt(n)*(T(sqrt(n))+n
.
The Big O would be O(n). the two terms are added together, so each term can be taken by itself.
sqrt(n) * T(sqrt(n))becomes 'n' in the limit, so you have two O(n) terms, which is the same as O(n).
.
If you are looking for numerics, I can't really help you.
Silver member by constant and unflinching longevity.
|
|
|
|
|
thanks very much for your attention
i want to know the computational order of it as you said :
sqrt(n) * T(sqrt(n))becomes 'n' in the limit, so you have two O(n) terms, which is the same as O(n).
but why in limit it becomes n?,please explain more.
also i think finding it as numerical would be interesting but i think this would be hard!!!
thanks.
|
|
|
|
|
response below
Silver member by constant and unflinching longevity.
|
|
|
|
|
I have to disagree. The two terms are not O(n) at all, one of them is O(n^0.5) which is asymptotically different from O(n), and the other is unknown until the recursion is solved.
|
|
|
|
|
response below your entry
Silver member by constant and unflinching longevity.
|
|
|
|
|
I'm answering both of you, so I am just tacking it on to the end.
The problem in what I wrote was with the T(sqrt(n)) part of the function.
The answer hinges on what F(n) = sqrt(n)*F(sqrt(n)) is. I was thinking it approached (n), but I see I was wrong, it may approach(n^1.5), which would mean it dominated.
When you add in the (+ n), with an infinite recursion, I see that this goes to infinity, even for n = 1.
As a matter of fact, I will kick my own but on this and say that, while I don't know which order of infinity this ends up being, but, since there is no stop condition on the recursion, the answer, even for n=1 is infinity, given this analysis:
T(1) = 1*T(1)+1
which shows that you end up adding 1 at each recursion level, with an infinite number of recursions (no stop condition). And it just gets larger from there.
khomeyni - sorry for my flawed analysis, thank you for asking why.
harold aptroot - is that a better analysis? I'm asking, not being snide.
Silver member by constant and unflinching longevity.
|
|
|
|
|
Yes this is better, this is why I asked him what T(1) was, and he said "take a constant as C>0", which significantly changes the result
|
|
|
|
|
thanks for your getting involved in it
i say that we must take T(1) a constant as c so the stop condition is T(1),but i dont know how either you or harold aptroot solved this? you said that it would be n^1.5 how you find it?
please explain more on the solution not only the final answer.if we only find a order it is enough.
thanks.
valhamdolelah.
|
|
|
|
|
khomeyni wrote: you said that it would be n^1.5 how you find it?
I said that about t(n) = sqrt(n)+T(sqrt(n)),but waswrong on the overall analysis at that point.
Than I went on to do the actual form t(n)=sqrt(n)+t(sqrt(n))+n and said it was infinite, though I don't know what order.
Even if you remove the sqrt(n)part, t(n)=t(sqrt(n))+n, but assume t(1) is a stop condition,if you try t(n >1), sqrt(sqrt(sqrt(...(n)))) approaches, but never reaches 1, so you have and infinite series of summing for x = 1 to infinity of n^(1/x).
Sums an infinite progression of numbers > 1.
Silver member by constant and unflinching longevity.
|
|
|
|
|