Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: ListVectorPlot[ ] absolute, definite vector length
Replies: 1   Last Post: Aug 13, 2013 3:43 AM

 Messages: [ Previous | Next ]
 roby.nowak@gmail.com Posts: 87 Registered: 5/8/07
Re: ListVectorPlot[ ] absolute, definite vector length
Posted: Aug 13, 2013 3:43 AM

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

Date Subject Author
8/9/13 roby.nowak@gmail.com
8/13/13 roby.nowak@gmail.com