Java – Is there an equivalent of the Point class other than 3D points?

Is there an equivalent of the Point class other than 3D points?… here is a solution to the problem.

Is there an equivalent of the Point class other than 3D points?

I want to store the xy and z-coordinates of some objects in my game, but I can’t find a built-in class like Point. Is there a good standard class I can add and use it to handle the distance between points/bearings etc. from one object to another?

Solution

Recently did some vector mapping (including z/3D), seeing your Android tag, I suggest you scroll yourself.

There are many reasons:

  • You can customize to meet specific precision/memory/performance limits.
  • If it is multithreaded, you can make your class immutable and thread-safe
  • That is, if memory is limited, you can store all three dimensions in an int or long
  • If the CPU is limited, you can use plain individual numbers
  • If GC/Garbage is throttled, you can reclaim and pool instances (variable)

Finally, most of these primitives are very easy to write, test, etc. The main methods you need to write (except boilerplate constructor/get/set/…)
-distance
– Dot product
– Unitization (make length == 1 used for various mathematical operations)
– I’ve used DistanceSquared comparison functions in the past… This removes the sqrt operator from most distance methods while calculating a relative distance sufficient for comparing point distances, etc.

Related Problems and Solutions