# vec3 swizzles as matrices

In this article I exhaustively enumerate some matrices and quaternions representing vec3 swizzles.

Languages like glsl have a neat feature where you can "swizzle" to swap coordinates. For example, vec3(4,5,6).zxy evaluates to vec3(6,4,5).

Playing around, I found that I could construct unit quaternions that performed this swizzling operation, but I couldn't find anything online about this relationship written up anywhere. It most likely exists under different terms.

Many of these unit quaternions would flip signs in addition to swizzling, so I have included them here as "signed swizzles". A capital letter X, Y, or Z denotes the negated form of the corresponding x, y, or z:

vec3(3,4,5).YxZ   // = vec3(-4,3,-5)
vec3(-1,7,-2).ZxY // = vec3(-4,3,-5)
vec3(8,5,1).yYy   // = vec3(5,-5,5)

If you are only interested in "classic swizzles" that don't flip any signs, simply ignore all signed swizzles with capital letters.

After creating some quaternions manually, I wrote some programs to exhaustively enumerate unit quaternions with integer values within ranges.

# quaternion

Here is the set of the only 24 quaternions I found for swizzles out of a total possible 216. Note that each of x, y, and z or its negated form appear exactly once. I bet there is a clever math reason why this is.

Another interesting fact about this set is that this is half of the possible swizzles where each letter or its negation appear exactly once. And each swizzle has a negated twin that has no associated quaternion.

I searched many more values than these (and found no more unique solutions), but all of these solutions below came from setting a -1, 0, or +1 as each item of the 4-item quaternion.

{
  "xyz": [0,0,0,1],
  "XYz": [0,0,1,0],
  "XyZ": [0,1,0,0],
  "xYZ": [1,0,0,0],
  "Xzy": [0,1,1,0],
  "xZy": [1,0,0,1],
  "xzY": [-1,0,0,1],
  "XZY": [0,-1,1,0],
  "Yxz": [0,0,1,1],
  "yXz": [0,0,-1,1],
  "yxZ": [1,1,0,0],
  "YXZ": [-1,1,0,0],
  "yzx": [-1,-1,-1,1],
  "YZx": [1,-1,1,1],
  "YzX": [-1,1,1,1],
  "yZX": [1,1,-1,1],
  "zxy": [1,1,1,1],
  "ZXy": [1,-1,-1,1],
  "ZxY": [-1,-1,1,1],
  "zXY": [-1,1,-1,1],
  "Zyx": [0,-1,0,1],
  "zYx": [1,0,1,0],
  "zyX": [0,1,0,1],
  "ZYX": [-1,0,1,0]
}

# 3x3 matrix

Like with quaternions, each of these results came from setting -1, 0, or +1 into each of the 9 slots of a 3x3 matrix.

Interestingly, under that procedure, each possible vec3 swizzle has exactly 1 solution.

The matrix layout here is the opengl/glmatrix way.

