⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 math::trig.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 2 页
字号:
.Ve.IP "rad2deg" 4.IX Item "rad2deg".Vb 1\&    $degrees  = rad2deg($radians);.Ve.IP "grad2deg" 4.IX Item "grad2deg".Vb 1\&    $degrees  = grad2deg($gradians);.Ve.IP "deg2grad" 4.IX Item "deg2grad".Vb 1\&    $gradians = deg2grad($degrees);.Ve.IP "rad2grad" 4.IX Item "rad2grad".Vb 1\&    $gradians = rad2grad($radians);.Ve.PPThe full circle is 2 \fIpi\fR radians or \fI360\fR degrees or \fI400\fR gradians.The result is by default wrapped to be inside the [0, {2pi,360,400}[ circle.If you don't want this, supply a true second argument:.PP.Vb 2\&    $zillions_of_radians  = deg2rad($zillions_of_degrees, 1);\&    $negative_degrees     = rad2deg($negative_radians, 1);.Ve.PPYou can also do the wrapping explicitly by \fIrad2rad()\fR, \fIdeg2deg()\fR, and\&\fIgrad2grad()\fR..IP "rad2rad" 4.IX Item "rad2rad".Vb 1\&    $radians_wrapped_by_2pi = rad2rad($radians);.Ve.IP "deg2deg" 4.IX Item "deg2deg".Vb 1\&    $degrees_wrapped_by_360 = deg2deg($degrees);.Ve.IP "grad2grad" 4.IX Item "grad2grad".Vb 1\&    $gradians_wrapped_by_400 = grad2grad($gradians);.Ve.SH "RADIAL COORDINATE CONVERSIONS".IX Header "RADIAL COORDINATE CONVERSIONS"\&\fBRadial coordinate systems\fR are the \fBspherical\fR and the \fBcylindrical\fRsystems, explained shortly in more detail..PPYou can import radial coordinate conversion functions by using the\&\f(CW\*(C`:radial\*(C'\fR tag:.PP.Vb 1\&    use Math::Trig \*(Aq:radial\*(Aq;\&\&    ($rho, $theta, $z)     = cartesian_to_cylindrical($x, $y, $z);\&    ($rho, $theta, $phi)   = cartesian_to_spherical($x, $y, $z);\&    ($x, $y, $z)           = cylindrical_to_cartesian($rho, $theta, $z);\&    ($rho_s, $theta, $phi) = cylindrical_to_spherical($rho_c, $theta, $z);\&    ($x, $y, $z)           = spherical_to_cartesian($rho, $theta, $phi);\&    ($rho_c, $theta, $z)   = spherical_to_cylindrical($rho_s, $theta, $phi);.Ve.PP\&\fBAll angles are in radians\fR..Sh "\s-1COORDINATE\s0 \s-1SYSTEMS\s0".IX Subsection "COORDINATE SYSTEMS"\&\fBCartesian\fR coordinates are the usual rectangular \fI(x, y, z)\fR\-coordinates..PPSpherical coordinates, \fI(rho, theta, pi)\fR, are three-dimensionalcoordinates which define a point in three-dimensional space.  They arebased on a sphere surface.  The radius of the sphere is \fBrho\fR, alsoknown as the \fIradial\fR coordinate.  The angle in the \fIxy\fR\-plane(around the \fIz\fR\-axis) is \fBtheta\fR, also known as the \fIazimuthal\fRcoordinate.  The angle from the \fIz\fR\-axis is \fBphi\fR, also known as the\&\fIpolar\fR coordinate.  The North Pole is therefore \fI0, 0, rho\fR, andthe Gulf of Guinea (think of the missing big chunk of Africa) \fI0,pi/2, rho\fR.  In geographical terms \fIphi\fR is latitude (northwardpositive, southward negative) and \fItheta\fR is longitude (eastwardpositive, westward negative)..PP\&\fB\s-1BEWARE\s0\fR: some texts define \fItheta\fR and \fIphi\fR the other way round,some texts define the \fIphi\fR to start from the horizontal plane, sometexts use \fIr\fR in place of \fIrho\fR..PPCylindrical coordinates, \fI(rho, theta, z)\fR, are three-dimensionalcoordinates which define a point in three-dimensional space.  They arebased on a cylinder surface.  The radius of the cylinder is \fBrho\fR,also known as the \fIradial\fR coordinate.  The angle in the \fIxy\fR\-plane(around the \fIz\fR\-axis) is \fBtheta\fR, also known as the \fIazimuthal\fRcoordinate.  The third coordinate is the \fIz\fR, pointing up from the\&\fBtheta\fR\-plane..Sh "3\-D \s-1ANGLE\s0 \s-1CONVERSIONS\s0".IX Subsection "3-D ANGLE CONVERSIONS"Conversions to and from spherical and cylindrical coordinates areavailable.  Please notice that the conversions are not necessarilyreversible because of the equalities like \fIpi\fR angles being equal to\&\fI\-pi\fR angles..IP "cartesian_to_cylindrical" 4.IX Item "cartesian_to_cylindrical".Vb 1\&    ($rho, $theta, $z) = cartesian_to_cylindrical($x, $y, $z);.Ve.IP "cartesian_to_spherical" 4.IX Item "cartesian_to_spherical".Vb 1\&    ($rho, $theta, $phi) = cartesian_to_spherical($x, $y, $z);.Ve.IP "cylindrical_to_cartesian" 4.IX Item "cylindrical_to_cartesian".Vb 1\&    ($x, $y, $z) = cylindrical_to_cartesian($rho, $theta, $z);.Ve.IP "cylindrical_to_spherical" 4.IX Item "cylindrical_to_spherical".Vb 1\&    ($rho_s, $theta, $phi) = cylindrical_to_spherical($rho_c, $theta, $z);.Ve.SpNotice that when \f(CW$z\fR is not 0 \f(CW$rho_s\fR is not equal to \f(CW$rho_c\fR..IP "spherical_to_cartesian" 4.IX Item "spherical_to_cartesian".Vb 1\&    ($x, $y, $z) = spherical_to_cartesian($rho, $theta, $phi);.Ve.IP "spherical_to_cylindrical" 4.IX Item "spherical_to_cylindrical".Vb 1\&    ($rho_c, $theta, $z) = spherical_to_cylindrical($rho_s, $theta, $phi);.Ve.SpNotice that when \f(CW$z\fR is not 0 \f(CW$rho_c\fR is not equal to \f(CW$rho_s\fR..SH "GREAT CIRCLE DISTANCES AND DIRECTIONS".IX Header "GREAT CIRCLE DISTANCES AND DIRECTIONS"A great circle is section of a circle that contains the circlediameter: the shortest distance between two (non-antipodal) points onthe spherical surface goes along the great circle connecting those twopoints..Sh "great_circle_distance".IX Subsection "great_circle_distance"You can compute spherical distances, called \fBgreat circle distances\fR,by importing the \fIgreat_circle_distance()\fR function:.PP.Vb 1\&  use Math::Trig \*(Aqgreat_circle_distance\*(Aq;\&\&  $distance = great_circle_distance($theta0, $phi0, $theta1, $phi1, [, $rho]);.Ve.PPThe \fIgreat circle distance\fR is the shortest distance between twopoints on a sphere.  The distance is in \f(CW$rho\fR units.  The \f(CW$rho\fR isoptional, it defaults to 1 (the unit sphere), therefore the distancedefaults to radians..PPIf you think geographically the \fItheta\fR are longitudes: zero at theGreenwhich meridian, eastward positive, westward negative\*(--and the\&\fIphi\fR are latitudes: zero at the North Pole, northward positive,southward negative.  \fB\s-1NOTE\s0\fR: this formula thinks in mathematics, notgeographically: the \fIphi\fR zero is at the North Pole, not at theEquator on the west coast of Africa (Bay of Guinea).  You need tosubtract your geographical coordinates from \fIpi/2\fR (also known as 90degrees)..PP.Vb 2\&  $distance = great_circle_distance($lon0, pi/2 \- $lat0,\&                                    $lon1, pi/2 \- $lat1, $rho);.Ve.Sh "great_circle_direction".IX Subsection "great_circle_direction"The direction you must follow the great circle (also known as \fIbearing\fR)can be computed by the \fIgreat_circle_direction()\fR function:.PP.Vb 1\&  use Math::Trig \*(Aqgreat_circle_direction\*(Aq;\&\&  $direction = great_circle_direction($theta0, $phi0, $theta1, $phi1);.Ve.Sh "great_circle_bearing".IX Subsection "great_circle_bearing"Alias 'great_circle_bearing' for 'great_circle_direction' is also available..PP.Vb 1\&  use Math::Trig \*(Aqgreat_circle_bearing\*(Aq;\&\&  $direction = great_circle_bearing($theta0, $phi0, $theta1, $phi1);.Ve.PPThe result of great_circle_direction is in radians, zero indicatingstraight north, pi or \-pi straight south, pi/2 straight west, and\&\-pi/2 straight east..PPYou can inversely compute the destination if you know thestarting point, direction, and distance:.Sh "great_circle_destination".IX Subsection "great_circle_destination".Vb 1\&  use Math::Trig \*(Aqgreat_circle_destination\*(Aq;\&\&  # thetad and phid are the destination coordinates,\&  # dird is the final direction at the destination.\&\&  ($thetad, $phid, $dird) =\&    great_circle_destination($theta, $phi, $direction, $distance);.Ve.PPor the midpoint if you know the end points:.Sh "great_circle_midpoint".IX Subsection "great_circle_midpoint".Vb 1\&  use Math::Trig \*(Aqgreat_circle_midpoint\*(Aq;\&\&  ($thetam, $phim) =\&    great_circle_midpoint($theta0, $phi0, $theta1, $phi1);.Ve.PPThe \fIgreat_circle_midpoint()\fR is just a special case of.Sh "great_circle_waypoint".IX Subsection "great_circle_waypoint".Vb 1\&  use Math::Trig \*(Aqgreat_circle_waypoint\*(Aq;\&\&  ($thetai, $phii) =\&    great_circle_waypoint($theta0, $phi0, $theta1, $phi1, $way);.Ve.PPWhere the \f(CW$way\fR is a value from zero ($theta0, \f(CW$phi0\fR) to one ($theta1,\&\f(CW$phi1\fR).  Note that antipodal points (where their distance is \fIpi\fRradians) do not have waypoints between them (they would have an an\&\*(L"equator\*(R" between them), and therefore \f(CW\*(C`undef\*(C'\fR is returned forantipodal points.  If the points are the same and the distancetherefore zero and all waypoints therefore identical, the first point(either point) is returned..PPThe thetas, phis, direction, and distance in the above are all in radians..PPYou can import all the great circle formulas by.PP.Vb 1\&  use Math::Trig \*(Aq:great_circle\*(Aq;.Ve.PPNotice that the resulting directions might be somewhat surprising ifyou are looking at a flat worldmap: in such map projections the greatcircles quite often do not look like the shortest routes\*(-- but forexample the shortest possible routes from Europe or North America toAsia do often cross the polar regions..SH "EXAMPLES".IX Header "EXAMPLES"To calculate the distance between London (51.3N 0.5W) and Tokyo(35.7N 139.8E) in kilometers:.PP.Vb 1\&    use Math::Trig qw(great_circle_distance deg2rad);\&\&    # Notice the 90 \- latitude: phi zero is at the North Pole.\&    sub NESW { deg2rad($_[0]), deg2rad(90 \- $_[1]) }\&    my @L = NESW( \-0.5, 51.3);\&    my @T = NESW(139.8, 35.7);\&    my $km = great_circle_distance(@L, @T, 6378); # About 9600 km..Ve.PPThe direction you would have to go from London to Tokyo (in radians,straight north being zero, straight east being pi/2)..PP.Vb 1\&    use Math::Trig qw(great_circle_direction);\&\&    my $rad = great_circle_direction(@L, @T); # About 0.547 or 0.174 pi..Ve.PPThe midpoint between London and Tokyo being.PP.Vb 1\&    use Math::Trig qw(great_circle_midpoint);\&\&    my @M = great_circle_midpoint(@L, @T);.Ve.PPor about 89.16N 68.93E, practically at the North Pole..Sh "\s-1CAVEAT\s0 \s-1FOR\s0 \s-1GREAT\s0 \s-1CIRCLE\s0 \s-1FORMULAS\s0".IX Subsection "CAVEAT FOR GREAT CIRCLE FORMULAS"The answers may be off by few percentages because of the irregular(slightly aspherical) form of the Earth.  The errors are at worstabout 0.55%, but generally below 0.3%..SH "BUGS".IX Header "BUGS"Saying \f(CW\*(C`use Math::Trig;\*(C'\fR exports many mathematical routines in thecaller environment and even overrides some (\f(CW\*(C`sin\*(C'\fR, \f(CW\*(C`cos\*(C'\fR).  This isconstrued as a feature by the Authors, actually... ;\-).PPThe code is not optimized for speed, especially because we use\&\f(CW\*(C`Math::Complex\*(C'\fR and thus go quite near complex numbers while doingthe computations even when the arguments are not. This, however,cannot be completely avoided if we want things like \f(CWasin(2)\fR to givean answer instead of giving a fatal runtime error..PPDo not attempt navigation using these formulas..SH "AUTHORS".IX Header "AUTHORS"Jarkko Hietaniemi <\fIjhi!at!iki.fi\fR> and Raphael Manfredi <\fIRaphael_Manfredi!at!pobox.com\fR>.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -