I would like to store the x y and z co-ords for some objects for a game but I can’t find a built in class like Point. Is there a nice standard class I could add in and use that would handle distance between points/bearings from one object to another etc?
Share
Having recently done some vector mapping (including z / 3D), and seeing your Android tag, I recommend rolling your own.
The reasons are many:
In the end, most of these primitives are quite simple to write, test, etc. The main methods you’ll need to write (beyond boilerplate constructor/get/set/…)
– Distance
– Dot product
– Unitize (make length == 1 for various math ops)
– And I’ve used DistanceSquared in the past for comparison functions… This removes the sqrt operator from most distance methods, while computing a relative distance useful enough for comparing point distances etc.