Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: Problems creating a package file

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77085] Re: Problems creating a package file
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sun, 3 Jun 2007 06:08:02 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <f3r92a$sgg$1@smc.vnet.net>

chuck009 wrote:
> Hello everyone.
> 
> I'd like to create my own package of some plotting routines but I'm having problems getting routines to work within the package.  I suspect my context is not right.  I created PlotRoutines.m via File/SaveAsSpecial/PackageFormat and placed it in a PlotUtilities directory within the ExtraPackages directory:
> 
> (*
>    PlotRoutines.m
> 
>     Package for plot routines *)
> 
> BeginPackage["PlotUtilities`PlotRoutines`"];
> 
> TagPoints::usage = "Tag Polygons with '1' which satisfy passed inequality"
> 
> Begin["`Private`"];
> 
> TagPoints[inequality_][p_] := 
>     Block[{x, y, z}, {x, y, z} = p; If[inequality, {p, 1}],{p, 2}]];
       ^^^^^            ^^^^^^^^^^^^^                       ^
        (1)                   (2)                          (3)

(1) -> Block is not needed. Should use Module anyway.
(2) -> Useless assignment since x, y, and z are not used.
(3) -> Extraneous square bracket: end the If statement here.

> 
> End[];
> 
> EndPackage[];
> 
> It takes a Graphics3D object and tests each coordinate of each Polygon matching the search criteria specified in the inequality and is suppose to append either a 1 or a 2 to each coordinate.  I'd call it as:
> 
> 
> << PlotUtilities`PlotRoutines`
> 
> p1=Graphics3D[Plot3D[some plot here]]
> 
> p1 /. Polygon[pts_] :> Polygon[TagPoints[z â?¥ 2] /@ pts];
                                            ^^    ^^
                                            (4)   (5)

(4) -> z has no value here.
(5) -> The second argument of TagPoints is missing ==> TagPoints is 
never executed.


> However it doesn't update the polygons and I know it works when I create the TagPoints function within the notebook.   Also, I noticed when I first create the *.m file, Mathematica adds (*  *) to the file which I remove.  Not sure what to do.  Can someone help me?
> 

You could write your package as suggested below.

(** Beginning of the file **)

(*PlotRoutines.m Package for plot routines*)

BeginPackage["PlotUtilities`PlotRoutines`"];

TagPoints::usage = "Tag Polygons with '1' which satisfy passed inequality"

Begin["`Private`"];

TagPoints[True][p_] := {p, 1}
TagPoints[False][p_] := {p, 2}

End[];

EndPackage[];
(* End of the file *)

Save the above in a .m file. Now we can test it as in the following:

In[1]:=
<< "PlotUtilities`PlotRoutines`"

In[2]:=
$ContextPath

Out[2]=
{"PlotUtilities`PlotRoutines`", "Global`", "System`"}

In[3]:=
Information["TagPoints", LongForm -> False]

"Tag Polygons with '1' which satisfy passed inequality"

In[4]:=
p1 = Graphics3D[Plot3D[x*Sin[y] + y*Cos[x],
      {x, 0, 2*Pi}, {y, 0, Pi}]];
p1 /. Polygon[pts_] :> Polygon[
      (TagPoints[#1[[3]] >= 2][#1] & ) /@ pts];

In[6]:=
(Short[#1, 6] & )[FullForm[%]]

Out[6]//Short=
Graphics3D[List[Polygon[List[List[List[0.`,0.1308996938995747`,0.\
1308996938995747`],2],List[List[0.`,0.`,0.`],2],\[LeftSkeleton]1\
\[RightSkeleton],List[List[0.2617993877991494`,0.1308996938995747`,0.\
16061107220589643`],2]]],\[LeftSkeleton]575\[RightSkeleton]]\
,List[Rule[PlotRange,Automatic],\[LeftSkeleton]30\[RightSkeleton],\
\[LeftSkeleton]1\[RightSkeleton]]]

Regards,
Jean-Marc


  • Prev by Date: Re: Using Part
  • Next by Date: Re: Problem with Mathematica 6
  • Previous by thread: Problems creating a package file
  • Next by thread: Re: Problems creating a package file