Exploring Analyic Geometry with Mathematica® |
|||||
| Home | Contents | Commands | Packages | Explorations | Reference |
| Tour | Lines | Circles | Conics | Analysis | Tangents |
D2DTangentPoints2D
The package D2DTangentPoints2D provides functions for constructing the point of contact between a curve and a tangent line.
Initialization
BeginPackage["D2DTangentPoints2D`", {"D2DCircle2D`", "D2DEllipse2D`", "D2DExpressions2D`", "D2DGeometry2D`", "D2DHyperbola2D`", "D2DIntersect2D`", "D2DLine2D`", "D2DMaster2D`", "D2DParabola2D`", "D2DPoint2D`", "D2DQuadratic2D`"}];
D2DTangentPoints2D::usage=
"D2DTangentPoints2D is a package for constructing tangent points.";
TangentPoints2D::usage=
"TangentPoints2D[point,curve] constructs a list containing points that are the tangency points of the lines from a point to a curve.";
Begin["`Private`"];
Point Construction
Circle Contact Points
Format: TangentPoints2D[point,circle]
Constructs a list containing up to two points that are the contact points of the lines tangent to a circle from a point. This is a simplified formula for circles; the general second-degree form also produces the correct points (see below).
TangentPoints2D[Point2D[{x1_,y1_}],Circle2D[{h_,k_},r_]] :=
Module[{d,R,c,s,S},
d=(x1-h)^2+(y1-k)^2;
If[IsZero2D[d],{},
R=If[IsZero2D[d-r^2],0,d-r^2];
c=(r*(x1-h)-S*Sqrt[R]*(y1-k))/d;
s=(r*(y1-k)+S*Sqrt[R]*(x1-h))/d;
Map[(Point2D[{h+r*c,k+r*s}] /. S->#)&,
Which[IsZero2D[R],{1},
IsNegative2D[R], {},
True, {-1,1}]]] ];
Conic Contact Points
Format: TangentPoints2D[point,curve]
Constructs a list containing up to two points that are the contact points of the lines tangent to a second-degree curve (ellipse, parabola, hyperbola or quadratic) from a point. The circle is handled as a special case (see above).
TangentPoints2D[P1:Point2D[{x1_,y1_}],crv2_] :=
Module[{Q,a,b,c,d,e,f,p,q,r,pts},
Q=If[Head[crv2]===Quadratic2D,crv2,Quadratic2D[crv2]];
{a,b,c,d,e,f}=List @@ Q;
p=2*a*x1+b*y1+d; q=b*x1+2*c*y1+e; r=d*x1+e*y1+2*f;
Which[
IsZero2D[{p,q},And], {},
IsOn2D[P1,Q], {Point2D[Line2D[p,q,r],crv2]},
True, Points2D[Line2D[p,q,r],crv2]] ] /;
Is2D[crv2,{Ellipse2D,Hyperbola2D,Parabola2D,Quadratic2D}];
Epilogue
End[ ]; (* end of "`Private" *)
EndPackage[ ]; (* end of "D2DTangentPoints2D`" *)