Exploring Analyic Geometry with Mathematica®

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

D2DArcLength2D

The package D2DArcLength2D provides functions for computing the arc length of Descarta2D objects.

Initialization

BeginPackage["D2DArcLength2D`", {"D2DArc2D`", "D2DCircle2D`", "D2DConicArc2D`", "D2DEllipse2D`", "D2DExpressions2D`", "D2DGeometry2D`", "D2DHyperbola2D`", "D2DLine2D`", "D2DNumbers2D`", "D2DParabola2D`", "D2DSegment2D`", "D2DTriangle2D`"}];

D2DArcLength2D::usage=
   "D2DArcLength2D is a package for computing the arc length of curves.";

ArcLength2D::usage=
   "ArcLength2D[curve,{t0,t1}] computes the arc length of a curve between two parameters.";

Circumference2D::usage=
   "Circumference2D[circle] computes the circumference of a circle. Circumference2D[ellipse] computes the circumference of an ellipse.";

Perimeter2D::usage=
   "Perimeter2D[triangle] computes the perimeter of a triangle.";

Span2D::usage=
   "Span2D[arc] computes the span (arc length) of an arc; N[Span2D[cnarc]] numerically computes the span (arc length) of a conic arc.";

Begin["`Private`"];

Arc Length

Arc

Format: Span2D[arc]
Computes the arc length of a complete span of an arc.

Span2D[A:Arc2D[{x0_,y0_},{x1_,y1_},B_]] :=
   Module[{theta1,theta2},
      {theta1,theta2}=PrimaryAngleRange2D[A];
      Radius2D[A]*(theta2-theta1) ];

Format: ArcLength2D[arc,{"D2DArcLength2D_1.gif","D2DArcLength2D_2.gif"}]
Computes the arc length of an arc between two parameters.

ArcLength2D[A:Arc2D[{x0_,y0_},{x1_,y1_},B_],
            {t1_?IsScalar2D,t2_?IsScalar2D}] :=
   Module[{T1,T2},
      {T1,T2}=PrimaryAngleRange2D[{Angle2D[A,t1],Angle2D[A,t2]}];
      Radius2D[A]*(T2-T1) ];

Circle

Format: Circumference2D[circle]
Computes the circumference of a circle.

Circumference2D[Circle2D[{h_,k_},r_]] := 2*Pi*r;

Format: ArcLength2D[circle,{"D2DArcLength2D_3.gif","D2DArcLength2D_4.gif"}]
Computes the arc length of a circle between two parameters.

ArcLength2D[Circle2D[{h_,k_},r_],{t1_?IsScalar2D,t2_?IsScalar2D}] :=
   Module[{T1,T2},
      {T1,T2}=PrimaryAngleRange2D[{t1,t2}];
      r*(T2-T1) ];

Conic Segment

Format: Span2D[cnarc] //N
Computes the length of a complete span of a conic arc numerically.

N[Span2D[C1:ConicArc2D[{x0_,y0_},{xA_,yA_},{x1_,y1_},p_]]] :=
   NArcLength$2D[C1,{0,1},$MachinePrecision] /;
IsNumeric2D[C1,Span2D];

N[Span2D[C1:ConicArc2D[{x0_,y0_},{xA_,yA_},{x1_,y1_},p_]],n_] :=
   NArcLength$2D[C1,{0,1},n] /;
IsNumeric2D[C1,Span2D];

