[Date Index]
[Thread Index]
[Author Index]
RE: Varying color in ParametricPlot
*To*: mathgroup at smc.vnet.net
*Subject*: [mg35055] RE: [mg35023] Varying color in ParametricPlot
*From*: "David Park" <djmp at earthlink.net>
*Date*: Thu, 20 Jun 2002 23:55:02 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
2D or 3D? Let's assume 2D. Also I am just going to work with one sample
function. It is easy to do the same thing for two.
Here is a sample curve.
curve[t_] := {1 + Cos[t], Sin[t]Cos[t]}
I don't think there is a simple method to color the curve according to t by
directly using ParametricPlot. You can only set the overall color for the
curve. You could extract the points and work with them, but Mathematica uses
an adaptive procedure to pick the points and it is not always easy to work
back to t. Therefore I would abandon ParametricPlot and just make a table of
colored line segments as follows.
segments =
With[
{delta = 2Pi/100},
Table[{Hue[t/(2Pi)], Line[{curve[t - delta], curve[t]}]}, {t, delta,
2Pi, delta}]];
Show[
Graphics[
{segments}],
AspectRatio -> Automatic];
On the other hand, you can color parametric curves using Parametric3D. Here
is the same curve in 3D, adding a color function to the parametrization.
curve3d[t_] := {1 + Cos[t], Sin[t]Cos[t], 0, Hue[t/(2Pi)]}
plot1 = ParametricPlot3D[Evaluate[curve3d[t]], {t, 0, 2Pi}];
ParametricPlot3D, by the way, does not use adaptive point sampling. Nor does
it produce a single line, but a whole series of individual line segments.
So, the second method is to make the 3D plot above and then convert the
primitives to a 2D plot.
Show[
Graphics[
{First[plot1] /. {x_, y_, z_} -> {x, y}}],
AspectRatio -> Automatic];
But this all raises the question: why do you want to color the curve
according to t? Other than making a pretty curve, the only reason could be
to indicate the value of t. We might be more interested in putting labeled
tick marks on the curve.
The simplest method is to combine the curve with a set of evenly spaced
points, and then judiciously label some of the points.
plot2d =
ParametricPlot[Evaluate[curve[t]], {t, 0, 2\[Pi]},
DisplayFunction -> Identity];
Show[
Graphics[
{First[plot2d],
AbsolutePointSize[4],
Table[{Point[curve[t]]}, {t, 0, 2Pi, 2Pi/32}],
Table[{Point[curve[t]], Text[t, curve[t], {0, 1.3}]}, {t, 2Pi/8,
2Pi,
2Pi/4}]}],
AspectRatio -> Automatic,
PlotRange -> All,
ImageSize -> 500];
If we really want tick marks perpendicular to the curve, we can use a little
differential geometry. To obtain a unit length vector, perpendicular to the
curve at each point, we use...
curve'[t] // Simplify
{-Sin[t], Cos[2 t]}
Reverse[curve'[t]]{-1, 1} // Simplify
perp[t_] = %/Sqrt[%.%] // Simplify
{-Cos[2 t], -Sin[t]}
{-(Cos[2*t]/Sqrt[Cos[2*t]^2 + Sin[t]^2]), -(Sin[t]/Sqrt[Cos[2*t]^2 +
Sin[t]^2])}
We can then plot the ticks and labels, coloring the ticks in red, and
displacing the labels from one end of the ticks.
Needs["Graphics`Colors`"]
Show[
Graphics[
{First[plot2d],
Table[
{Red, Line[{curve[t] - perp[t]/60, curve[t] + perp[t]/60}],
Black,
Text[NumberForm[N[t], {3, 2}], curve[t] + perp[t]/15, {0, 0},
TextStyle -> {FontSize -> 10}]}, {t, 0, 2Pi - 2Pi/16,
2Pi/16}]}],
AspectRatio -> Automatic,
PlotRange -> All,
ImageSize -> 500];
This is probably the best way to indicate time along a curve.
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
> From: Student, T.U.E. [mailto:YourName at student.tue.nl]
To: mathgroup at smc.vnet.net
>
>
> What I would like to do, is the following:
>
> I have defined 2 functions x[t] and y[t] and I would like to plot them
> parametrically using ParametricPlot with a color that is also a
> function of
> t (something like Hue[t]).
>
> I haven't been able to figure this out using help in Mathematica. I have
> tried to use ColorOutput and PlotStyle but that doesn't seem to work. Does
> anyone have a solution to this problem.
>
Prev by Date:
**Re: Friendly Challenge 2: sort by column**
Next by Date:
**RE: Re: Friendly Challenge 2: sort by column**
Previous by thread:
**Re: Varying color in ParametricPlot**
Next by thread:
**Re: Varying color in ParametricPlot**
| |