MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Line clipping function

  • To: mathgroup at
  • Subject: [mg35384] Line clipping function
  • From: Selwyn Hollis <slhollis at>
  • Date: Wed, 10 Jul 2002 02:20:18 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

This is a follow-up to a recent thread regarding PlotVectorField. To
make a long story short, I was trying to superimpose numerically
generated curves (from ListPlot) over a vector field (from
PlotVectorfield). At first I used PlotRange to get the rectangle I
wanted, but that caused problems with the vector field. Anyway, it
turned out that the best remedy was to clip the generated data so that 
the curves would not spill out of the rectangle. With the much 
appreciated help of Herr Hartmut Wolf, I ended up using the following 
functions to do the line clipping. I thought it worthwhile to present 
these "for the record".



pull[z_, end_, xory_, k_, bounds_]:= With[

clip[zIn_, bounds_]:= Module[{z=zIn},
If[z[[end,1]]<bounds[[1,1]], pull[z,end,1,1,bounds],
If[z[[end,1]]>bounds[[1,-1]], pull[z,end,1,-1,bounds]]];
If[z[[end,-1]]<bounds[[-1,1]], pull[z,end,-1,1,bounds],
If[z[[end,-1]]>bounds[[-1,-1]], pull[z,end,-1,-1,bounds]]];],
{1,-1}]; z];


datapts = Join[{{Random[Real,{-1,0}],Random[Real,{-1,0}]}},
    Table[{0.1*i, Random[Real,{0,1}]}, {i,1,9}],
    {{Random[Real,{1,2}], Random[Real,{1,2}]}}]

ListPlot[datapts, PlotJoined -> True, PlotRange -> All];

clippeddatapts= clip[datapts, {{0, 1}, {0, 1}}]

ListPlot[clippeddatapts, PlotJoined -> True,
     PlotRange -> All];


Selwyn Hollis

slhollis at

  • Prev by Date: Re: downloading notebooks
  • Next by Date: RE: Sovling integrals: non-algebraic???
  • Previous by thread: RE: Re: RE: RE: Corrupted Files & Version 4.2 Problems
  • Next by thread: SafeFileOpen->IgnoreCache