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


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

ListVectorPlot[ ] absolute, definite vector length

Started byroby <roby.nowak@gmail.com>
First post2013-08-09 05:47 +0000
Last post2013-08-13 07:43 +0000
Articles 2 — 1 participant

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


Contents

  ListVectorPlot[ ] absolute, definite vector length roby <roby.nowak@gmail.com> - 2013-08-09 05:47 +0000
    Re: ListVectorPlot[ ] absolute, definite vector length roby <roby.nowak@gmail.com> - 2013-08-13 07:43 +0000

#15290 — ListVectorPlot[ ] absolute, definite vector length

Fromroby <roby.nowak@gmail.com>
Date2013-08-09 05:47 +0000
SubjectListVectorPlot[ ] absolute, definite vector length
Message-ID<ku1vor$gph$1@smc.vnet.net>
Dear Group,

is it possible to plot vectors of definite length using ListVectorPlot ?

I am trying to plot vectors starting from specified (grid) points.
I would like that the vectors would be drawn exact with their length's relative to the units of the given gridpoints.

To do so I use VectorPoints -> All to get only the vectors in the data (no intermediate interpolated vectors)
and VectorStyle -> "LeftArrow" to start the vectortails from the grid points.


What is further neeeded is an absolut VectorScale (not relative to the plot).

The Example below draws Vectors with a length of about 0.41 I would like the length's to be eact 1.0 is this in general possible with ListVectorPlot?

 
ListVectorPlot[Table[{{x, y}, {1, 0}}, {x, -2, 2, 1}, {y, -2, 2, 1}], 
 VectorPoints -> All, VectorStyle -> ("Left" <> "Arrow"), 
 PlotRangePadding -> 1]

Regards Robert

[toc] | [next] | [standalone]


#15299

Fromroby <roby.nowak@gmail.com>
Date2013-08-13 07:43 +0000
Message-ID<kuco3h$a2n$1@smc.vnet.net>
In reply to#15290
Am Freitag, 9. August 2013 07:47:07 UTC+2 schrieb roby:
> Dear Group,

> is it possible to plot vectors of definite length using ListVectorPlot ?
> 


Hi Bob & group,
thank you for yout hint.

I tried to generalize the whole procedure.
I rewrote a special version of ListVectorPlot and called it ListVectorP.
ListVectorP takes (almost) the same Options as does ListVectorPlot and adds the Option AbsolutVectorScale->s where s determines the vectorlength relative to the grid of base points.

If the new Option is omitted or set to None (AbsolutVectorScale->None) the result is the default behaviour of ListVectorPlot.

Things work fine so far.

But now I would like to name my new version just equal to the built in ListVectorPlot.
I tryed this by Unprotect[ListVectorPlot] and redefining it such that it also takes the new Option.
But when trying to evaluate my version of ListVectorPlot the system complains:
"ListVectorPlot::optx: Unknown Option AbsolutVectorScale in Options[ListVectorPlot]"


"Definition for ListVectorP"
************************************

Options[ListVectorP] = 
  Prepend[Options[ListVectorPlot], AbsoultVectorScale -> None];
ListVectorP[array_?(ArrayDepth@# == 4 &), opt : OptionsPattern[]] := 
 Module[{rx, ry},
   rx = Max@array[[All, All, 1, 1]] - Min@array[[All, All, 1, 1]];
   ry = Max@array[[All, All, 1, 2]] - Min@array[[All, All, 1, 2]]; 
   ListVectorPlot[array, 
    VectorScale -> 
     N[OptionValue[AbsoultVectorScale]/Sqrt[rx^2 + ry^2]],
    FilterRules[{opt}, Except[AbsoultVectorScale]]
    ]] /; OptionValue[ListVectorP, AbsoultVectorScale] =!= None
ListVectorP[array_, opt : OptionsPattern[]] := Module[{},
   ListVectorPlot[array, 
    FilterRules[{opt}, Except[AbsoultVectorScale]]]
   ] /; OptionValue[ListVectorP, AbsoultVectorScale] === None


"data"
************************************

data = Table[{{x, y}, {1, 0}}, {x, -4, 4, 2}, {y, -2, 2, 1}];


"test working fine"
************************************

ListVectorP[data, VectorPoints -> All, AbsoultVectorScale -> 1]
% // Cases[#, Arrow[l___] :> l, \[Infinity]] & // 
   Subtract @@ # & /@ # & // Norm /@ # & // Rationalize



"redefinition for ListVectorPlot"
************************************

Unprotect[ListVectorPlot]; 
Options[ListVectorPlot] = 
 Prepend[Options[ListVectorPlot], AbsoultVectorScale -> None];
ListVectorPlot[array_, opt : OptionsPattern[]] := Module[{},
   ListVectorP[array, opt]
   ] /; OptionValue[ListVectorPlot, AbsoultVectorScale] =!= None
Protect[ListVectorPlot];



"test failing"
************************************

ListVectorPlot[data, VectorPoints -> All, AbsoultVectorScale -> 1]
% // Cases[#, Arrow[l___] :> l, \[Infinity]] & // 
   Subtract @@ # & /@ # & // Norm /@ # & // Rationalize


"ListVectorPlot::optx: Unknown Option AbsolutVectorScale in Options[ListVectorPlot]"


Any hints how to manage this ?

Is it in general possible to redefine mathematica builtins but still call the original function from within the redefinition ?
In particular I would like to overload a builtin (distinguished by an additional Option) and keep the possibility to call the original (distinguished by omitting the additional Option)


Regards Robert

[toc] | [prev] | [standalone]


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


csiph-web