Group Abstract Group Abstract

Message Boards Message Boards

Varying color parametrically along a curve?

Posted 10 years ago

I'm trying to vary the color of a ParametricPlot along the curve according to a function of t, for experimental purposes and to make cool designs. I've tried:

ParametricPlot[{Cos[4 t] - Cos[0.5 t] + Sin[t], Sin[3 t] - Sin[2 t]}, {t, 0, 4 Pi}, PlotStyle -> Thickness[0.01], 
 ColorFunction -> Function[{t}, ColorData["DarkRainbow"][2.49 Sin[t] - Sin[0.33 t]]]]

enter image description here

and

ParametricPlot[{Cos[4 t] - Cos[0.5 t] + Sin[t], Sin[3 t] - Sin[2 t]}, {t, 0, 4 Pi}, PlotStyle -> Thickness[0.01], ColorFunction -> Function[{t}, Hue[0.1 Sin[0.3 t] - Sin[2 t]]]]

enter image description here

These attempts fail because the color is constant for x (I want the color to vary with an arbitrary function of t, which should make the color different at different x values), and because the color only goes through the spectrum once. Ideally, the solution would utilize one of the ColorData schemes (i.e. "Pastels") such that the curve would oscillate in that color scheme multiple times along the curve according to a function f[t].

Thanks in advance, sorry if it's a newbie question.

POSTED BY: Bryan Lettner
5 Replies

The problem is that ColorData["Pastel"] wants the argument between 0 and 1. You can rescale your curvature, though:

x = Sin[t] + 2/3 Sin[3 t];
y = Cos[t] + 2/3 Cos[3 t];
curvature[t_] =
  (D[x, t] D[y, {t, 2}] - 
     D[y, t] D[x, {t, 2}])/(D[x, t]^2 + D[y, t]^2)^(3/2);
ParametricPlot[{Sin[t] + 2/3 Sin[3 t], Cos[t] + 2/3 Cos[3 t]}, {t, 0, 
  2 Pi}, ColorFunction -> 
  Function[{x, y, u}, 
   ColorData["Pastel"][
    Rescale[curvature[u], {curvature[Pi/2], curvature[0]}, {0, 1}]]], 
 ColorFunctionScaling -> False]
POSTED BY: Gianluca Gorni
Posted 9 years ago

works great thank you!

enter image description here

POSTED BY: Bryan Lettner
Posted 1 year ago

Is there any way to show that curvature in bar legend?

POSTED BY: Updating Name
Posted 9 years ago
POSTED BY: Bryan Lettner

You need to use the 3rd argument in this case (go to the help of ColorFunction there it will be shown which parameters and in what order are passed on to ColorFunction. ParametricPlot in this case gets x,y,t values...

ParametricPlot[{Cos[4 t] - Cos[0.5 t] + Sin[t], Sin[3 t] - Sin[2 t]}, {t, 0, 4 Pi}, PlotStyle -> Thickness[0.01], ColorFunction -> Function[{x, y, t}, Hue[0.1 Sin[0.3 t] - Sin[2 t]]]]
POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard