Vectors for the 2D / 3D world in Java

I read about math in games and wonder what is the best way to represent Vector's location in Java.

I know that there is a Vector class, but I do not think that this is what I need.

There is also a Matrix class that looks as if it could be what I want (maybe it could be a 1-dimensional matrix).

In particular, if I were to create a location vector, for example:

v (x, y, z), where x, y and z are the coordinates in three-dimensional space, which would be the best way to represent this in Java. It would be nice if I could add, subtract and find the point product of vectors.

ideas?

+3
source share
3 answers

maybe you can create a 3DVector class

Example:

class 3DVector {
   int x , y, z;

    public 3DVector(int x, int y, int z){
       //constructor
    }


    public 3DVector add(3DVector anotherVector){

    }

    public 3DVector subtract()....

    public 3DVector doProduct().....
}
+1

, :
javax.vecmath.Vector3d

+1

There is a math library, but a simple class with 3 floating point numbers is what everyone else uses

0
source

Source: https://habr.com/ru/post/1736945/


All Articles