Format: ArcLength2D[cnarc,{{"D2DArcLength2D_5.gif","D2DArcLength2D_6.gif"}] //N
Computes the arclength of a complete span of a conic arc between two parameters numerically.

N[ArcLength2D[C1:ConicArc2D[{x0_,y0_},{xA_,yA_},{x1_,y1_},p_],
              {t1_?IsScalar2D,t2_?IsScalar2D}]] :=
   NArcLength$2D[C1,{t1,t2},$MachinePrecision] /;
IsNumeric2D[{C1,t1,t2},ArcLength2D];

N[ArcLength2D[C1:ConicArc2D[{x0_,y0_},{xA_,yA_},{x1_,y1_},p_],
              {t1_?IsScalar2D,t2_?IsScalar2D}],
  n_] :=
   NArcLength$2D[C1,{t1,t2},n] /;
IsNumeric2D[{C1,t1,t2},ArcLength2D];

Ellipse

Format: Circumference2D[ellipse]
Computes the circumference of an ellipse.

Circumference2D[E1:Ellipse2D[{h_,k_},a_,b_,theta_]] :=
   ArcLength2D[E1,{0,2Pi}];

Format: ArcLength2D[ellipse,{"D2DArcLength2D_7.gif","D2DArcLength2D_8.gif"}]
Computes the arc length of an ellipse between two parameters.

ArcLength2D[Ellipse2D[{h_,k_},a_,b_,theta_],
            {t1_?IsScalar2D,t2_?IsScalar2D}] :=
   Module[{T1,T2,L},
      {T1,T2}=PrimaryAngleRange2D[{t1,t2}];
      L=b*(EllipticE[T2,1-a^2/b^2]-EllipticE[T1,1-a^2/b^2]);
      If[IsNegative2D[L],-L,L] ];

Hyperbola

The private function ArcLengthHyperbola$2D[hyperbola,{0,t}] computes the arc length of a hyperbola between parameter values 0 and t.  The result may be positive or negative, depending on the value given for t.

ArcLengthHyperbola$2D[Hyperbola2D[{h_,k_},a_,b_,theta_],{0,t_}] :=
   Re[-I*b*EllipticE[I*ArcCosh[Sqrt[a^2+b^2]/a]*t,1+a^2/b^2]];

Format: ArcLength2D[hyperbola,{"D2DArcLength2D_9.gif","D2DArcLength2D_10.gif"}]
Computes the arc length of a hyperbola between two parameters.

ArcLength2D[H1:Hyperbola2D[{h_,k_},a_,b_,theta_],
            {t1_?IsScalar2D,t2_?IsScalar2D}] :=
   Module[{L},
      L=ArcLengthHyperbola$2D[H1,{0,t2}]-
        ArcLengthHyperbola$2D[H1,{0,t1}];
      If[IsNegative2D[L],-L,L] ];

Line

Format: ArcLength2D[line,{"D2DArcLength2D_11.gif","D2DArcLength2D_12.gif"}]
Computes the arc length of a line between two parameters.

ArcLength2D[Line2D[a_,b_,c_],{t1_?IsScalar2D,t2_?IsScalar2D}] :=
   Module[{L},
      L=t2-t1;
      If[IsNegative2D[L],-L,L] ];

Line Segment

Format: ArcLength2D[lnseg,{"D2DArcLength2D_13.gif","D2DArcLength2D_14.gif"}]
Computes the arc length of a line segment between two parameters. The function Length2D[lnseg] computes the length of a complete line segment (defined in package D2DSegment2D).

ArcLength2D[Segment2D[{x0_,y0_},{x1_,y1_}],
            {t1_?IsScalar2D,t2_?IsScalar2D}] :=
   Module[{L},
      L=(t2-t1)*Sqrt[(x0-x1)^2+(y0-y1)^2];
      If[IsNegative2D[L],-L,L] ];

Parabola

Format: ArcLength2D[parabola,{"D2DArcLength2D_15.gif","D2DArcLength2D_16.gif"}]
Computes the arc length of a parabola between two parameter values.

ArcLength2D[Parabola2D[{h_,k_},f_,t_],
            {t1_?IsScalar2D,t2_?IsScalar2D}] :=
   Module[{S1=Sqrt[1+t1^2],S2=Sqrt[1+t2^2]},
      L=f*( (S2*t2+Log[2*f^2(S2+t2)]) -
            (S1*t1+Log[2*f^2(S1+t1)]) );
      If[IsNegative2D[L],-L,L] ];

Triangle

Format: Perimeter2D[triangle]
Computes the perimeter of a triangle.

Perimeter2D[Triangle2D[{x1_,y1_},{x2_,y2_},{x3_,y3_}]] :=
   Sqrt[(x1-x2)^2+(y1-y2)^2]+
   Sqrt[(x1-x3)^2+(y1-y3)^2]+
   Sqrt[(x2-x3)^2+(y2-y3)^2];

Arc Length (Numerical)

Parametric Curves

The private function NArcLength$2D[curve,{"D2DArcLength2D_17.gif","D2DArcLength2D_18.gif"}] computes the arc length of a parametric curve between two parameter values.  The function uses numerical integration, so the arguments of the function must be numerical.  The third argument, n, specifies the numerical precision.

NArcLength$2D[obj_,{t1_,t2_},n_] :=
   Module[{t,Dx,Dy,L},
      {Dx,Dy}=Map[D[#,t]&,obj[t]];
      L=NIntegrate[Sqrt[Dx^2+Dy^2],{t,t1,t2},WorkingPrecision->n];
      If[IsNegative2D[L],-L,L] ];

Epilogue

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


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