CINXE.COM

Math::Trig - trigonometric functions - Perldoc Browser

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Math::Trig - trigonometric functions - Perldoc Browser</title> <link rel="search" href="/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser"> <link rel="canonical" href="https://perldoc.perl.org/Math::Trig"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" /> <style> body { background: #f4f4f5; color: #020202; } .navbar-dark { background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%); background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%); background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0); background-repeat: repeat-x; } .navbar-dark .navbar-nav .nav-link, .navbar-dark .navbar-nav .nav-link:focus { color: #fff } .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 } #wrapperlicious { margin: 0 auto; font: 0.9em 'Helvetica Neue', Helvetica, sans-serif; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0; } #wrapperlicious h1 { font-size: 1.5em } #wrapperlicious h2 { font-size: 1.3em } #wrapperlicious h3 { font-size: 1.1em } #wrapperlicious h4 { font-size: 0.9em } #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3, #wrapperlicious h4, #wrapperlicious dt { color: #020202; margin-top: 1em; margin-bottom: 1em; position: relative; font-weight: bold; } #wrapperlicious a { color: inherit; text-decoration: underline } #wrapperlicious #toc { text-decoration: none } #wrapperlicious a:hover { color: #2a2a2a } #wrapperlicious a img { border: 0 } #wrapperlicious :not(pre) > code { color: inherit; background-color: rgba(0, 0, 0, 0.04); border-radius: 3px; font: 0.9em Consolas, Menlo, Monaco, monospace; padding: 0.3em; } #wrapperlicious dd { margin: 0; margin-left: 2em; } #wrapperlicious dt { color: #2a2a2a; font-weight: bold; margin-left: 0.9em; } #wrapperlicious p { margin-bottom: 1em; margin-top: 1em; } #wrapperlicious li > p { margin-bottom: 0; margin-top: 0; } #wrapperlicious pre { border: 1px solid #c1c1c1; border-radius: 3px; font: 100% Consolas, Menlo, Monaco, monospace; margin-bottom: 1em; margin-top: 1em; } #wrapperlicious pre > code { display: block; background-color: #f6f6f6; font: 0.9em Consolas, Menlo, Monaco, monospace; line-height: 1.5em; text-align: left; white-space: pre; padding: 1em; } #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul { margin-bottom: 1em; margin-top: 1em; } #wrapperlicious ul { list-style-type: square; } #wrapperlicious ul ul { margin-bottom: 0px; margin-top: 0px; } #footer { font-size: 0.8em; padding-top: 0.5em; text-align: center; } #more { display: inline; font-size: 0.8em; } #perldocdiv { background-color: #fff; border: 1px solid #c1c1c1; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; margin-left: auto; margin-right: auto; padding: 3em; padding-top: 1em; max-width: 960px; } #moduleversion { float: right } #wrapperlicious .leading-notice { font-style: italic; padding-left: 1em; margin-top: 1em; margin-bottom: 1em; } #wrapperlicious .permalink { display: none; left: -0.75em; position: absolute; padding-right: 0.25em; text-decoration: none; } #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink, #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink, #wrapperlicious dt:hover .permalink { display: block; } </style> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-KVNWBNT5FB'); gtag('config', 'UA-50555-3'); </script> </head> <body> <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <a class="navbar-brand" href="/"><img src="/images/perl_camel_30.png" width="30" height="30" class="d-inline-block align-top" alt="Perl Camel Logo"> Perldoc Browser</a> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav mr-auto"> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.8.2</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-stable"> <a class="dropdown-item" href="/Math::Trig">Latest</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.1/Math::Trig">5.40.1</a> <a class="dropdown-item" href="/5.40.0/Math::Trig">5.40.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.38.3/Math::Trig">5.38.3</a> <a class="dropdown-item" href="/5.38.2/Math::Trig">5.38.2</a> <a class="dropdown-item" href="/5.38.1/Math::Trig">5.38.1</a> <a class="dropdown-item" href="/5.38.0/Math::Trig">5.38.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.36.3/Math::Trig">5.36.3</a> <a class="dropdown-item" href="/5.36.2/Math::Trig">5.36.2</a> <a class="dropdown-item" href="/5.36.1/Math::Trig">5.36.1</a> <a class="dropdown-item" href="/5.36.0/Math::Trig">5.36.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.34.3/Math::Trig">5.34.3</a> <a class="dropdown-item" href="/5.34.2/Math::Trig">5.34.2</a> <a class="dropdown-item" href="/5.34.1/Math::Trig">5.34.1</a> <a class="dropdown-item" href="/5.34.0/Math::Trig">5.34.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.32.1/Math::Trig">5.32.1</a> <a class="dropdown-item" href="/5.32.0/Math::Trig">5.32.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.30.3/Math::Trig">5.30.3</a> <a class="dropdown-item" href="/5.30.2/Math::Trig">5.30.2</a> <a class="dropdown-item" href="/5.30.1/Math::Trig">5.30.1</a> <a class="dropdown-item" href="/5.30.0/Math::Trig">5.30.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.28.3/Math::Trig">5.28.3</a> <a class="dropdown-item" href="/5.28.2/Math::Trig">5.28.2</a> <a class="dropdown-item" href="/5.28.1/Math::Trig">5.28.1</a> <a class="dropdown-item" href="/5.28.0/Math::Trig">5.28.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.26.3/Math::Trig">5.26.3</a> <a class="dropdown-item" href="/5.26.2/Math::Trig">5.26.2</a> <a class="dropdown-item" href="/5.26.1/Math::Trig">5.26.1</a> <a class="dropdown-item" href="/5.26.0/Math::Trig">5.26.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.24.4/Math::Trig">5.24.4</a> <a class="dropdown-item" href="/5.24.3/Math::Trig">5.24.3</a> <a class="dropdown-item" href="/5.24.2/Math::Trig">5.24.2</a> <a class="dropdown-item" href="/5.24.1/Math::Trig">5.24.1</a> <a class="dropdown-item" href="/5.24.0/Math::Trig">5.24.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.22.4/Math::Trig">5.22.4</a> <a class="dropdown-item" href="/5.22.3/Math::Trig">5.22.3</a> <a class="dropdown-item" href="/5.22.2/Math::Trig">5.22.2</a> <a class="dropdown-item" href="/5.22.1/Math::Trig">5.22.1</a> <a class="dropdown-item" href="/5.22.0/Math::Trig">5.22.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.20.3/Math::Trig">5.20.3</a> <a class="dropdown-item" href="/5.20.2/Math::Trig">5.20.2</a> <a class="dropdown-item" href="/5.20.1/Math::Trig">5.20.1</a> <a class="dropdown-item" href="/5.20.0/Math::Trig">5.20.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.18.4/Math::Trig">5.18.4</a> <a class="dropdown-item" href="/5.18.3/Math::Trig">5.18.3</a> <a class="dropdown-item" href="/5.18.2/Math::Trig">5.18.2</a> <a class="dropdown-item" href="/5.18.1/Math::Trig">5.18.1</a> <a class="dropdown-item" href="/5.18.0/Math::Trig">5.18.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.16.3/Math::Trig">5.16.3</a> <a class="dropdown-item" href="/5.16.2/Math::Trig">5.16.2</a> <a class="dropdown-item" href="/5.16.1/Math::Trig">5.16.1</a> <a class="dropdown-item" href="/5.16.0/Math::Trig">5.16.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.14.4/Math::Trig">5.14.4</a> <a class="dropdown-item" href="/5.14.3/Math::Trig">5.14.3</a> <a class="dropdown-item" href="/5.14.2/Math::Trig">5.14.2</a> <a class="dropdown-item" href="/5.14.1/Math::Trig">5.14.1</a> <a class="dropdown-item" href="/5.14.0/Math::Trig">5.14.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.12.5/Math::Trig">5.12.5</a> <a class="dropdown-item" href="/5.12.4/Math::Trig">5.12.4</a> <a class="dropdown-item" href="/5.12.3/Math::Trig">5.12.3</a> <a class="dropdown-item" href="/5.12.2/Math::Trig">5.12.2</a> <a class="dropdown-item" href="/5.12.1/Math::Trig">5.12.1</a> <a class="dropdown-item" href="/5.12.0/Math::Trig">5.12.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.10.1/Math::Trig">5.10.1</a> <a class="dropdown-item" href="/5.10.0/Math::Trig">5.10.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.8.9/Math::Trig">5.8.9</a> <a class="dropdown-item" href="/5.8.8/Math::Trig">5.8.8</a> <a class="dropdown-item" href="/5.8.7/Math::Trig">5.8.7</a> <a class="dropdown-item" href="/5.8.6/Math::Trig">5.8.6</a> <a class="dropdown-item" href="/5.8.5/Math::Trig">5.8.5</a> <a class="dropdown-item" href="/5.8.4/Math::Trig">5.8.4</a> <a class="dropdown-item" href="/5.8.3/Math::Trig">5.8.3</a> <a class="dropdown-item active" href="/5.8.2/Math::Trig">5.8.2</a> <a class="dropdown-item" href="/5.8.1/Math::Trig">5.8.1</a> <a class="dropdown-item" href="/5.8.0/Math::Trig">5.8.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.6.2/Math::Trig">5.6.2</a> <a class="dropdown-item" href="/5.6.1/Math::Trig">5.6.1</a> <a class="dropdown-item" href="/5.6.0/Math::Trig">5.6.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.005_04/Math::Trig">5.005_04</a> <a class="dropdown-item" href="/5.005_03/Math::Trig">5.005_03</a> <a class="dropdown-item" href="/5.005_02/Math::Trig">5.005_02</a> <a class="dropdown-item" href="/5.005_01/Math::Trig">5.005_01</a> <a class="dropdown-item" href="/5.005/Math::Trig">5.005</a> </div> </li> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-dev"> <a class="dropdown-item" href="/blead/Math::Trig">blead</a> <a class="dropdown-item" href="/5.41.10/Math::Trig">5.41.10</a> <a class="dropdown-item" href="/5.41.9/Math::Trig">5.41.9</a> <a class="dropdown-item" href="/5.41.8/Math::Trig">5.41.8</a> <a class="dropdown-item" href="/5.41.7/Math::Trig">5.41.7</a> <a class="dropdown-item" href="/5.41.6/Math::Trig">5.41.6</a> <a class="dropdown-item" href="/5.41.5/Math::Trig">5.41.5</a> <a class="dropdown-item" href="/5.41.4/Math::Trig">5.41.4</a> <a class="dropdown-item" href="/5.41.3/Math::Trig">5.41.3</a> <a class="dropdown-item" href="/5.41.2/Math::Trig">5.41.2</a> <a class="dropdown-item" href="/5.41.1/Math::Trig">5.41.1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.1-RC1/Math::Trig">5.40.1-RC1</a> <a class="dropdown-item" href="/5.40.0-RC2/Math::Trig">5.40.0-RC2</a> <a class="dropdown-item" href="/5.40.0-RC1/Math::Trig">5.40.0-RC1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.39.10/Math::Trig">5.39.10</a> <a class="dropdown-item" href="/5.39.9/Math::Trig">5.39.9</a> <a class="dropdown-item" href="/5.39.8/Math::Trig">5.39.8</a> <a class="dropdown-item" href="/5.39.7/Math::Trig">5.39.7</a> <a class="dropdown-item" href="/5.39.6/Math::Trig">5.39.6</a> <a class="dropdown-item" href="/5.39.5/Math::Trig">5.39.5</a> <a class="dropdown-item" href="/5.39.4/Math::Trig">5.39.4</a> <a class="dropdown-item" href="/5.39.3/Math::Trig">5.39.3</a> <a class="dropdown-item" href="/5.39.2/Math::Trig">5.39.2</a> <a class="dropdown-item" href="/5.39.1/Math::Trig">5.39.1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.38.3-RC1/Math::Trig">5.38.3-RC1</a> </div> </li> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-nav"> <a class="dropdown-item" href="/5.8.2/perl">Perl</a> <a class="dropdown-item" href="/5.8.2/perlintro">Intro</a> <a class="dropdown-item" href="/5.8.2/perl#Tutorials">Tutorials</a> <a class="dropdown-item" href="/5.8.2/perlfaq">FAQs</a> <a class="dropdown-item" href="/5.8.2/perl#Reference-Manual">Reference</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.8.2/perlop">Operators</a> <a class="dropdown-item" href="/5.8.2/functions">Functions</a> <a class="dropdown-item" href="/5.8.2/variables">Variables</a> <a class="dropdown-item" href="/5.8.2/modules">Modules</a> <a class="dropdown-item" href="/5.8.2/perlutil">Utilities</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.8.2/perldelta">Release Notes</a> <a class="dropdown-item" href="/5.8.2/perlcommunity">Community</a> <a class="dropdown-item" href="/5.8.2/perlhist">History</a> </div> </li> </ul> <ul class="navbar-nav"> <script> function set_expand (expand) { var perldocdiv = document.getElementById('perldocdiv'); var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width'); var expanded = (width == '' || width == 'none') ? true : false; if (expand === null) { expand = !expanded; } if ((expand && !expanded) || (!expand && expanded)) { perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px'); var button_classlist = document.getElementById('content-expand-button').classList; if (expand) { button_classlist.add('btn-light'); button_classlist.remove('btn-outline-light'); } else { button_classlist.add('btn-outline-light'); button_classlist.remove('btn-light'); } } return expand; } function toggle_expand () { var expand = set_expand(null); document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC'; } function read_expand () { return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 }); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', function () { if (read_expand()) { set_expand(true); } }); } else if (read_expand()) { set_expand(true); } </script> <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-4" onclick="toggle_expand()">Expand</button> </ul> <form class="form-inline" method="get" action="/5.8.2/search"> <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search" value=""> </form> </div> </nav> <div id="wrapperlicious" class="container-fluid"> <div id="perldocdiv"> <div id="links"> <a href="/5.8.2/Math::Trig">Math::Trig</a> <div id="more"> (<a href="/5.8.2/Math::Trig.txt">source</a>, <a href="https://metacpan.org/pod/Math::Trig">CPAN</a>) </div> <div id="moduleversion">version 1.02</div> </div> <div class="leading-notice"> You are viewing the version of this documentation from Perl 5.8.2. <a href="/Math::Trig">View the latest version</a> </div> <h1><a id="toc">CONTENTS</a></h1> <ul> <li> <a class="text-decoration-none" href="#NAME">NAME</a> </li> <li> <a class="text-decoration-none" href="#SYNOPSIS">SYNOPSIS</a> </li> <li> <a class="text-decoration-none" href="#DESCRIPTION">DESCRIPTION</a> </li> <li> <a class="text-decoration-none" href="#TRIGONOMETRIC-FUNCTIONS">TRIGONOMETRIC FUNCTIONS</a> <ul> <li> <a class="text-decoration-none" href="#ERRORS-DUE-TO-DIVISION-BY-ZERO">ERRORS DUE TO DIVISION BY ZERO</a> </li> <li> <a class="text-decoration-none" href="#SIMPLE-(REAL)-ARGUMENTS,-COMPLEX-RESULTS">SIMPLE (REAL) ARGUMENTS, COMPLEX RESULTS</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#PLANE-ANGLE-CONVERSIONS">PLANE ANGLE CONVERSIONS</a> </li> <li> <a class="text-decoration-none" href="#RADIAL-COORDINATE-CONVERSIONS">RADIAL COORDINATE CONVERSIONS</a> <ul> <li> <a class="text-decoration-none" href="#COORDINATE-SYSTEMS">COORDINATE SYSTEMS</a> </li> <li> <a class="text-decoration-none" href="#3-D-ANGLE-CONVERSIONS">3-D ANGLE CONVERSIONS</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#GREAT-CIRCLE-DISTANCES-AND-DIRECTIONS">GREAT CIRCLE DISTANCES AND DIRECTIONS</a> </li> <li> <a class="text-decoration-none" href="#EXAMPLES">EXAMPLES</a> <ul> <li> <a class="text-decoration-none" href="#CAVEAT-FOR-GREAT-CIRCLE-FORMULAS">CAVEAT FOR GREAT CIRCLE FORMULAS</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#BUGS">BUGS</a> </li> <li> <a class="text-decoration-none" href="#AUTHORS">AUTHORS</a> </li> </ul> <h1 id="NAME"><a class="permalink" href="#NAME">#</a>NAME</h1> <p>Math::Trig - trigonometric functions</p> <h1 id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">#</a>SYNOPSIS</h1> <pre><code>use Math::Trig; $x = tan(0.9); $y = acos(3.7); $z = asin(2.4); $halfpi = pi/2; $rad = deg2rad(120);</code></pre> <h1 id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">#</a>DESCRIPTION</h1> <p><code>Math::Trig</code> defines many trigonometric functions not defined by the core Perl which defines only the <code>sin()</code> and <code>cos()</code>. The constant <b>pi</b> is also defined as are a few convenience functions for angle conversions.</p> <h1 id="TRIGONOMETRIC-FUNCTIONS"><a class="permalink" href="#TRIGONOMETRIC-FUNCTIONS">#</a><a id="TRIGONOMETRIC"></a>TRIGONOMETRIC FUNCTIONS</h1> <p>The tangent</p> <dl> <dt id="tan"><a class="permalink" href="#tan">#</a><b>tan</b></dt> <dd> </dd> </dl> <p>The cofunctions of the sine, cosine, and tangent (cosec/csc and cotan/cot are aliases)</p> <p><b>csc</b>, <b>cosec</b>, <b>sec</b>, <b>sec</b>, <b>cot</b>, <b>cotan</b></p> <p>The arcus (also known as the inverse) functions of the sine, cosine, and tangent</p> <p><b>asin</b>, <b>acos</b>, <b>atan</b></p> <p>The principal value of the arc tangent of y/x</p> <p><b>atan2</b>(y, x)</p> <p>The arcus cofunctions of the sine, cosine, and tangent (acosec/acsc and acotan/acot are aliases)</p> <p><b>acsc</b>, <b>acosec</b>, <b>asec</b>, <b>acot</b>, <b>acotan</b></p> <p>The hyperbolic sine, cosine, and tangent</p> <p><b>sinh</b>, <b>cosh</b>, <b>tanh</b></p> <p>The cofunctions of the hyperbolic sine, cosine, and tangent (cosech/csch and cotanh/coth are aliases)</p> <p><b>csch</b>, <b>cosech</b>, <b>sech</b>, <b>coth</b>, <b>cotanh</b></p> <p>The arcus (also known as the inverse) functions of the hyperbolic sine, cosine, and tangent</p> <p><b>asinh</b>, <b>acosh</b>, <b>atanh</b></p> <p>The arcus cofunctions of the hyperbolic sine, cosine, and tangent (acsch/acosech and acoth/acotanh are aliases)</p> <p><b>acsch</b>, <b>acosech</b>, <b>asech</b>, <b>acoth</b>, <b>acotanh</b></p> <p>The trigonometric constant <b>pi</b> is also defined.</p> <p>$pi2 = 2 * <b>pi</b>;</p> <h2 id="ERRORS-DUE-TO-DIVISION-BY-ZERO"><a class="permalink" href="#ERRORS-DUE-TO-DIVISION-BY-ZERO">#</a><a id="ERRORS"></a>ERRORS DUE TO DIVISION BY ZERO</h2> <p>The following functions</p> <pre><code class="plaintext">acoth acsc acsch asec asech atanh cot coth csc csch sec sech tan tanh</code></pre> <p>cannot be computed for all arguments because that would mean dividing by zero or taking logarithm of zero. These situations cause fatal runtime errors looking like this</p> <pre><code class="plaintext">cot(0): Division by zero. (Because in the definition of cot(0), the divisor sin(0) is 0) Died at ...</code></pre> <p>or</p> <pre><code class="plaintext">atanh(-1): Logarithm of zero. Died at...</code></pre> <p>For the <code>csc</code>, <code>cot</code>, <code>asec</code>, <code>acsc</code>, <code>acot</code>, <code>csch</code>, <code>coth</code>, <code>asech</code>, <code>acsch</code>, the argument cannot be <code>0</code> (zero). For the <code>atanh</code>, <code>acoth</code>, the argument cannot be <code>1</code> (one). For the <code>atanh</code>, <code>acoth</code>, the argument cannot be <code>-1</code> (minus one). For the <code>tan</code>, <code>sec</code>, <code>tanh</code>, <code>sech</code>, the argument cannot be <i>pi/2 + k * pi</i>, where <i>k</i> is any integer.</p> <h2 id="SIMPLE-(REAL)-ARGUMENTS,-COMPLEX-RESULTS"><a class="permalink" href="#SIMPLE-(REAL)-ARGUMENTS,-COMPLEX-RESULTS">#</a><a id="SIMPLE"></a><a id="SIMPLE-REAL-ARGUMENTS-COMPLEX-RESULTS"></a>SIMPLE (REAL) ARGUMENTS, COMPLEX RESULTS</h2> <p>Please note that some of the trigonometric functions can break out from the <b>real axis</b> into the <b>complex plane</b>. For example <code>asin(2)</code> has no definition for plain real numbers but it has definition for complex numbers.</p> <p>In Perl terms this means that supplying the usual Perl numbers (also known as scalars, please see <a href="/5.8.2/perldata">perldata</a>) as input for the trigonometric functions might produce as output results that no more are simple real numbers: instead they are complex numbers.</p> <p>The <code>Math::Trig</code> handles this by using the <code>Math::Complex</code> package which knows how to handle complex numbers, please see <a href="/5.8.2/Math::Complex">Math::Complex</a> for more information. In practice you need not to worry about getting complex numbers as results because the <code>Math::Complex</code> takes care of details like for example how to display complex numbers. For example:</p> <pre><code>print asin(2), &quot;\n&quot;;</code></pre> <p>should produce something like this (take or leave few last decimals):</p> <pre><code class="plaintext">1.5707963267949-1.31695789692482i</code></pre> <p>That is, a complex number with the real part of approximately <code>1.571</code> and the imaginary part of approximately <code>-1.317</code>.</p> <h1 id="PLANE-ANGLE-CONVERSIONS"><a class="permalink" href="#PLANE-ANGLE-CONVERSIONS">#</a><a id="PLANE"></a>PLANE ANGLE CONVERSIONS</h1> <p>(Plane, 2-dimensional) angles may be converted with the following functions.</p> <pre><code>$radians = deg2rad($degrees); $radians = grad2rad($gradians); $degrees = rad2deg($radians); $degrees = grad2deg($gradians); $gradians = deg2grad($degrees); $gradians = rad2grad($radians);</code></pre> <p>The full circle is 2 <i>pi</i> radians or <i>360</i> degrees or <i>400</i> gradians. The result is by default wrapped to be inside the [0, {2pi,360,400}[ circle. If you don&#39;t want this, supply a true second argument:</p> <pre><code>$zillions_of_radians = deg2rad($zillions_of_degrees, 1); $negative_degrees = rad2deg($negative_radians, 1);</code></pre> <p>You can also do the wrapping explicitly by rad2rad(), deg2deg(), and grad2grad().</p> <h1 id="RADIAL-COORDINATE-CONVERSIONS"><a class="permalink" href="#RADIAL-COORDINATE-CONVERSIONS">#</a><a id="RADIAL"></a>RADIAL COORDINATE CONVERSIONS</h1> <p><b>Radial coordinate systems</b> are the <b>spherical</b> and the <b>cylindrical</b> systems, explained shortly in more detail.</p> <p>You can import radial coordinate conversion functions by using the <code>:radial</code> tag:</p> <pre><code>use Math::Trig &#39;:radial&#39;; ($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);</code></pre> <p><b>All angles are in radians</b>.</p> <h2 id="COORDINATE-SYSTEMS"><a class="permalink" href="#COORDINATE-SYSTEMS">#</a><a id="COORDINATE"></a>COORDINATE SYSTEMS</h2> <p><b>Cartesian</b> coordinates are the usual rectangular <i>(x, y, z)</i>-coordinates.</p> <p>Spherical coordinates, <i>(rho, theta, pi)</i>, are three-dimensional coordinates which define a point in three-dimensional space. They are based on a sphere surface. The radius of the sphere is <b>rho</b>, also known as the <i>radial</i> coordinate. The angle in the <i>xy</i>-plane (around the <i>z</i>-axis) is <b>theta</b>, also known as the <i>azimuthal</i> coordinate. The angle from the <i>z</i>-axis is <b>phi</b>, also known as the <i>polar</i> coordinate. The `North Pole&#39; is therefore <i>0, 0, rho</i>, and the `Bay of Guinea&#39; (think of the missing big chunk of Africa) <i>0, pi/2, rho</i>. In geographical terms <i>phi</i> is latitude (northward positive, southward negative) and <i>theta</i> is longitude (eastward positive, westward negative).</p> <p><b>BEWARE</b>: some texts define <i>theta</i> and <i>phi</i> the other way round, some texts define the <i>phi</i> to start from the horizontal plane, some texts use <i>r</i> in place of <i>rho</i>.</p> <p>Cylindrical coordinates, <i>(rho, theta, z)</i>, are three-dimensional coordinates which define a point in three-dimensional space. They are based on a cylinder surface. The radius of the cylinder is <b>rho</b>, also known as the <i>radial</i> coordinate. The angle in the <i>xy</i>-plane (around the <i>z</i>-axis) is <b>theta</b>, also known as the <i>azimuthal</i> coordinate. The third coordinate is the <i>z</i>, pointing up from the <b>theta</b>-plane.</p> <h2 id="3-D-ANGLE-CONVERSIONS"><a class="permalink" href="#3-D-ANGLE-CONVERSIONS">#</a><a id="3"></a><a id="D-ANGLE-CONVERSIONS"></a>3-D ANGLE CONVERSIONS</h2> <p>Conversions to and from spherical and cylindrical coordinates are available. Please notice that the conversions are not necessarily reversible because of the equalities like <i>pi</i> angles being equal to <i>-pi</i> angles.</p> <dl> <dt id="cartesian_to_cylindrical"><a class="permalink" href="#cartesian_to_cylindrical">#</a>cartesian_to_cylindrical</dt> <dd> <pre><code>($rho, $theta, $z) = cartesian_to_cylindrical($x, $y, $z);</code></pre> </dd> <dt id="cartesian_to_spherical"><a class="permalink" href="#cartesian_to_spherical">#</a>cartesian_to_spherical</dt> <dd> <pre><code>($rho, $theta, $phi) = cartesian_to_spherical($x, $y, $z);</code></pre> </dd> <dt id="cylindrical_to_cartesian"><a class="permalink" href="#cylindrical_to_cartesian">#</a>cylindrical_to_cartesian</dt> <dd> <pre><code>($x, $y, $z) = cylindrical_to_cartesian($rho, $theta, $z);</code></pre> </dd> <dt id="cylindrical_to_spherical"><a class="permalink" href="#cylindrical_to_spherical">#</a>cylindrical_to_spherical</dt> <dd> <pre><code>($rho_s, $theta, $phi) = cylindrical_to_spherical($rho_c, $theta, $z);</code></pre> <p>Notice that when <code>$z</code> is not 0 <code>$rho_s</code> is not equal to <code>$rho_c</code>.</p> </dd> <dt id="spherical_to_cartesian"><a class="permalink" href="#spherical_to_cartesian">#</a>spherical_to_cartesian</dt> <dd> <pre><code>($x, $y, $z) = spherical_to_cartesian($rho, $theta, $phi);</code></pre> </dd> <dt id="spherical_to_cylindrical"><a class="permalink" href="#spherical_to_cylindrical">#</a>spherical_to_cylindrical</dt> <dd> <pre><code>($rho_c, $theta, $z) = spherical_to_cylindrical($rho_s, $theta, $phi);</code></pre> <p>Notice that when <code>$z</code> is not 0 <code>$rho_c</code> is not equal to <code>$rho_s</code>.</p> </dd> </dl> <h1 id="GREAT-CIRCLE-DISTANCES-AND-DIRECTIONS"><a class="permalink" href="#GREAT-CIRCLE-DISTANCES-AND-DIRECTIONS">#</a><a id="GREAT"></a>GREAT CIRCLE DISTANCES AND DIRECTIONS</h1> <p>You can compute spherical distances, called <b>great circle distances</b>, by importing the great_circle_distance() function:</p> <pre><code>use Math::Trig &#39;great_circle_distance&#39;; $distance = great_circle_distance($theta0, $phi0, $theta1, $phi1, [, $rho]);</code></pre> <p>The <i>great circle distance</i> is the shortest distance between two points on a sphere. The distance is in <code>$rho</code> units. The <code>$rho</code> is optional, it defaults to 1 (the unit sphere), therefore the distance defaults to radians.</p> <p>If you think geographically the <i>theta</i> are longitudes: zero at the Greenwhich meridian, eastward positive, westward negative--and the <i>phi</i> are latitudes: zero at the North Pole, northward positive, southward negative. <b>NOTE</b>: this formula thinks in mathematics, not geographically: the <i>phi</i> zero is at the North Pole, not at the Equator on the west coast of Africa (Bay of Guinea). You need to subtract your geographical coordinates from <i>pi/2</i> (also known as 90 degrees).</p> <pre><code>$distance = great_circle_distance($lon0, pi/2 - $lat0, $lon1, pi/2 - $lat1, $rho);</code></pre> <p>The direction you must follow the great circle can be computed by the great_circle_direction() function:</p> <pre><code>use Math::Trig &#39;great_circle_direction&#39;; $direction = great_circle_direction($theta0, $phi0, $theta1, $phi1);</code></pre> <p>The result is in radians, zero indicating straight north, pi or -pi straight south, pi/2 straight west, and -pi/2 straight east.</p> <p>Notice that the resulting directions might be somewhat surprising if you are looking at a flat worldmap: in such map projections the great circles quite often do not look like the shortest routes-- but for example the shortest possible routes from Europe or North America to Asia do often cross the polar regions.</p> <h1 id="EXAMPLES"><a class="permalink" href="#EXAMPLES">#</a>EXAMPLES</h1> <p>To calculate the distance between London (51.3N 0.5W) and Tokyo (35.7N 139.8E) in kilometers:</p> <pre><code> use Math::Trig qw(great_circle_distance deg2rad); # Notice the 90 - latitude: phi zero is at the North Pole. @L = (deg2rad(-0.5), deg2rad(90 - 51.3)); @T = (deg2rad(139.8),deg2rad(90 - 35.7)); $km = great_circle_distance(@L, @T, 6378);</code></pre> <p>The direction you would have to go from London to Tokyo</p> <pre><code>use Math::Trig qw(great_circle_direction); $rad = great_circle_direction(@L, @T);</code></pre> <h2 id="CAVEAT-FOR-GREAT-CIRCLE-FORMULAS"><a class="permalink" href="#CAVEAT-FOR-GREAT-CIRCLE-FORMULAS">#</a><a id="CAVEAT"></a>CAVEAT FOR GREAT CIRCLE FORMULAS</h2> <p>The answers may be off by few percentages because of the irregular (slightly aspherical) form of the Earth. The formula used for grear circle distances</p> <pre><code class="plaintext"> lat0 = 90 degrees - phi0 lat1 = 90 degrees - phi1 d = R * arccos(cos(lat0) * cos(lat1) * cos(lon1 - lon01) + sin(lat0) * sin(lat1))</code></pre> <p>is also somewhat unreliable for small distances (for locations separated less than about five degrees) because it uses arc cosine which is rather ill-conditioned for values close to zero.</p> <h1 id="BUGS"><a class="permalink" href="#BUGS">#</a>BUGS</h1> <p>Saying <code>use Math::Trig;</code> exports many mathematical routines in the caller environment and even overrides some (<code>sin</code>, <code>cos</code>). This is construed as a feature by the Authors, actually... ;-)</p> <p>The code is not optimized for speed, especially because we use <code>Math::Complex</code> and thus go quite near complex numbers while doing the computations even when the arguments are not. This, however, cannot be completely avoided if we want things like <code>asin(2)</code> to give an answer instead of giving a fatal runtime error.</p> <h1 id="AUTHORS"><a class="permalink" href="#AUTHORS">#</a>AUTHORS</h1> <p>Jarkko Hietaniemi &lt;<i>jhi@iki.fi</i>&gt; and Raphael Manfredi &lt;<i>Raphael_Manfredi@pobox.com</i>&gt;.</p> </div> <div id="footer"> <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p> <p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p> </div> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script> <script src="/js/highlight.pack.js"></script> <script>hljs.highlightAll();</script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10