Exploring Analyic Geometry with Mathematica®

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

D2DPoint2D

The package D2DPoint2D implements the Point2D object.

Initialization

BeginPackage["D2DPoint2D`", {"D2DExpressions2D`", "D2DGeometry2D`", "D2DLine2D`", "D2DMaster2D`", "D2DNumbers2D`", "D2DQuadratic2D`", "D2DSketch2D`", "D2DTransform2D`"}];

D2DPoint2D::usage=
   "D2DPoint2D is a package that implements the Point2D object.";

Coordinates2D::usage=
   "Coordinates2D[a1,a2,...] gives the {x,y} coordinates of the point returned by Point2D[a1,a2,...].";

Distance2D::usage=
   "Distance2D[coords,coords] gives the distance between two positions given by coordinates; Distance2D[point,pt | ln | cir] gives the distance between a point and a point, line or circle.";

Point2D::usage=
  "Point2D[{x,y}] is the standard form of a point at coordinates {x,y}.";

XCoordinate2D::usage=
   "XCoordinate2D[point] gives the x-coordinate of a point; XCoordinate2D[coords] gives the x-coordinate of a coordinate location.";

YCoordinate2D::usage=
   "YCoordinate2D[point] gives the y-coordinate of a point; YCoordinate[coords] gives the y-coordinate of a coordinate location.";

Begin["`Private`"];

Description

Representation

Format: {x,y}
Standard representation of a location specified by (x,y) coordinates in Descarta2D.

Format: Point2D[{x,y}] or Point2D[coords]
Standard representation of a point in Descarta2D.  The coordinates define the (x,y) position of the point.

Graphics

Provides graphics for a point by extending the Mathematica Display command. Executed when the package is loaded.

SetDisplay2D[
   Point2D[{x_,y_}],
   {AbsolutePointSize[4],Point[{x,y}]} ];

Validation

Format: Point2D[{x,y}]
Detects that a point has imaginary coordinates and returns the $Failed symbol.  If the imaginary parts are insignificant, they are removed.

Point2D::imaginary=
   "An invalid point of the form 'Point2D[{`1`,`2`}]' has been detected; the coordinates of a point cannot be imaginary.";

Point2D[{x_,y_}] :=
   (Point2D @@ ChopImaginary2D[Point$2D[{x,y}]]) /;
(FreeQ[{x,y},_Pattern] && IsTinyImaginary2D[{x,y}]);

Point2D[{x_,y_}] :=
   (Message[Point2D::imaginary,x,y];$Failed) /;
(FreeQ[{x,y},_Pattern] && IsComplex2D[{x,y},0]);

Format: IsValid2D[point]
Verifies that a point is syntactically valid.

IsValid2D[Point2D[{x_?IsScalar2D,y_?IsScalar2D}]] := True;

Scalars

Coordinates Function

Format: Coordinates2D[args..]
Returns the {x,y} coordinates of Point2D[args..].

Coordinates2D[a___]:=
   Module[{pt},
      If[pt===$Failed,pt,{XCoordinate2D[pt],YCoordinate2D[pt]}] /;
  (pt=Point2D[a] /. Point2D[Point2D[x___]]->Point2D[x];
   (Is2D[pt,{Point2D}] || pt===$Failed))];

Distance between Coordinates

Format: Distance2D[coords,coords]
Computes the distance between two locations defined by coordinates.

Distance2D[{x1_?IsScalar2D,y1_?IsScalar2D},
           {x2_?IsScalar2D,y2_?IsScalar2D}] :=
   Sqrt[(x1-x2)^2+(y1-y2)^2];

Distance between Two Points

Format: Distance2D[point,point]
Computes the distance between two points.

Distance2D[Point2D[{x1_,y1_}],Point2D[{x2_,y2_}]] :=
   Sqrt[(x1-x2)^2+(y1-y2)^2];

X-Coordinate (Abscissa)

Format: XCoordinate2D[coords]
Returns the x-coordinate.

XCoordinate2D[{x_?IsScalar2D,y_?IsScalar2D}] := x;

