Vector3f middle

I needed a method that took two Vector3f’s and returned a Vector3f that was right between them. I didn’t find one in the Vector3f class so I made one myself. It’s really simple.

[java] public Vector3f middle(Vector3f v1, Vector3f v2){

Vector3f pos = new Vector3f(v1);




return pos;


Use it as much as you like. Can be made static if you want.

Why is there no method like this in the Vector3f class? Perhaps I didn’t find it.


[java] Vector3f v1 = new Vector3f(2, 2, 2);

Vector3f v2 = new Vector3f(4, 4, 4);

Vector3f m = middle(v1, v2);


Prints (3.0, 3.0, 3.0).


normen said:

Those methods seems to be unnecessarily advanced for what I'm doing. I'll keep using my method :)

No, its very efficient and in contrast to your method it doesnt create a new vector.