Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: operator overloading with UpValues (eg, for shifting graphics)

  • To: mathgroup at
  • Subject: [mg13642] Re: operator overloading with UpValues (eg, for shifting graphics)
  • From: Paul Abbott <paul at>
  • Date: Fri, 07 Aug 1998 18:37:26 +0800
  • Organization: University of Western Australia
  • References: <6qbqkd$>
  • Sender: owner-wri-mathgroup at

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:

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:

		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:


or display a more complicated combination of rotation, scaling, and


 > "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 ...


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  AUSTRALIA              

            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