X-Coordinate of a Point (Abscissa)

Format: XCoordinate2D[point]
Returns the x-coordinate of a point.

XCoordinate2D[Point2D[{x_,y_}]] := x;

Y-Coordinate (Ordinate)

Format: YCoordinate2D[coords]
Returns the y-coordinate.

YCoordinate2D[{x_?IsScalar2D,y_?IsScalar2D}] := y;

Y-Coordinate of a Point (Ordinate)

Format: YCoordinate2D[point]
Returns the y-coordinate of a point.

YCoordinate2D[Point2D[{x_,y_}]] := y;

Equations

Quadratic

Format: Quadratic2D[point]
Constructs the quadratic representing the equation of a point (a point circle).

Quadratic2D[Point2D[{x_,y_}]] := Quadratic2D[1,0,1,-2*x,-2*y,x^2+y^2];

Transformations

Reflect

Format: Reflect2D[point,line]
Reflects a point in a line.

Reflect2D[Point2D[{x_,y_}],L:Line2D[a_,b_,c_]] :=
   Point2D[ Reflect2D[{x,y},L] ];

Rotate

Format: Rotate2D[point,θ,coords]
Rotates a point by an angle θ about a position specified by coordinates.  If the third argument is omitted, it defaults to the origin (see D2DTransform2D.html).

Rotate2D[Point2D[{x_,y_}],theta_?IsScalar2D,
         {h_?IsScalar2D,k_?IsScalar2D}] :=
   Point2D[ Rotate2D[{x,y},theta,{h,k}] ];

Scale

Format: Scale2D[point,s,coords]
Scales a point from a position given by coordinates.  If the third argument is omitted, it defaults to the origin (see D2DTransform2D.html).

Scale2D[Point2D[{x_,y_}],s_?IsScalar2D,
        {x0_?IsScalar2D,y0_?IsScalar2D}] :=
   Point2D[{x0,y0}+s*{x-x0,y-y0}] /;
Not[IsZeroOrNegative2D[s]];

Translate

Format: Translate2D[point,{u,v}]
Translates a point delta distance.

Translate2D[Point2D[{x_,y_}],{u_?IsScalar2D,v_?IsScalar2D}] :=
   Point2D[{x+u,y+v}];

Point Construction

Point from Coordinates

Format: Point2D[x,y]
Constructs a point from the x- and y-coordinates.

Point2D[x_?IsScalar2D,y_?IsScalar2D] := Point2D[{x,y}];

Midpoint of Two Points

Format: Point2D[point,point]
Constructs the midpoint of two given points.

Point2D[Point2D[{x1_,y1_}],Point2D[{x2_,y2_}]] := Point2D[{x1+x2,y1+y2}/2];

Offset Point from Two Points

Format: Point2D[point,point,d]
Constructs a point at a given distance from the first point on the line joining the two given points.

Point2D::noDir=
   "Points {`1`, `2`} are coincident and do not define a valid direction.";

Point2D[P1:Point2D[{x1_,y1_}],P2:Point2D[{x2_,y2_}],d_?IsScalar2D] :=
   Module[{d12=Sqrt[(x2-x1)^2+(y2-y1)^2]},
      If[IsZero2D[d12],
         Message[Point2D::noDir,P1,P2];$Failed,
         Point2D[{x1,y1}+{d*(x2-x1),d*(y2-y1)}/d12]] ];

Point of Division

Format: Point2D[point,point,"D2DPoint2D_1.gif","D2DPoint2D_2.gif"]
Constructs a point which divides a line segment determined by two points into the ratio "D2DPoint2D_3.gif".

Point2D::noRatio=
   "The sum of the ratio numbers {`1`, `2`} cannot be zero.";

Point2D[Point2D[{x1_,y1_}],Point2D[{x2_,y2_}],
        r1_?IsScalar2D,r2_?IsScalar2D] :=
   If[IsZero2D[r1+r2],
      Message[Point2D::noRatio,r1,r2];$Failed,
      Point2D[{x1*r2+x2*r1,y1*r2+y2*r1}/(r1+r2)]];