{
  "xxx": [1,1,1,0,0,0,0,0,0],
  "xxX": [1,1,-1,0,0,0,0,0,0],
  "xxy": [1,1,0,0,0,1,0,0,0],
  "xxY": [1,1,0,0,0,-1,0,0,0],
  "xxz": [1,1,0,0,0,0,0,0,1],
  "xxZ": [1,1,0,0,0,0,0,0,-1],
  "xXx": [1,-1,1,0,0,0,0,0,0],
  "xXX": [1,-1,-1,0,0,0,0,0,0],
  "xXy": [1,-1,0,0,0,1,0,0,0],
  "xXY": [1,-1,0,0,0,-1,0,0,0],
  "xXz": [1,-1,0,0,0,0,0,0,1],
  "xXZ": [1,-1,0,0,0,0,0,0,-1],
  "xyx": [1,0,1,0,1,0,0,0,0],
  "xyX": [1,0,-1,0,1,0,0,0,0],
  "xyy": [1,0,0,0,1,1,0,0,0],
  "xyY": [1,0,0,0,1,-1,0,0,0],
  "xyz": [1,0,0,0,1,0,0,0,1],
  "xyZ": [1,0,0,0,1,0,0,0,-1],
  "xYx": [1,0,1,0,-1,0,0,0,0],
  "xYX": [1,0,-1,0,-1,0,0,0,0],
  "xYy": [1,0,0,0,-1,1,0,0,0],
  "xYY": [1,0,0,0,-1,-1,0,0,0],
  "xYz": [1,0,0,0,-1,0,0,0,1],
  "xYZ": [1,0,0,0,-1,0,0,0,-1],
  "xzx": [1,0,1,0,0,0,0,1,0],
  "xzX": [1,0,-1,0,0,0,0,1,0],
  "xzy": [1,0,0,0,0,1,0,1,0],
  "xzY": [1,0,0,0,0,-1,0,1,0],
  "xzz": [1,0,0,0,0,0,0,1,1],
  "xzZ": [1,0,0,0,0,0,0,1,-1],
  "xZx": [1,0,1,0,0,0,0,-1,0],
  "xZX": [1,0,-1,0,0,0,0,-1,0],
  "xZy": [1,0,0,0,0,1,0,-1,0],
  "xZY": [1,0,0,0,0,-1,0,-1,0],
  "xZz": [1,0,0,0,0,0,0,-1,1],
  "xZZ": [1,0,0,0,0,0,0,-1,-1],
  "Xxx": [-1,1,1,0,0,0,0,0,0],
  "XxX": [-1,1,-1,0,0,0,0,0,0],
  "Xxy": [-1,1,0,0,0,1,0,0,0],
  "XxY": [-1,1,0,0,0,-1,0,0,0],
  "Xxz": [-1,1,0,0,0,0,0,0,1],
  "XxZ": [-1,1,0,0,0,0,0,0,-1],
  "XXx": [-1,-1,1,0,0,0,0,0,0],
  "XXX": [-1,-1,-1,0,0,0,0,0,0],
  "XXy": [-1,-1,0,0,0,1,0,0,0],
  "XXY": [-1,-1,0,0,0,-1,0,0,0],
  "XXz": [-1,-1,0,0,0,0,0,0,1],
  "XXZ": [-1,-1,0,0,0,0,0,0,-1],
  "Xyx": [-1,0,1,0,1,0,0,0,0],
  "XyX": [-1,0,-1,0,1,0,0,0,0],
  "Xyy": [-1,0,0,0,1,1,0,0,0],
  "XyY": [-1,0,0,0,1,-1,0,0,0],
  "Xyz": [-1,0,0,0,1,0,0,0,1],
  "XyZ": [-1,0,0,0,1,0,0,0,-1],
  "XYx": [-1,0,1,0,-1,0,0,0,0],
  "XYX": [-1,0,-1,0,-1,0,0,0,0],
  "XYy": [-1,0,0,0,-1,1,0,0,0],
  "XYY": [-1,0,0,0,-1,-1,0,0,0],
  "XYz": [-1,0,0,0,-1,0,0,0,1],
  "XYZ": [-1,0,0,0,-1,0,0,0,-1],
  "Xzx": [-1,0,1,0,0,0,0,1,0],
  "XzX": [-1,0,-1,0,0,0,0,1,0],
  "Xzy": [-1,0,0,0,0,1,0,1,0],
  "XzY": [-1,0,0,0,0,-1,0,1,0],
  "Xzz": [-1,0,0,0,0,0,0,1,1],
  "XzZ": [-1,0,0,0,0,0,0,1,-1],
  "XZx": [-1,0,1,0,0,0,0,-1,0],
  "XZX": [-1,0,-1,0,0,0,0,-1,0],
  "XZy": [-1,0,0,0,0,1,0,-1,0],
  "XZY": [-1,0,0,0,0,-1,0,-1,0],
  "XZz": [-1,0,0,0,0,0,0,-1,1],
  "XZZ": [-1,0,0,0,0,0,0,-1,-1],
  "yxx": [0,1,1,1,0,0,0,0,0],
  "yxX": [0,1,-1,1,0,0,0,0,0],
  "yxy": [0,1,0,1,0,1,0,0,0],
  "yxY": [0,1,0,1,0,-1,0,0,0],
  "yxz": [0,1,0,1,0,0,0,0,1],
  "yxZ": [0,1,0,1,0,0,0,0,-1],
  "yXx": [0,-1,1,1,0,0,0,0,0],
  "yXX": [0,-1,-1,1,0,0,0,0,0],
  "yXy": [0,-1,0,1,0,1,0,0,0],
  "yXY": [0,-1,0,1,0,-1,0,0,0],
  "yXz": [0,-1,0,1,0,0,0,0,1],
  "yXZ": [0,-1,0,1,0,0,0,0,-1],
  "yyx": [0,0,1,1,1,0,0,0,0],
  "yyX": [0,0,-1,1,1,0,0,0,0],
  "yyy": [0,0,0,1,1,1,0,0,0],
  "yyY": [0,0,0,1,1,-1,0,0,0],
  "yyz": [0,0,0,1,1,0,0,0,1],
  "yyZ": [0,0,0,1,1,0,0,0,-1],
  "yYx": [0,0,1,1,-1,0,0,0,0],
  "yYX": [0,0,-1,1,-1,0,0,0,0],
  "yYy": [0,0,0,1,-1,1,0,0,0],
  "yYY": [0,0,0,1,-1,-1,0,0,0],
  "yYz": [0,0,0,1,-1,0,0,0,1],
  "yYZ": [0,0,0,1,-1,0,0,0,-1],
  "yzx": [0,0,1,1,0,0,0,1,0],
  "yzX": [0,0,-1,1,0,0,0,1,0],
  "yzy": [0,0,0,1,0,1,0,1,0],
  "yzY": [0,0,0,1,0,-1,0,1,0],
  "yzz": [0,0,0,1,0,0,0,1,1],
  "yzZ": [0,0,0,1,0,0,0,1,-1],
  "yZx": [0,0,1,1,0,0,0,-1,0],
  "yZX": [0,0,-1,1,0,0,0,-1,0],
  "yZy": [0,0,0,1,0,1,0,-1,0],
  "yZY": [0,0,0,1,0,-1,0,-1,0],
  "yZz": [0,0,0,1,0,0,0,-1,1],
  "yZZ": [0,0,0,1,0,0,0,-1,-1],
  "Yxx": [0,1,1,-1,0,0,0,0,0],
  "YxX": [0,1,-1,-1,0,0,0,0,0],
  "Yxy": [0,1,0,-1,0,1,0,0,0],
  "YxY": [0,1,0,-1,0,-1,0,0,0],
  "Yxz": [0,1,0,-1,0,0,0,0,1],
  "YxZ": [0,1,0,-1,0,0,0,0,-1],
  "YXx": [0,-1,1,-1,0,0,0,0,0],
  "YXX": [0,-1,-1,-1,0,0,0,0,0],
  "YXy": [0,-1,0,-1,0,1,0,0,0],
  "YXY": [0,-1,0,-1,0,-1,0,0,0],
  "YXz": [0,-1,0,-1,0,0,0,0,1],
  "YXZ": [0,-1,0,-1,0,0,0,0,-1],
  "Yyx": [0,0,1,-1,1,0,0,0,0],
  "YyX": [0,0,-1,-1,1,0,0,0,0],
  "Yyy": [0,0,0,-1,1,1,0,0,0],
  "YyY": [0,0,0,-1,1,-1,0,0,0],
  "Yyz": [0,0,0,-1,1,0,0,0,1],
  "YyZ": [0,0,0,-1,1,0,0,0,-1],
  "YYx": [0,0,1,-1,-1,0,0,0,0],
  "YYX": [0,0,-1,-1,-1,0,0,0,0],
  "YYy": [0,0,0,-1,-1,1,0,0,0],
  "YYY": [0,0,0,-1,-1,-1,0,0,0],
  "YYz": [0,0,0,-1,-1,0,0,0,1],
  "YYZ": [0,0,0,-1,-1,0,0,0,-1],
  "Yzx": [0,0,1,-1,0,0,0,1,0],
  "YzX": [0,0,-1,-1,0,0,0,1,0],
  "Yzy": [0,0,0,-1,0,1,0,1,0],
  "YzY": [0,0,0,-1,0,-1,0,1,0],
  "Yzz": [0,0,0,-1,0,0,0,1,1],
  "YzZ": [0,0,0,-1,0,0,0,1,-1],
  "YZx": [0,0,1,-1,0,0,0,-1,0],
  "YZX": [0,0,-1,-1,0,0,0,-1,0],
  "YZy": [0,0,0,-1,0,1,0,-1,0],
  "YZY": [0,0,0,-1,0,-1,0,-1,0],
  "YZz": [0,0,0,-1,0,0,0,-1,1],
  "YZZ": [0,0,0,-1,0,0,0,-1,-1],
  "zxx": [0,1,1,0,0,0,1,0,0],
  "zxX": [0,1,-1,0,0,0,1,0,0],
  "zxy": [0,1,0,0,0,1,1,0,0],
  "zxY": [0,1,0,0,0,-1,1,0,0],
  "zxz": [0,1,0,0,0,0,1,0,1],
  "zxZ": [0,1,0,0,0,0,1,0,-1],
  "zXx": [0,-1,1,0,0,0,1,0,0],
  "zXX": [0,-1,-1,0,0,0,1,0,0],
  "zXy": [0,-1,0,0,0,1,1,0,0],
  "zXY": [0,-1,0,0,0,-1,1,0,0],
  "zXz": [0,-1,0,0,0,0,1,0,1],
  "zXZ": [0,-1,0,0,0,0,1,0,-1],
  "zyx": [0,0,1,0,1,0,1,0,0],
  "zyX": [0,0,-1,0,1,0,1,0,0],
  "zyy": [0,0,0,0,1,1,1,0,0],
  "zyY": [0,0,0,0,1,-1,1,0,0],
  "zyz": [0,0,0,0,1,0,1,0,1],
  "zyZ": [0,0,0,0,1,0,1,0,-1],
  "zYx": [0,0,1,0,-1,0,1,0,0],
  "zYX": [0,0,-1,0,-1,0,1,0,0],
  "zYy": [0,0,0,0,-1,1,1,0,0],
  "zYY": [0,0,0,0,-1,-1,1,0,0],
  "zYz": [0,0,0,0,-1,0,1,0,1],
  "zYZ": [0,0,0,0,-1,0,1,0,-1],
  "zzx": [0,0,1,0,0,0,1,1,0],
  "zzX": [0,0,-1,0,0,0,1,1,0],
  "zzy": [0,0,0,0,0,1,1,1,0],
  "zzY": [0,0,0,0,0,-1,1,1,0],
  "zzz": [0,0,0,0,0,0,1,1,1],
  "zzZ": [0,0,0,0,0,0,1,1,-1],
  "zZx": [0,0,1,0,0,0,1,-1,0],
  "zZX": [0,0,-1,0,0,0,1,-1,0],
  "zZy": [0,0,0,0,0,1,1,-1,0],
  "zZY": [0,0,0,0,0,-1,1,-1,0],
  "zZz": [0,0,0,0,0,0,1,-1,1],
  "zZZ": [0,0,0,0,0,0,1,-1,-1],
  "Zxx": [0,1,1,0,0,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,-1,-1]
}

