[Date Index]
[Thread Index]
[Author Index]
Re: operator overloading with UpValues (eg, for shifting graphics)
*To*: mathgroup at smc.vnet.net
*Subject*: [mg13642] Re: operator overloading with UpValues (eg, for shifting graphics)
*From*: Paul Abbott <paul at physics.uwa.edu.au>
*Date*: Fri, 07 Aug 1998 18:37:26 +0800
*Organization*: University of Western Australia
*References*: <6qbqkd$a67@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
Daniel Reeves wrote:
> I thought it would be nice to shift some graphics by just adding an x-y
> pair. It seemed like this sort of thing should do that:
>
> Unprotect[Line];
> Line /: Line[pts_] + {x_,y_} := Line[pts+{x,y}] Protect[Line];
>
> But it doesn't. The UpValue for Graphics doesn't get used. This does
> work:
>
> Line /: Line[pts_] + shift[x_,y_] := Line[pts+{x,y}]
>
> but then I might as well just do this:
>
> shift[Line[pts_],{x_,y_}] := Line[pts+{x,y}]
>
> The idea is to be able to just say Line[...] + {x,y} and get a shifted
> Line.
>
> Does anyone know a way to do that?
> Also, if/why Mathematica is doing "the right thing" in defying my
> expectations in the first example. Ie, should the Listable-ness of
> Plus have precedence over my UpValue for Line?
I think you'll find that all these questions (and many more) are
answered in the excellent "Mathematica Graphics: Techniques and
Applications" by Tom Wickham-Jones. Incidentally, the packages for
this book are available from MathSource:
http://www.mathsource.com/cgi-bin/MathSource/Enhancements/Graphics/3D/0208-976
BTW, a nice simple example of Affine transformations on graphics was
given in The Mathematica Journal 4(3):38-39:
An arbitrary affine transformation (that is, a composition of
translation, rotation, and scaling) of a vector {x,y} in the plane can
be be written in matrix notation as m.{x,y} + c, where m is a 2x2
matrix (generating rotation and scaling) and c is a constant
(translation) vector.
Here is a simple procedure that applies affine transformations to
two-dimensional graphics:
Affine[plot_Graphics,m_?MatrixQ,c_?VectorQ]:=
Show[plot/.{x_?NumberQ,y_?NumberQ} -> m.{x,y}+c]
Commencing with a basic plot:
SinPlot=Plot[Sin[x],{x,0,6 Pi}];
one can rotate it about the z-axis by 90 degrees and then mirror it in
the y-axis:
Affine[SinPlot,{{0,1},{1,0}},{0,0}];
or display a more complicated combination of rotation, scaling, and
translation:
Affine[SinPlot,{{1,0},{1,3}},{-1,-2}];
> "This isn't right. This isn't even wrong."
> -- Wolfgang Pauli, on a paper submitted by a physicist colleague
Only a physicist would have such a sig ...
Cheers,
Paul
____________________________________________________________________
Paul Abbott Phone: +61-8-9380-2734
Department of Physics Fax: +61-8-9380-1014
The University of Western Australia Nedlands WA 6907
mailto:paul at physics.uwa.edu.au AUSTRALIA
http://www.physics.uwa.edu.au/~paul
God IS a weakly left-handed dice player
____________________________________________________________________
Prev by Date:
**Re: Can't take a value from an InterpolatingFunction.**
Next by Date:
**Re: New Notebook Select or Evaluation Command?**
Previous by thread:
**Re: operator overloading with UpValues (eg, for shifting graphics)**
Next by thread:
**Precision & InputForm perils**
| |