1
$\begingroup$

I want to use Hue function for different colours with the argument being a function, i.e.,

Hue[f[i,j]]

Now, f[i,j] in my case can take negative values. The range of my function is [-2,2] (which can be rescaled to [-1,1] if necessary, by dividing the function by 2). The problem is that Hue automatically rescales its argument to put it into the range of [0,1). This is a problem for me as it will then show the same colour when my function is either -1 or 0 or 1, for example. The actual figure I want to work on can be generated by the following code:

Clear["Global`*"]; 
n := 10; 
angles = Table[RandomReal[{-Pi, Pi}], {i, n}, {j, n}]; 
f[here_, down_, right_] := Cos[down - here] + Cos[right - here] 
g[list_, {i_, j_}] := Module[{m, n}, {m, n} = Dimensions[list]; {list[[i, j]], 
    If[i != m, list[[i + 1, j]], -list[[1, j]]], 
      If[j != n, list[[i, j + 1]], -list[[i, 1]]]}] 
GraphicsGrid[ MapIndexed[ Graphics[{LightGray, Circle[{0, 0}, 1], 
    Hue[Rescale[f @@ g[angles, #2], {-2, 2}, {-1, 1}]], Thin, 
      Arrowheads[Small], Arrow[{{0, 0}, {Cos[#], Sin[#]}}]}] &, angles, {2}]]
$\endgroup$
2
  • 4
    $\begingroup$ Why you dont you use Rescale like Rescale[..,{-2,2},{0,1}]? Hue will use the values of its first argument cyclically if they are outside the range $(0,1)$. $\endgroup$
    – Spawn1701D
    Apr 25, 2013 at 21:24
  • 1
    $\begingroup$ To rephrase @Spawn's comment: Hue[] is a periodic function with period $1$, with the colors determined by the usual color wheel. Use Rescale[] if you want to use Hue[] for your desired range, with the caveat that due to the periodicity, Hue[0] and Hue[1] are both Red (RGBColor[1, 0, 0]). $\endgroup$ Apr 26, 2013 at 5:12

1 Answer 1

2
$\begingroup$

Hue does not rescale its argument, but it is a periodic function, equivalent to Hue[Mod[x, 1]]. What you need is rescaling: Rescale[f[...], {-2,2}].

$\endgroup$

Your Answer

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

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