Exploring Analyic Geometry with Mathematica® |
|||||
| Home | Contents | Commands | Packages | Explorations | Reference |
| Tour | Lines | Circles | Conics | Analysis | Tangents |
D2DSegment2D
The package D2DSegment2D implements the Segment2D object.
Initialization
BeginPackage["D2DSegment2D`", {"D2DCircle2D`", "D2DExpressions2D`", "D2DGeometry2D`", "D2DLine2D`", "D2DMaster2D`", "D2DNumbers2D`", "D2DPoint2D`", "D2DSketch2D`", "D2DTransform2D`"}];
D2DSegment2D::usage=
"D2DSegment2D is a package providing support for line segments.";
Length2D::usage=
"Length2D[lnseg] computes the length of a line segment.";
Segment2D::usage=
"Segment2D[{x0,y0},{x1,y1}] is the standard form of a line segment with end points {x0,y0} and {x1,y1}.";
Begin["`Private`"];
Description
Representation
Format: Segment2D[{
,
},{
,
}]
Standard representation of a line segment in Descarta2D. The coordinates {
,
} and {
,
} are the start and end points, respectively, of the line segment.
Evaluation
Format: Segment2D[{
,
},{
,
}][t]
Evaluates a parameter, -Infinity < t < Infinity, on a line segment. The parameter values 0 and 1 are the start and end points, respectively. Returns a coordinate list {x,y}.
Segment2D[{x0_,y0_},{x1_,y1_}][t_?IsScalar2D] :=
{x0+t*(x1-x0), y0+t*(y1-y0)};
Graphics
Provides graphics primitives for a line segment by extending the Mathematica Display command. Executed when the package is loaded.
SetDisplay2D[
Segment2D[{x0_,y0_},{x1_,y1_}][{t1_?IsScalar2D,t2_?IsScalar2D}],
Line[{Segment2D[{x0,y0},{x1,y1}][t1],
Segment2D[{x0,y0},{x1,y1}][t2]}] ];
SetDisplay2D[
Segment2D[{x0_,y0_},{x1_,y1_}],
Line[{{x0,y0},{x1,y1}}] ];
Validation
Format: Segment2D[{
,
},{
,
}]
Detects line segments with imaginary arguments and returns the $Failed symbol. If the imaginary parts are insignificant, they are removed.
Segment2D::imaginary=
"An invalid line segment of the form Segment2D[`1`,`2`] has been detected; the arguments cannot be imaginary.";
Segment2D[{x0_,y0_},{x1_,y1_}] :=
(Segment2D @@ ChopImaginary2D[Segment$2D[{x0,y0},{x1,y1}]]) /;
(FreeQ[{x0,y0,x1,y1},_Pattern] && IsTinyImaginary2D[{x0,y0,x1,y1}]);
Segment2D[{x0_,y0_},{x1_,y1_}] :=
(Message[Segment2D::imaginary,{x0,y0},{x1,y1}];$Failed) /;
(FreeQ[{x0,y0,x1,y1},_Pattern] && IsComplex2D[{x0,y0,x1,y1},0]);
Format: Segment2D[{
,
},{
,
}]
Returns the $Failed symbol for line segments with coincident start and end points.
Segment2D::invalid=
"An invalid line segment of the form Segment2D[`1`,`2`] has been detected; the defining coordinates cannot be coincident.";
Segment2D[{x0_,y0_},{x1_,y1_}] :=
(Message[Segment2D::invalid,{x0,y0},{x1,y1}];$Failed) /;
(FreeQ[{x0,y0,x1,y1},_Pattern] && IsCoincident2D[{x0,y0},{x1,y1}]);
Format: IsValid2D[lnseg]
Verifies that a line segment is syntactically valid.
IsValid2D[
Segment2D[{x0_?IsScalar2D,y0_?IsScalar2D},
{x1_?IsScalar2D,y1_?IsScalar2D}]] := True;
Scalars
Length
Format: Length2D[lnseg]
Computes the length of a line segment.
Length2D[Segment2D[{x0_,y0_},{x1_,y1_}]] := Sqrt[(x0-x1)^2+(y0-y1)^2];
Slope
Format: Slope2D[lnseg]
Computes the slope of a line segment.
Slope2D[Segment2D[{x0_,y0_},{x1_,y1_}]] :=
If[IsZero2D[x1-x0],Infinity,(y1-y0)/(x1-x0)];
Transformations
Reflect
Format: Reflect2D[lnseg,line]
Reflects a line segment in a line.
Reflect2D[Segment2D[{x0_,y0_},{x1_,y1_}],L2:Line2D[a_,b_,c_]] :=
Segment2D[Reflect2D[{x0,y0},L2],Reflect2D[{x1,y1},L2]];
Rotate
Format: Rotate2D[lnseg,θ,coords]
Rotates a line segment by an angle θ about a position specified by a coordinate list. If the third argument is omitted it defaults to the origin (see D2DTransform2D.html).
Rotate2D[Segment2D[{x0_,y0_},{x1_,y1_}],theta_?IsScalar2D,
{h_?IsScalar2D,k_?IsScalar2D}] :=
Segment2D[Rotate2D[{x0,y0},theta,{h,k}],
Rotate2D[{x1,y1},theta,{h,k}]];
Scale
Format: Scale2D[lnseg,s,coords]
Scales a line segment from a position given by coordinates. If the third argument is omitted it defaults to the origin (see D2DTransform2D.html).
Scale2D[Segment2D[{x0_,y0_},{x1_,y1_}],s_?IsScalar2D,
{h_?IsScalar2D,k_?IsScalar2D}] :=
Segment2D[Scale2D[{x0,y0},s,{h,k}],Scale2D[{x1,y1},s,{h,k}]] /;
Not[IsZeroOrNegative2D[s]];
Translate
Format: Translate2D[lnseg,{u,v}]
Translates a line segment delta distance.
Translate2D[Segment2D[{x0_,y0_},{x1_,y1_}],{u_?IsScalar2D,v_?IsScalar2D}] :=
Segment2D[{x0+u,y0+v},{x1+u,y1+v}];
Point Construction
Midpoint
Format: Point2D[lnseg]
Constructs the midpoint of a line segment.
Point2D[Segment2D[{x0_,y0_},{x1_,y1_}]] := Point2D[{x0+x1,y0+y1}/2];
Line Segment Construction
Line Segment from Two Points
Format: Segment2D[point,point]
Constructs a line segment from two points.
Segment2D[Point2D[{x0_,y0_}],Point2D[{x1_,y1_}]] :=
Segment2D[{x0,y0},{x1,y1}];
Line Construction
Line from Line Segment
Format: Line2D[lnseg]
Constructs a line containing a line segment.
Line2D[Segment2D[{x0_,y0_},{x1_,y1_}]] :=
Line2D[-(y1-y0),(x1-x0),(x0*y1-x1*y0)];
Line Bisecting a Line Segment
Format: Line2D[lnseg,Perpendicular2D]
Constructs a line that is the perpendicular bisector of a line segment.
Line2D[Segment2D[{x0_,y0_},{x1_,y1_}],Perpendicular2D] :=
Line2D[2*(x1-x0),2*(y1-y0),x0^2-x1^2+y0^2-y1^2];
Circle Construction
Circle from Diameter Chord
Format: Circle2D[lnseg]
Constructs a circle from a line segment that is one of the circle's diameter chords.
Circle2D[Segment2D[{x0_,y0_},{x1_,y1_}]] :=
Circle2D[{(x0+x1)/2,(y0+y1)/2},Sqrt[(x0-x1)^2+(y0-y1)^2]/2];
Epilogue
End[ ]; (* end of "`Private" *)
EndPackage[ ]; (* end of "D2DSegment2D`" *)