quote:Original post by Tree Penguin
Stop there! Summing the distances of the dimensions does NOT give you the 3d distance, not even when you''d do it in 2d, take a look at this:
...
Anyway even if you do need the distance in 1d that piece of code you gave is really slow, it can be replaced with this:
distance=x1-x2;
distance=max(distance,-distance);
or this:
distance=max(x1-x2,x2-x1);
For my piece of code, it just finds each distance between two points - it isn''t made to find the distance between two points that are on two different planes. The assumption is made that if you are trying to find say x1 and x2, you are assuming that y1,y2 and z1,z2 are the same. There is no 2D/3D vector conversion there.
You are right about it being limited to 1D but I was just presenting the code for finding the distance between two points assuming only 1 value changes within each point''s faction.
For the max function, I did not know of that function - thank you for pointing that out to me. Does that function also take negatives into account, say if x2 is negative and/or x1 is negative?