Exploring Analyic Geometry with Mathematica® |
|||||
| Home | Contents | Commands | Packages | Explorations | Reference |
| Tour | Lines | Circles | Conics | Analysis | Tangents |
D2DEllipse2D
The package D2DEllipse2D implements the Ellipse2D object.
Initialization
BeginPackage["D2DEllipse2D`",{"D2DExpressions2D`", "D2DGeometry2D`", "D2DLine2D`", "D2DMaster2D`", "D2DNumbers2D`", "D2DPoint2D`", "D2DQuadratic2D`", "D2DSegment2D`", "D2DSketch2D`", "D2DTransform2D`"}];
D2DEllipse2D::usage=
"D2DEllipse2D is a package that implements the Ellipse2D object.";
Ellipse2D::usage=
"Ellipse2D[{h,k},a,b,theta] is the standard form of an ellipse centered at (h,k), semi-major axis length 'a', semi-minor axis length 'b' and rotation angle 'theta'.";
SemiMajorAxis2D::usage=
"SemiMajorAxis2D[ellipse] returns the length of the semi-major axis of an ellipse.";
SemiMinorAxis2D::usage=
"SemiMinorAxis2D[ellipse] returns the length of the semi-minor axis of an ellipse.";
Begin["`Private`"];
Description
Representation
Format: Ellipse2D[{h,k},a,b,θ]
Standard representation of an ellipse in Descarta2D. The first argument is a list of coordinates representing the center of the ellipse. The second and third arguments are (positive) scalars representing the lengths of the semi-major and semi-minor axes of the ellipse. The fourth argument is the CCW rotation angle (in radians) of the ellipse about the center point.
Equation
Format: Quadratic2D[ellipse]
Constructs a quadratic representing the equation of an ellipse.
Quadratic2D[Ellipse2D[{h_,k_},a_,b_,theta_]] :=
Rotate2D[
Quadratic2D[b^2,0,a^2,-2*b^2*h,-2*a^2*k,-a^2*b^2+b^2*h^2+a^2*k^2],
theta,
{h,k}];
Evaluation
Format: Ellipse2D[{h,k},a,b,θ][
]
Evaluates a position on an ellipse at parameter
and returns a list of coordinates {x,y}. Parameters in the range
cover the entire ellipse.
Ellipse2D[{h_,k_},a_,b_,theta_][t_?IsScalar2D] :=
Rotate2D[{h+a*Cos[t],k+b*Sin[t]},theta,{h,k}];
Graphics
Provides the graphics primitives for an ellipse by extending the Mathematica Display command. Executed when the package is loaded.
SetDisplay2D[
Ellipse2D[{h_,k_},a_,b_,t_][{t1_?IsScalar2D,t2_?IsScalar2D}],
MakePrimitives2D[Ellipse2D[{h,k},a,b,t],
PrimaryAngleRange2D[{t1,t2}]] ];
SetDisplay2D[
Ellipse2D[{h_,k_},a_,b_,t_],
MakePrimitives2D[Ellipse2D[{h,k},a,b,t],{0,2Pi}] ];
Validation
Format: Ellipse2D[{h,k},a,b,θ]
Detects an ellipse with imaginary arguments and returns the $Failed symbol. If the imaginary parts are insignificant, they are removed.
Ellipse2D::imaginary=
"An invalid ellipse of the form 'Ellipse2D[`1`, `2`, `3`, `4`]' has been detected; the arguments of an ellipse cannot involve imaginary numbers.";
Ellipse2D[{h_,k_},a_,b_,theta_] :=
(Ellipse2D @@ ChopImaginary2D[Ellipse$2D[{h,k},a,b,theta]]) /;
(FreeQ[{h,k,a,b,theta},_Pattern] && IsTinyImaginary2D[{h,k,a,b,theta}]);
Ellipse2D[{h_,k_},a_,b_,theta_] :=
(Message[Ellipse2D::imaginary,{h,k},a,b,theta];$Failed) /;
(FreeQ[{h,k,a,b,theta},_Pattern] && IsComplex2D[{h,k,a,b,theta},0]);
Format: Ellipse2D[{h,k},a,b,θ]
Detects an ellipse with invalid arguments and returns the $Failed symbol.
Ellipse2D::invalid=
"An invalid ellipse of the form 'Ellipse2D[`1`, `2`, `3`, `4`]' has been detected; the length of both the semi-major and semi-minor axes must be positive.";
Ellipse2D[{h_,k_},a_,b_,theta_] :=
(Message[Ellipse2D::invalid,{h,k},a,b,theta];$Failed) /;
(FreeQ[{h,k,a,b,theta},_Pattern] && IsZeroOrNegative2D[{a,b},0]);
Format: Ellipse2D[{h,k},a,b,θ]
Detects a y-axis ellipse and rotates it π/2 radians.
Ellipse2D[{h_,k_},a_,b_,theta_] :=
Ellipse2D[{h,k},b,a,theta+Pi/2] /;
(FreeQ[{h,k,a,b,theta},_Pattern] && IsNegative2D[a-b,0]);
Format: Ellipse2D[{h,k},a,b,θ]
Adjusts the rotation angle on all ellipses to the range 0≤θ<π.
Ellipse2D[{h_,k_},a_,b_,theta_] :=
Ellipse2D[{h,k},a,b,PrimaryAngle2D[theta,Pi]] /;
(FreeQ[{h,k,a,b,theta},_Pattern] && (theta=!=PrimaryAngle2D[theta,Pi]));
Format: IsValid2D[ellipse]
Verifies that an ellipse is syntactically valid.
IsValid2D[Ellipse2D[{h_?IsScalar2D,k_?IsScalar2D},
a_?IsScalar2D,b_?IsScalar2D,
theta_?IsScalar2D]] := True;
Scalars
Angle of Rotation
Format: Angle2D[ellipse]
Returns the rotation angle of an ellipse.
Angle2D[Ellipse2D[{h_,k_},a_,b_,theta_]] := theta;
Semi-major Axis Length
Format: SemiMajorAxis2D[ellipse]
Returns the length of the semi-major axis of an ellipse.
SemiMajorAxis2D[Ellipse2D[{h_,k_},a_,b_,theta_]] := a;
Semi-minor Axis Length
Format: SemiMinorAxis2D[ellipse]
Returns the length of the semi-major axis of an ellipse.
SemiMinorAxis2D[Ellipse2D[{h_,k_},a_,b_,theta_]] := b;
Transformations
Reflect
Format: Reflect2D[ellipse,line]
Reflects an ellipse in a line.
Reflect2D[Ellipse2D[{h_,k_},a_,b_,theta_],L:Line2D[p_,q_,r_]] :=
Ellipse2D[Reflect2D[{h,k},L],a,b,ReflectAngle2D[theta,L]];
Rotate
Format: Rotate2D[ellipse,θ,coords]
Rotates an ellipse 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[Ellipse2D[{h_,k_},a_,b_,theta_],alpha_?IsScalar2D,
{x0_?IsScalar2D,y0_?IsScalar2D}] :=
Ellipse2D[Rotate2D[{h,k},alpha,{x0,y0}],a,b,alpha+theta];
Scale
Format: Scale2D[ellipse,s,coords]
Scales an ellipse by a scale factor, s, from a position given by coordinates. If the third argument is omitted, it defaults to the origin (see D2DTransform2D.html).
Scale2D[Ellipse2D[{h_,k_},a_,b_,theta_],s_?IsScalar2D,
{x0_?IsScalar2D,y0_?IsScalar2D}] :=
Ellipse2D[Scale2D[{h,k},s,{x0,y0}],s*a,s*b,theta] /;
Not[IsZeroOrNegative2D[s]];
Translate
Format: Translate2D[ellipse,{u,v}]
Translates an ellipse delta distance.
Translate2D[Ellipse2D[{h_,k_},a_,b_,theta_],
{u_?IsScalar2D,v_?IsScalar2D}] :=
Ellipse2D[{h+u,k+v},a,b,theta];
Point Construction
Center Point
Format: Point2D[ellipse]
Constructs the center point of an ellipse.
Point2D[Ellipse2D[{h_,k_},a_,b_,theta_]] := Point2D[{h,k}];
Pole Point
Format: Point2D[line,ellipse]
Constructs the pole point of a line with respect to an ellipse. If the line is tangent to the ellipse then the point is the point of tangency.
Point2D[L1:Line2D[a1_,b1_,c1_],E2:Ellipse2D[{h2_,k2_},a2_,b2_,theta2_]] :=
Point2D[L1,Quadratic2D[E2]];
Line Construction
Axis Line
Format: Line2D[ellipse]
Constructs a line containing the major axis of an ellipse.
Line2D[Ellipse2D[{h_,k_},a_,b_,theta_]] :=
Rotate2D[Line2D[0,1,-k],theta,{h,k}];
Polar Line
Format: Line2D[point,ellipse]
Constructs the polar (line) of a pole (point) with respect to an ellipse. If the point is on the ellipse then the line is tangent to the ellipse at the point.
Line2D[P1:Point2D[{x1_,y1_}],E2:Ellipse2D[{h2_,k2_},a2_,b2_,theta2_]] :=
Line2D[P1,Quadratic2D[E2]];
Ellipse Construction
Ellipse from Vertices and Eccentricity
Format: Ellipse2D[{point,point},e]
Constructs an ellipse from the vertices and eccentricity.
Ellipse2D::invdef=
"The defining geometry or eccentricity is invalid; the eccentricity of an ellipse must be in the range 0<e<1, the foci and vertices cannot be coincident, and the focus cannot lie on the directrix.";
Ellipse2D[{P1:Point2D[{x1_,y1_}],P2:Point2D[{x2_,y2_}]},e_?IsScalar2D] :=
Module[{a,b,h,k},
If[IsZeroOrNegative2D[{e,1-e},Or] || IsCoincident2D[P1,P2],
Message[Ellipse2D::invdef];$Failed,
a=Distance2D[P1,P2]/2;
b=a*Sqrt[1-e^2];
{h,k}={(x1+x2)/2,(y1+y2)/2};
Ellipse2D[{h,k},a,b,ArcTan[x2-x1,y2-y1]]] ];
Ellipse from Foci and Eccentricity
Format: Ellipse2D[point,point,e]
Constructs an ellipse from the foci and eccentricity.
Ellipse2D[P1:Point2D[{x1_,y1_}],P2:Point2D[{x2_,y2_}],e_?IsScalar2D] :=
Module[{a,b,h,k},
If[IsZeroOrNegative2D[{e,1-e},Or] || IsCoincident2D[P1,P2],
Message[Ellipse2D::invdef];$Failed,
a=Distance2D[P1,P2]/(2*e);
b=a*Sqrt[1-e^2];
{h,k}={(x1+x2)/2,(y1+y2)/2};
Ellipse2D[{h,k},a,b,ArcTan[x2-x1,y2-y1]]] ];
Ellipse from Focus, Directrix and Eccentricity
Format: Ellipse2D[point,line,e]
Constructs an ellipse from a focus point, directrix line and eccentricity.
Ellipse2D[P1:Point2D[{x1_,y1_}],L2:Line2D[p_,q_,r_],e_?IsScalar2D] :=
Module[{d,s,a,b,h,k},
If[IsZeroOrNegative2D[{e,1-e},Or] || IsOn2D[P1,L2],
Message[Ellipse2D::invdef];$Failed,
d=Distance2D[P1,L2];
s=(p*x1+q*y1+r)/(p^2+q^2);
a=d*e/(1-e^2);
b=a*Sqrt[1-e^2];
{h,k}={x1,y1}+{p,q}*(a*s*e)/d;
Ellipse2D[{h,k},a,b,ArcTan[p,q]]] ];
Epilogue
End[ ]; (* end of "`Private" *)
EndPackage[ ]; (* end of "D2DEllipse2D`" *)