Re: ListVectorPlot[ ] absolute, definite vector length
- To: mathgroup at smc.vnet.net
- Subject: [mg131502] Re: ListVectorPlot[ ] absolute, definite vector length
- From: roby <roby.nowak at gmail.com>
- Date: Tue, 13 Aug 2013 03:59:17 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
- References: <ku1vor$gph$1@smc.vnet.net>
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