Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.