Do people prefer to represent 3D points in space using arrays of double / float primitives, or a custom class?
I use a class similar to the one below, but I’m wondering if there’s a speed benefit (even if it’s a small one) to using an array of doubles instead?
public class JVector3
{
double x = 0;
double y = 0;
double z = 0;
JVector3 ()
{
this.x = 0.0;
this.y = 0.0;
this.z = 0.0;
}
public JVector3 (JVector3 v)
{
this.x = v.x;
this.y = v.y;
this.z = v.z;
}
}
The only single immediate advantage I can see to using double[] instead of JVector3 is the ability to quickly iterate through all the points in the array:
for (int i=0; i < darray.length; i++)
darray[i] *= 6;
Thoughts?