# Coloring according to orientation

I have the set of the following 3D objects (this is an MWE just for visualization of the issue):

Graphics3D[{Table[
Translate[Sphere[{2, 2, 3}], {i, i, Sqrt[2] i}], {i, 0, 2}],
Table[Translate[Sphere[{2, 2, 3}], {i, i, -Sqrt[2] i}], {i, 1, 2}],
Table[Translate[Sphere[{-2, -1, -3}], {i, -i, Sqrt[2] i}], {i, 0, 2}], Table[Translate[Sphere[{-2, -1, -3}], {i, -i, -Sqrt[2] i}], {i, 1, 2}], {Arrow[{{0, 0, 0}, {0, 0, 5}}],
Text["Z", {0, 0, 5.5}]}, {Arrow[{{0, 0, 0}, {0, 5, 0}}],
Text["Y", {0, 5.5, 0}]}, {Arrow[{{0, 0, 0}, {5, 0, 0}}],
Text["X", {5.5, 0, 0}]}}, Boxed -> False]


and I would like to color them according to the projection of their $$C_2$$ axes on the $$X$$-axis. Green — parallel ($$X+$$) and yellow — antiparallel ($$X-$$) would be reference states, i.e.:

Graphics3D[{{Green,
Table[Translate[Sphere[{2, 0, 0}], {i, 0, Sqrt[2] i}], {i, 0, 2}],
Table[Translate[Sphere[{2, 0, 0}], {i, 0, -Sqrt[2] i}], {i, 1,
2}]}, {Yellow, Table[Translate[Sphere[{-2, 0, 0}], {-i, 0, Sqrt[2] i}], {i, 0,
2}], Table[Translate[Sphere[{-2, 0, 0}], {-i, 0, -Sqrt[2] i}], {i, 1,
2}]}, {Arrow[{{0, 0, 0}, {0, 0, 5}}],
Text["Z", {0, 0, 5.5}]}, {Arrow[{{0, 0, 0}, {5, 0, 0}}],
Text["X", {5.5, 0, 0}]}}, Boxed -> False]


thus, objects from MWE should be colored via the gradient color of green/yellow.

Instead of using Translate, simply add the displacement to the center point. First, generate all spheres, and then colour them according to their $$x$$-coordinate.

spheres = Flatten[{
Table[Sphere[{2, 2, 3} + {i, i, Sqrt[2] i}], {i, 0, 2}],
Table[Sphere[{2, 2, 3} + {i, i, -Sqrt[2] i}], {i, 1, 2}],
Table[Sphere[{-2, -1, -3} + {i, -i, Sqrt[2] i}], {i, 0, 2}],
Table[Sphere[{-2, -1, -3} + {i, -i, -Sqrt[2] i}], {i, 1, 2}]}];
axes = {Arrow[{{0, 0, 0}, {0, 0, 5}}], Text["Z", {0, 0, 5.5}],
Arrow[{{0, 0, 0}, {0, 5, 0}}], Text["Y", {0, 5.5, 0}],
Arrow[{{0, 0, 0}, {5, 0, 0}}], Text["X", {5.5, 0, 0}]};

minmax = MinMax[spheres[[All, 1, 1]]];
Graphics3D[{{Blend[{Yellow, Green},
Rescale[#[[1, 1]], minmax]], #} & /@ spheres, axes}, Boxed -> False]


• This is not what I meant. Those are MWE just for visualization of the idea. Green and yellow states are just the reference states. All intermediate states should be colored through the gradient color of those two. Commented Oct 13, 2021 at 22:51
• @ATomek, well, in that case, both of them should be green, since their $C_2$ symmetry axes have the same $x$ projection. Is that what you want? If not, please provide more details about your calculation of $C_2$ axis. Commented Oct 13, 2021 at 23:36