# 4x4 matrix

Like with quaternions, each of these results came from setting -1, 0, or +1 into each of the 16 slots of a 4x4 matrix. Each swizzle has 3 solutions but only one is shown below.

The matrix layout here is the opengl/glmatrix way.

{
  "xxx": [1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0],
  "xxX": [1,1,-1,0,0,0,0,0,0,0,0,0,0,0,0,0],
  "xxy": [1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0],
  "xxY": [1,1,0,0,0,0,-1,0,0,0,0,0,0,0,0,0],
  "xxz": [1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0],
  "xxZ": [1,1,0,0,0,0,0,0,0,0,-1,0,0,0,0,0],
  "xXx": [1,-1,1,0,0,0,0,0,0,0,0,0,0,0,0,0],
  "xXX": [1,-1,-1,0,0,0,0,0,0,0,0,0,0,0,0,0],
  "xXy": [1,-1,0,0,0,0,1,0,0,0,0,0,0,0,0,0],
  "xXY": [1,-1,0,0,0,0,-1,0,0,0,0,0,0,0,0,0],
  "xXz": [1,-1,0,0,0,0,0,0,0,0,1,0,0,0,0,0],
  "xXZ": [1,-1,0,0,0,0,0,0,0,0,-1,0,0,0,0,0],
  "xyx": [1,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0],
  "xyX": [1,0,-1,0,0,1,0,0,0,0,0,0,0,0,0,0],
  "xyy": [1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0],
  "xyY": [1,0,0,0,0,1,-1,0,0,0,0,0,0,0,0,0],
  "xyz": [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0],
  "xyZ": [1,0,0,0,0,1,0,0,0,0,-1,0,0,0,0,0],
  "xYx": [1,0,1,0,0,-1,0,0,0,0,0,0,0,0,0,0],
  "xYX": [1,0,-1,0,0,-1,0,0,0,0,0,0,0,0,0,0],
  "xYy": [1,0,0,0,0,-1,1,0,0,0,0,0,0,0,0,0],
  "xYY": [1,0,0,0,0,-1,-1,0,0,0,0,0,0,0,0,0],
  "xYz": [1,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