2
$\begingroup$

I am trying to represent 3-dimensional vectors in a 3-dimensional space. In my field, there is a common color coding (color wheel) as in the picture.

For (vx,vy,vz) vectors: (0,0,1) is white, (0,0,-1) is black, (vx,vy,0) is a Hue coloring. As vz changes from -1 to 1, we may need to adjust the saturation and brightness for Hue function, but I am stuck how to show it. How can I make a VectorColorFunction for ListVectorPlot3D with such color-wheel?

enter image description here enter image description here

For example, the third image is a failed one with

g = VectorPlot3D[{x, y, z}, {x, -6, 6}, {y, -6, 6}, {z, -6, 6}, 
  VectorStyle -> "Arrow3D", VectorPoints -> 15, 
  VectorColorFunction -> 
   Function[{x, y, z, vx, vy, vz, n}, 
    ColorData["Rainbow"][Arg[vx + I vy]]], AxesLabel -> {x, y, z}, 
  VectorScale -> {0.15, Scaled[0.5]}, 
  RegionFunction -> Function[{x, y, z}, 4^2 < x^2 + y^2 + z^2 < 5^2]]

: enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$

First let's define a helper function which maps from unit vectors to our desired colors:

HSLFromUnitVector = Function[{x, y, z}, 
  Hue[Mod[Arg[x + I*y]/(2 \[Pi]), 1], Min[1, 1 - z], (1 + z)/2]
]

I named it HSL... based on the HSL color space which it shares a close resemblance with. It's quite certainly not a 100% accurate implementation of it, but it should give you the general idea and, with a bit of time could be perfected if needed.

Then we can use it to get the coloring in the vector field plot:

VectorPlot3D[{x, y, z}, {x, -6, 6}, {y, -6, 6}, {z, -6, 6}, 
  VectorStyle -> "Arrow3D", VectorPoints -> 15, 
  VectorColorFunction -> Function[{x, y, z, vx, vy, vz, n}, 
    HSLFromUnitVector @@ Normalize[{vx, vy, vz}]
  ], 
  VectorColorFunctionScaling -> False, AxesLabel -> {x, y, z}, 
  VectorScale -> {0.15, Scaled[0.5]}, 
  RegionFunction -> Function[{x, y, z}, 4^2 < x^2 + y^2 + z^2 < 5^2]
]

HSL color vector field plot

Notice the added VectorColorFuncctionScaling->False which makes sure that our VctorColorFunction gets the original {vx,vy,vz} values and not rescaled values, which would sabotage our color scheme.

The effect is easier to see on a sphere:

SphericalPlot3D[1, {\[Theta], 0, \[Pi]}, {\[Phi], -\[Pi], \[Pi]}, 
  ColorFunctionScaling -> False, 
  ColorFunction -> Function[{x, y, z, u, v}, HSLFromUnitVector @@ {x, y, z}]
]

HSL coloring on sphere

$\endgroup$
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.