Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7797 > unrolled thread

Plotting a line with color changing as a function of position

Started by"Eric Michielssen" <emichiel@eecs.umich.edu>
First post2012-01-14 07:58 +0000
Last post2012-01-14 22:20 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Plotting a line with color changing as a function of position "Eric Michielssen" <emichiel@eecs.umich.edu> - 2012-01-14 07:58 +0000
    Re: Plotting a line with color changing as a function of position Dan <dflatin@rcn.com> - 2012-01-14 22:20 +0000

#7797 — Plotting a line with color changing as a function of position

From"Eric Michielssen" <emichiel@eecs.umich.edu>
Date2012-01-14 07:58 +0000
SubjectPlotting a line with color changing as a function of position
Message-ID<jercj4$1c7$1@smc.vnet.net>
Hello,

I would like to plot/draw a line between two points p1= (x1,y1} and
p2={x2,y2}, and I would like the line color (preferred) or thickness or dash
density  to be reflective of a known function f(d) that measures the
distance d from p1 to the point on the line.

Say p1={x1,y1}={0.,0.}, p2={10.,10}, and f[d_]:=Cos[d].

Is this possible?

Thanks!
Eric

Eric Michielssen


[toc] | [next] | [standalone]


#7840

FromDan <dflatin@rcn.com>
Date2012-01-14 22:20 +0000
Message-ID<jesv3u$co3$1@smc.vnet.net>
In reply to#7797
It turns out that there is a capability that will do just what you
want, ColorFunction. Look it up in the online help for more
information. Here is an example:

Module[{x1 = 0, y1 = 0, x2 = 10, y2 = 10, m, b},
  m = (y2 - y1)/(x2 - x1);
  b = (x2*y1 - x1*y2)/(x2 - x1);
  Plot[m*x + b, {x, -1, 11},
    ColorFunction -> Function[{x, y}, Hue[Cos[Norm[{x, y} - {x1,
y1}]]]],
    ColorFunctionScaling -> False,
    PlotStyle -> Directive@{Thickness[0.01]}
  ]
]

In order to vary thickness or dash interval I think you will have to
build the plot through construction. Thickness could be managed with
the Filling option for Plot using two curves.


On Jan 14, 2:58 am, "Eric Michielssen" <emich...@eecs.umich.edu>
wrote:
> Hello,
>
> I would like to plot/draw a line between two points p1= (x1,y1} and
> p2={x2,y2}, and I would like the line color (preferred) or thickness or dash
> density  to be reflective of a known function f(d) that measures the
> distance d from p1 to the point on the line.
>
> Say p1={x1,y1}={0.,0.}, p2={10.,10}, and f[d_]:=Cos[d].
>
> Is this possible?
>
> Thanks!
> Eric
>
> Eric Michielssen

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web