Exploring Analyic Geometry with Mathematica® |
|||||
| Home | Contents | Commands | Packages | Explorations | Reference |
| Tour | Lines | Circles | Conics | Analysis | Tangents |
D2DTransform2D
The package D2DTransform2D provides the basic support for the transformations provided by Descarta2D (reflect, rotate, scale and translate). Each Descarta2D object provides specific support for the transformations using these basic capabilities.
Initialization
BeginPackage["D2DTransform2D`", {"D2DExpressions2D`", "D2DLine2D`", "D2DMaster2D`"}];
D2DTransform2D::usage=
"D2DTransform2D is a package providing transformations.";
Reflect2D::usage=
"Reflect2D[obj,line] reflects an object in a line; Reflect2D[objList,line] reflects a list of objects in a line; Reflect[eqn,{x,y},line] reflects an equation in variables 'x' and 'y' in a line.";
ReflectAngle2D::usage=
"ReflectAngle2D[theta,line] reflects an angle in a line.";
Rotate2D::usage=
"Rotate2D[obj,theta,{h,k}] rotates an object an angle 'theta' about a point with coordinates {h,k}; Rotate2D[objList,theta,{h,k}] rotates a list of objects; Rotate2D[eqn,{x,y},{h,k}] rotates an equation in variables 'x' and 'y'; if the {h,k} coordinates are omitted, the default is {0,0}.";
Scale2D::usage=
"Scale2D[obj,s,{h,k}] scales an object about coordinates {h,k} by scale factor 's'; Scale2D[objList,s,{h,k}] scales a list of objects; Scale2D[eqn,{x,y},{h,k}] scales an equation in variables 'x' and 'y'; if the center of scaling {h,k} is omitted, the default is {0,0}.";
Translate2D::usage=
"Translate2D[obj,{u,v}] translates an object delta distance {u,v}; Translate2D[objList,{u,v}] translates a list of objects; Translate2D[eqn,{x,y},{u,v}] translates an equation in variables 'x' and 'y'.";
Begin["`Private`"];
Queries
Transformable Query
The private function IsTransformable$2D returns True if an object or all the objects in a list are transformable; otherwise, returns False.
IsTransformable$2D[obj_List] :=
(And @@ Map[IsTransformableSingleLevel$2D[#]&,obj]) /;
Not[IsScalarPair2D[obj]];
IsTransformable$2D[obj_] := IsTransformableSingleLevel$2D[obj];
IsTransformableSingleLevel$2D[obj_] :=
(IsValid2D[obj] || IsScalarPair2D[obj]);
Reflect
Reflect Angle
Format: ReflectAngle2D[θ,line]
Reflects an angle in a line. This function is useful for reflecting objects that are defined by rotation angles.
ReflectAngle2D[theta_?IsScalar2D,Line2D[a_,b_,c_]] :=
2*ArcTan[b,-a]-theta;
Reflect Coordinates
Format: Reflect2D[{x,y},line]
Reflects a list of coordinates {x,y} in a line.
Reflect2D[{x_?IsScalar2D,y_?IsScalar2D},Line2D[a_,b_,c_]] :=
{x,y}-2*(a*x+b*y+c)*{a,b}/(a^2+b^2);
Reflect Equation
Format: Reflect2D[eqn,{x,y},line]
Reflects an equation in the variables x and y in a line.
Reflect2D[eqn_Equal,{x_?IsScalar2D,y_?IsScalar2D},Line2D[a_,b_,c_]] :=
eqn /. {x->((b^2-a^2)*x-2*a*b*y-2*a*c)/(a^2+b^2),
y->((a^2-b^2)*y-2*a*b*x-2*b*c)/(a^2+b^2)};
Reflect List
Format: Reflect2D[objList,line]
Reflects a list of {x,y} coordinates or objects.
Reflect2D[obj_List?IsTransformable$2D,L:Line2D[a_,b_,c_]] :=
Map[Reflect2D[#,L]&, obj] /;
Not[IsScalarPair2D[obj]];
Rotate
Rotate About Origin
Format: Rotate2D[object,θ]
Rotates an object by an angle θ about the origin.
Rotate2D[obj_?IsTransformable$2D,theta_?IsScalar2D] :=
Rotate2D[obj,theta,{0,0}];
Rotate Coordinates
Format: Rotate2D[coords,θ,coords]
Rotates a coordinate list {x,y} by an angle θ about a position specified by a coordinate list. If the third argument is omitted, it defaults to the origin.
Rotate2D[{x1_?IsScalar2D,y1_?IsScalar2D},theta_?IsScalar2D,
{h_?IsScalar2D,k_?IsScalar2D}] :=
{h+((x1-h)*Cos[theta]-(y1-k)*Sin[theta]),
k+((x1-h)*Sin[theta]+(y1-k)*Cos[theta])};
Rotate Equation
Format: Rotate2D[eqn,coords,θ,coords]
Rotates an equation in the variables x and y by an angle θ about a position given by coordinates.
Rotate2D[eqn_Equal,{x_?IsScalar2D,y_?IsScalar2D},theta_?IsScalar2D,
{h_?IsScalar2D,k_?IsScalar2D}] :=
eqn /. {x->h+(x-h)*Cos[theta]+(y-k)*Sin[theta],
y->k-(x-h)*Sin[theta]+(y-k)*Cos[theta]};
Rotate List
Format: Rotate2D[objList,θ,coords]
Rotates a list of {x,y} coordinates or objects by an angle θ about a position specified by a coordinate list. If the third argument is omitted, it defaults to the origin.
Rotate2D[obj_List?IsTransformable$2D,theta_?IsScalar2D,
{h_?IsScalar2D,k_?IsScalar2D}] :=
Map[Rotate2D[#,theta,{h,k}]&, obj] /;
Not[IsScalarPair2D[obj]];
Scale
Scale from Origin
Format: Scale2D[object,s]
Scales an object about the origin.
Scale2D[obj_?IsTransformable$2D,s_?IsScalar2D] :=
Scale2D[obj,s,{0,0}] /;
Not[IsZeroOrNegative2D[s]];
Scales Coordinates
Format: Scale2D[coords,s,coords]
Scales a coordinate list from a position given by coordinates. If the position is omitted, it defaults to the origin.
Scale2D[{x1_?IsScalar2D,y1_?IsScalar2D},s_?IsScalar2D,
{h_?IsScalar2D,k_?IsScalar2D}] :=
({h,k}+s*{x1-h,y1-k}) /;
Not[IsZeroOrNegative2D[s]];
Scale Equation
Format: Scale2D[eqn,{x,y},s,coords]
Scales an equation in the variables x and y from a position given by coordinates.
Scale2D[eqn_Equal,{x_?IsScalar2D,y_?IsScalar2D},s_?IsScalar2D,
{h_?IsScalar2D,k_?IsScalar2D}] :=
(eqn /. {x->h+(x-h)/s,y->k+(y-k)/s}) /;
Not[IsZeroOrNegative2D[s]];
Scale List
Format: Scale2D[objList,s,coords]
Scales a list of {x,y} coordinates or objects from a position given by coordinates. If the position is omitted, it defaults to the origin.
Scale2D[obj_List,s_?IsScalar2D,{h_?IsScalar2D,k_?IsScalar2D}] :=
Map[Scale2D[#,s,{h,k}]&, obj] /;
(Not[IsScalarPair2D[obj]] && Not[IsZeroOrNegative2D[s]]);
Invalid Scale
Returns $Failed when Scale2D is called with a non-positive scale, s.
Scale2D::invalidScale=
"The scale factor `1` is invalid; the scale factor must be positive.";
Scale2D[obj_?IsTransformable$2D,s_?IsScalar2D,___] :=
(Message[Scale2D::invalidScale,s];$Failed) /;
IsZeroOrNegative2D[s];
Translate
Translate Coordinates
Format: Translate2D[coords,{u,v}]
Translates a coordinate list delta distance.
Translate2D[{x_?IsScalar2D,y_?IsScalar2D},
{u_?IsScalar2D,v_?IsScalar2D}] := {x+u,y+v};
Translate Equation
Format: Translate2D[eqn,{x,y},{u,v}]
Translates an equation in the variables x and y by delta distance.
Translate2D[eqn_Equal,{x_?IsScalar2D,y_?IsScalar2D},
{u_?IsScalar2D,v_?IsScalar2D}] :=
(eqn /. {x->x-u,y->y-v});
Translate List
Format: Translate2D[objList,{u,v}]
Translates a list of {x,y} coordinates or objects delta distance.
Translate2D[obj_List?IsTransformable$2D,
{u_?IsScalar2D,v_?IsScalar2D}] :=
Map[Translate2D[#,{u,v}]&, obj] /;
Not[IsScalarPair2D[obj]];
Epilogue
End[ ]; (* end of "`Private" *)
EndPackage[ ]; (* end of "D2DTransform2D`" *)