Is it possible to store a 3d unit length vector with only 2 components, for example as coordinates on a unit sphere? It seems possible but I have never seen anyone do this. Would this be at all practical?
No, it is not usually possible. But when it is, it’s quite useful.
The problem is that there will always be two possibilities for the missing coordinate. For instance, if you store
[0,0] this could mean the unit vector was either
[0,0,-1] and without additional information there is no way to tell which of the two it was.
Fortunately, in some cases that information is known. For instance if the vector is a normal to a surface, most of the time it is pointing outside the surface and so a local coordinate system can be chosen so that the missing coordinate is always positive.
Memory is indeed cheap nowadays; however, it is not always the case (think mobile platforms) and what’s not so cheap is the GPU bandwidth. The main advantage of packing vectors is that they help reduce that bandwidth usage.
So, what you mention does exist and does have practical uses, the most prominent example being the compression of normal maps (the Unity engine uses this technique to compress normal maps, and so does the C4 engine) and normal buffers (see this comprehensive article on compact normal storage that explores several other packing techniques, and this other article for yet another method).
Yes it's possible. Instead of using 3 cartesian coordinates [x, y, z] you can use 2 spherical coordinates [theta , phi] to represent any 3d unit vector. It depends on the case if it's useful or not. For example it can be useful for compressing animation data. There are also other representations you could use and there was actually an interesting paper released about compact 3d unit vector representations recently.
For many cases, it's possible. But it's not practical.
- Reduced memory requirements
- Reduced precision
- Increased complexity
By today's standards, memory is pretty cheap compared to time. Implementing and using a two component vector will take more development time as well as processing time whenever it's used. Keeping a three component vector only takes a little more memory, and is pretty straight forward to implement and quick to process.
There are, of course, exceptions to this. As explained in Sam's answer, where you can easily embrace the reduced precision I mention. You embrace reduced precision when you can make assumptions about what your third coordinate is going to be (typically, -1, 0, or 1 depending on the context).