Point Offset Along a Line

Format: Point2D[point,line,d]
Constructs a point  at a distance d from a given point in the direction of a given line. If the given point is on the line then the offset point will also be on the line. The distance may be positive or negative producing one of the two possible points.

Point2D[Point2D[{x1_,y1_}],Line2D[A2_,B2_,C2_],d_?IsScalar2D] :=
   Point2D[{x1,y1}+{-d*B2,d*A2}/Sqrt[A2^2+B2^2]];

Point Projected Onto a Line

Format: Point2D[point,line]
Constructs a point on a line by projecting a given point onto the line.

Point2D[Point2D[{x1_,y1_}],Line2D[A2_,B2_,C2_]] :=
   Point2D[{(  B2^2*x1-A2*B2*y1-A2*C2),
            (-A2*B2*x1+ A2^2*y1-B2*C2)}/(A2^2+B2^2)];

General Offset Point

Format: Point2D[point,line,{u,v}]
Constructs a point offset from the origin of an inferred coordinate system.  The given point is on the +x-axis  of the inferred coordinate system and the given line is the y-axis.  The point constructed has coordinates (u,v) in the inferred coordinate system.

Point2D[P1:Point2D[{x1_,y1_}],L2:Line2D[A2_,B2_,C2_],
        {u_?IsScalar2D,v_?IsScalar2D}] :=
   Module[{a,b,d,D,x=x1,y=y1},
      If[IsOn2D[P1,L2],x=x1+A2;y=y1+B2];
      {a,b,d}={A2,B2,A2*x+B2*y+C2}/Sqrt[A2^2+B2^2];
      D=Sqrt[d^2];
      Point2D[{x-a*d+(a*u-b*v)*d/D,y-b*d+(a*v+b*u)*d/D}] ];

Intersection Point of Two Lines

Format: Point2D[line,line]
Constructs the intersection point of two lines.

Point2D::coincident=
   "No unique intersection point exists; lines `1` and `2` are coincident.";

Point2D::parallel=
   "No intersection point exists; lines `1` and `2` are parallel.";

Point2D[L1:Line2D[A1_,B1_,C1_],L2:Line2D[A2_,B2_,C2_]] :=
   Which[
      IsCoincident2D[L1,L2],
         Message[Point2D::coincident,L1,L2];$Failed,
      IsParallel2D[L1,L2],
         Message[Point2D::parallel,L1,L2];$Failed,
      True,
         Point2D[{B1*C2-B2*C1,A2*C1-A1*C2}/(A1*B2-A2*B1)] ];

Center Point of a Quadratic

Format: Point2D[quad]
Constructs the center point of a central quadratic.

Point2D::notCentral=
   "`1` is not a central conic; it has no center point.";

Point2D[Q1:Quadratic2D[a_,b_,c_,d_,e_,f_]] :=
   Module[{disc=b^2-4*a*c},
      If[IsZero2D[disc],
         Message[Point2D::notCentral,Q1];$Failed,
         Point2D[{2*c*d-b*e,2*a*e-b*d}/(b^2-4*a*c)]] ];

Pole Point of a Quadratic

Format: Point2D[line,quad]
Constructs a pole (point) of a quadratic with respect to a polar (line).

Point2D::noPole=
   "Since `1` passes through the center of the conic, no pole point exists.";

Point2D[L1:Line2D[A1_,B1_,C1_],Q2:Quadratic2D[a_,b_,c_,d_,e_,f_]] :=
   Module[{q12,q1,q2},
      q12=A1*(b*e-2*c*d)+B1*(b*d-2*a*e)+C1*(4*a*c-b^2);
      If[IsZero2D[q12],
         Message[Point2D::noPole,L1,Q2];$Failed,
         q1=A1*(4*c*f-e^2)+B1*(d*e-2*b*f)+C1*(b*e-2*c*d);
         q2=A1*(d*e-2*b*f)+B1*(4*a*f-d^2)+C1*(b*d-2*a*e);
         Point2D[{q1,q2}/q12]] ];

Epilogue

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


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