3 ms·
Most academic code won't get repurposed. If a rewrite is necessary for commercial use, so be it. I once did a job like that in 1996. I was building a collisi
by Animats 11y ago
Most academic code won't get repurposed. If a rewrite is necessary for commercial use, so be it.
I once did a job like that in 1996. I was building a collision detection engine for an animation system. I had Lin's "I-Collide" to look at, and the paper that goes with it. This was one of the first fast many-vs-many collision detection systems. There's a bounding box layer for culling, and then a detailed layer for precision collision detection between pairs of objects.
The code was in C, but written strangely for C. Everything was lists, handled with raw pointer manipulation. When I saw something being appended to a list by reversing the list, adding a new member at the head, and reversing the list again, I realized that this had been written by a LISP programmer. As I found out later, it was originally in LISP, but had been rewritten in C to speed it up.
So I started over in C++, using classes for the geometry (Face, Edge, Vertex, Polyhedron, etc.) and collection classes (Microsoft's, this was pre-STL) for all the links between the geometry objects. This is one of those problems that maps well to an object model. I used a standard library of inlines for all the geometric calculations, added lots of checking for geometric inconsistencies, and commented the code properly. I noticed that the original implementation used a bubble sort when starting up the axis-oriented bounding box level, which made for a slow startup. I replaced the original separating vector algorithm with GJK. (I think mine was the first collision engine to use axis oriented bounding boxes with incremental GJK, which is fairly standard now.) I wrote a different approach to managing pairs of objects, so that pairs were created when objects got close together and released when they were no longer close. (I-Collide generated pairs, but never released them, which was a memory leak.) I added code to detect fast fly-throughs, so that a fast moving object couldn't get through another object between frame times.
I hooked the system up to QHull to generate convex polyhedra from input geometry, and OpenGL so I could see what was going on. The end result was faster and much more robust than the original.
That's the difference between academic proof of concept code and production code. Having the I-Collide implementation to look at and run was very helpful for insight into the algorithms, but in the end, the job required all new code. Making academics do this is inappropriate. Really, very little code needs to undergo such a process.
- dreamcompiler 11y agoJust to be clear, the Lisp code you describe sounds very amateurish. Like the code described in the post, its quality is a function of the programmer, not a function of Lisp. No professional Lisp programmer would write double-reverse consing lists for a serious application. He/she would use a tail-consing structure, an array, or (if it was Common Lisp) objects, as you did. The fact that they tried to speed this up by translating everything literally to C rather than first trying better algorithms and data structures is another red flag suggesting inexperience.