I'm writing a simple implementation of the GJK algorithm (collision of convex shapes) in Java, and it involves a lot of simple calculations on 3D vectors. In terms of performance vs readability, would it be better to store the points as double[3] and have a whole host of static methods to process them (add, subtract, dot, cross, negate etc) or use a class with the methods contained within?
The problem with the array of doubles is that to do a simple subtraction (for instance) multiple loops are required if specialised methods are used, or the code becomes very long if they're hard-coded in. A Point object makes the code much more readable, but is it worth it for what I'm assuming is not an insignificant performance overhead?
My suggestion: make it work using whatever takes the least effort on your part, then optimize it later. It may turn out that the bottleneck in your application is something else entirely, and the improvement in the collision detection is but a minor piece.
For example, say you find that your application spends 10% of its time doing collision detection, and 50% of its time doing disk reads. If you can use caching to cut disk reads in half, you've improved execution by 25%, which is more than twice what you could optimally achieve by eliminating the collision detection time altogether.
As Donald Knuth said "premature optimization is the root of all evil."