Exploring Analyic Geometry with Mathematica®

Home Contents Commands Packages Explorations Reference
Tour Lines Circles Conics Analysis Tangents

D2DSketch2D

The package D2DSketch2D provides the Sketch2D command which is the basic command for plotting Descarta2D objects.

Initialization

BeginPackage["D2DSketch2D`", {"D2DExpressions2D`", "D2DMaster2D`"}];

D2DSketch2D::usage=
   "D2DSketch2D is a package providing sketching functions.";

AskCurveLength2D::usage=
   "AskCurveLength2D[ ] returns the value of the option CurveLength2D for the Sketch2D function (the approximate sketched length of an unbounded curve).";

CurveLength2D::usage=
   "CurveLength2D->n is an option for the Sketch2D function to specify the approximate sketched length of an unbounded curve.";

CurveLimits2D::usage=
   "CurveLimits2D[{x,y},curve] returns a list of two parameter values, {-t,t}, so that the distance the point on the unbounded curve at the parameter 't' is a distance CurveLength2D/2 from the given coordinates.";

IsDisplay2D::usage=
   "IsDisplay2D[object] returns 'True' if the object can be displayed.";

MakePrimitives2D::usage=
   "MakePrimitives2D[object,{t1,t2}] returns a list of graphics primitives between a pair of parameters for a parametrically defined curve.";

SetDisplay2D::usage=
   "SetDisplay2D[objPatt,objPrim] modifies the Display command to allow plotting of a new object.";

Sketch2D::usage=
   "Sketch2D[objList,opts] sketches a list of geometric objects.";

Begin["`Private`"];

Utilities

Filter Options

The private function FilterOptions$2D filters a list of options and provides a Sequence of valid options for the specified command.

FilterOptions$2D[command_Symbol,opts___] :=
   Module[{keywords = First /@ Options[command]},
      Sequence @@ Select[{opts},MemberQ[keywords,First[#]]&] ];

Plotting

Set Display

Format: SetDisplay2D[objPatt,objPrim]
Modifies the Mathematica Display command to enable plotting of a new object.  The argument objPatt is a pattern which matches the standard form of the object used in Descarta2D; the argument objPrim provides the commands that generate the primitives required to plot the object.

"D2DSketch2D_1.gif"

Display Query

Format:  IsDisplay2D[object]
Returns True if the object can be displayed and has parameters that can be evaluated to real numbers; otherwise, returns False.  The function SetDisplay2D, above, provides the implementation of IsDisplay2D for each object after its display graphics are defined.

IsDisplay2D[___] := False;

Curve Length

Format: CurveLength2D->n
The option CurveLength2D of the Sketch2D command specifies the plotted length of an infinite curve and is measured from the midpoint to one of the plotted end points of the curve.

Sketch2D::invalidLength=
   "Option CurveLength2D->`1` is invalid; 'CurveLength2D' must be positive; the current value of CurveLength2D->`2` will be retained.";

protected=Unprotect[SetOptions];
SetOptions[Sketch2D,opts1___,CurveLength2D->n_,opts2___] :=
   Message[Sketch2D::invalidLength,n,AskCurveLength2D[ ]] /;
(IsZeroOrNegative2D[n] || !IsReal2D[n]);
Protect[Evaluate[protected]];

Format: AskCurveLength2D[ ]
Returns the value of the Sketch2D command CurveLength2D option.

AskCurveLength2D[ ] := Options[Sketch2D,CurveLength2D][[1,2]];

Curve Parameter Limits

Format: CurveLimits2D[{x,y},curve]
Returns a list of two parameter values {-t,t} on an unbounded curve such that the points at the parameter values on the curve are at a distance CurveLength2D/2 from the given base point coordinates.  This is a numerical function used to support plotting, and, therefore, requires numerical arguments.

CurveLimits2D[p0:{x0_,y0_},crv_?IsValid2D] :=
   Module[{xt,yt,t,eqn,root},
      {xt,yt}=crv[t];
      eqn=Sqrt[(xt-x0)^2+(yt-y0)^2]==AskCurveLength2D[]/2;
      root=FindRoot[Evaluate[eqn],{t,1}];
      {-t,t} /. root[[1]] ] /;
IsNumeric2D[{p0,crv},CurveLimits2D];

Make Graphics Primitives

Format: MakePrimitives2D[curve,{"D2DSketch2D_2.gif","D2DSketch2D_3.gif"}]
Provides graphics primitives for a parametrically defined curve between two parameters.

MakePrimitives2D[crv_?IsValid2D,{t1_?IsScalar2D,t2_?IsScalar2D}] :=
   Module[{saveMsg,t,parPlot},
      saveMsg=Head[ParametricPlot::ppcom];Off[ParametricPlot::ppcom];
      parPlot=ParametricPlot[crv[t] //Evaluate,{t,t1,t2}];
      parPlot=parPlot[[1,1,3,2]];
      If[saveMsg===String,On[ParametricPlot::ppcom]];
      parPlot ];

Sketch

Format: Sketch2D[objList,opts]
Plots a list of Descarta2D objects.  The options may be any options supported by the Mathematica Graphics command.  The list is flattened before it is plotted.

Sketch2D::noObj="No valid objects to sketch.";

Sketch2D::notReal=
   "<`1`> object(s) cannot be sketched.";

Options[Sketch2D] =
   {Axes->True,
    Frame->True,
    AspectRatio->Automatic,
    PlotRange->Automatic,
    CurveLength2D->10};

Sketch2D[obj_List,opts___?OptionQ] :=
   Module[{sketchOptsList,inputOptsList,allOptsList,
           grOptsSequence,realObj,n,grafix},
      sketchOptsList=Options[Sketch2D];
      inputOptsList=Flatten[{opts}];
      SetOptions[Sketch2D,
                 FilterOptions$2D[Sketch2D,
                                  Sequence @@ inputOptsList]];
      allOptsList=Flatten[Join[inputOptsList,sketchOptsList]];
      grOptsSequence=FilterOptions$2D[Graphics, Sequence @@ allOptsList];
      realObj=Select[Flatten[obj],IsDisplay2D] //N;
      If[(n=Length[Flatten[obj]]-Length[realObj])>0,
         Message[Sketch2D::notReal,n]];
      grafix=If[Length[realObj]>0,
                Show[Graphics[realObj,grOptsSequence]],
                Message[Sketch2D::noObj];Null];
      SetOptions[Sketch2D,Sequence @@ sketchOptsList];
      grafix ];

Epilogue

End[ ]; (* end of "`Private" *)
EndPackage[ ]; (* end of "D2DSketch2D`" *)


Copyright © 1999-2007 Donald L. Vossler, Descarta2D Publishing
www.Descarta2D.com