Quadtree for 2D collision detection

Your quadtree structure isn’t optimal. You’re right to store 4 subtrees per node, but actual objects should only be stored inside the leaves, not inner nodes. Therefore the collection holding the actual objects needs to be moved to the leaves. Let’s have a look at the implementation of the operations: Insert an object into the … Read more

Modules and namespace / name collision in AngularJS

As of today, AngularJS modules do not provide any sort of namespacing that would prevent collisions between objects in different modules. The reason is that an AngularJS app has a single injector that holds names for all objects without respect to module names. The AngularJS Developer Guide says: To manage the responsibility of dependency creation, … Read more

What is a good 64bit hash function in Java for textual strings?

Why don’t you use a long variant of the default String.hashCode() (where some really smart guys certainly put effort into making it efficient – not mentioning the thousands of developer eyes that already looked at this code)? // adapted from String.hashCode() public static long hash(String string) { long h = 1125899906842597L; // prime int len … Read more

How to deal with symbol collisions between statically linked libraries?

At least in the case of static libraries you can work around it quite conveniently. Consider those headers of libraries foo and bar. For the sake of this tutorial I’ll also give you the source files examples/ex01/foo.h int spam(void); double eggs(void); examples/ex01/foo.c (this may be opaque/not available) int the_spams; double the_eggs; int spam() { return … Read more

Efficient (and well explained) implementation of a Quadtree for 2D collision detection [closed]

Efficient Quadtrees All right, I’ll take a shot at this. First a teaser to show the results of what I’ll propose involving 20,000 agents (just something I whipped up real quick for this specific question): The GIF has extremely reduced frame rate and significantly lower res to fit the 2 MB maximum for this site. … Read more

Why are my balls disappearing? [closed]

Your error comes from this line initially: var direction1 = Math.atan2(ball1.velocitY, ball1.velocityX); You have ball1.velocitY (which is undefined) instead of ball1.velocityY. So Math.atan2 is giving you NaN, and that NaN value is propagating through all your calculations. This is not the source of your error, but there is something else that you might want to … Read more

Likelihood of collision using most significant bits of a UUID in Java

According to the documentation, the static method UUID.randomUUID() generates a type 4 UUID. This means that six bits are used for some type information and the remaining 122 bits are assigned randomly. The six non-random bits are distributed with four in the most significant half of the UUID and two in the least significant half. … Read more

tech