Skip to content

1D, 2D, 3D and 4D vectors

Mike Anderson edited this page Aug 28, 2013 · 6 revisions

Vectorz has special support for 1D, 2D, 3D and 4D vectors. These have the following properties:

  • The elements are stored in public fields (x,y,z and t)
  • They have specialised, efficient functions that operate on and return vectors of the same size / type
  • They require less memory than regular Vector values of the same size, improving efficiency
  • They still extend AVector, so you get all the standard Vectorz functionality as usual

These small fixed-size vectors are very useful in many circumstances, e.g.

  • 2D and 3D graphics
  • Representing RGB and ARGB colours (as 3D and 4D vectors)
  • Physical modelling
  • Complex numbers (as 2D vectors)
  • Quaternions (as 4D vectors)

Examples

// create a new 3D vector
Vector3 v=Vector3.of(1,2,3);

// directly access the x-coordinate of a 3D vector
double x = v.x;

// add to a 3D vector (uses optimised 3D addition)
v.add(Vector3.of(2,3,4));
Clone this wiki locally