Is there an equivalent to the Point class, but for three-dimensional points?

I would like to save the xy and z coordinates for some objects for the game, but I cannot find a built-in class like Point. Is there a good standard class that I could add and use to handle the distance between points / bearings from one object to another, etc.?

+4
source share
3 answers

Having recently done some vectorial mapping (including z / 3D) and seeing your Android tag, I recommend flipping yours.

There are many reasons:

  • You can configure to meet specific performance / memory / performance constraints.
  • If multithreading, you can make your class immutable and thread safe
  • those. If memory is limited, you can save all three dimensions in int or long
  • If cpu constrained you can use simple separate numbers
  • If GC / Garbage is limited, you can recycle and merge instances (mutable)

In the end, most of these primitives are fairly simple to write, test, etc. The main methods you need to write (in addition to the template constructor / get / set / ...) - Distance - Scalar product - Unify (make length == 1 for various mathematical operations) - And I used DistanceSquared in the past for comparison functions .. This removes the sqrt operator from most distance methods, calculating a relative distance useful enough to compare point distances, etc.

+4
source

Perhaps Point3D is what you need.

+3
source

There is also a JavaFX Point3D class that meets your requirements.

+1
source

All Articles