Compute, phi4, the latitude for the inverse of the
Polyconic projection.
485372
protected function phi4z($eccent, $e0, $e1, $e2, $e3, $a, $b, &$c, $phi)
    {
        /*
        $sinphi;
        $sin2ph;
        $tanph;
        $ml;
        $mlp;
        $con1;
        $con2;
        $con3;
        $dphi;
        $i;
        */

        $phi = $a;
        for ($i = 1; $i <= 15; $i++) {
            $sinphi = sin( $phi );
            $tanphi = tan( $phi );
            $c = $tanphi * sqrt( 1.0 - $eccent * $sinphi * $sinphi );
            $sin2ph = sin( 2.0 * $phi );
            /*
              ml = e0 * *phi - e1 * sin2ph + e2 * sin (4.0 *  *phi);
              mlp = e0 - 2.0 * e1 * cos (2.0 *  *phi) + 4.0 * e2 *  cos (4.0 *  *phi);
             */
            $ml = $e0 * $phi - $e1 * $sin2ph + $e2 * sin( 4.0 * $phi ) - $e3 * sin( 6.0 * $phi );
            $mlp = $e0 - 2.0 * $e1 * cos( 2.0 * $phi ) + 4.0 * $e2 * cos( 4.0 * $phi ) - 6.0 * $e3 * cos( 6.0 * $phi );
            $con1 = 2.0 * $ml + $c * ($ml * $ml + $b) - 2.0 * $a * ($c * $ml + 1.0);
            $con2 = $eccent * $sin2ph * ($ml * $ml + $b - 2.0 * $a * $ml) / (2.0 * $c);
            $con3 = 2.0 * ($a - $ml) * ($c * $mlp - 2.0 / $sin2ph) - 2.0 * $mlp;
            $dphi = $con1 / ($con2 + $con3);
            $phi += $dphi;

            if ( abs( $dphi ) <= .0000000001 ) {
                return($phi);
            }
        }

        Proj4php::reportError('phi4z: No convergence');

        return null;
    }
117226
public function inverse($p)
    {
        /*
        $delta_lon; /* Delta longitude (Given longitude - center 
        $theta;  /* angle
        $delta_theta; /* adjusted longitude
        $sin_phi;
        $cos_phi; /* sin and cos value	
        $b;  /* temporary values
        $c;
        $t;
        $tq; /* temporary values
        $con;
        $n;
        $ml; /* cone constant, small m	
        $vs;
        $us;
        $q;
        $s;
        $ts1;
        $vl;
        $ul;
        $bs;
        $dlon;
        $flag;
        */

        $p->x -= $this->x0;
        $p->y -= $this->y0;
        #$flag = 0;

        $vs = $p->x * $this->cosaz - $p->y * $this->sinaz;
        $us = $p->y * $this->cosaz + $p->x * $this->sinaz;
        $us = $us + $this->u;

        $q = exp( -$this->bl * $vs / $this->al );
        $s = .5 * ($q - 1.0 / $q);
        $t = .5 * ($q + 1.0 / $q);

        $vl = sin( $this->bl * $us / $this->al );
        $ul = ($vl * $this->cosgam + $s * $this->singam) / $t;

        if (abs(abs($ul) - 1.0) <= Common::EPSLN) {
            $lon = $this->longc;
            if (ul >= 0.0) {
                $lat = Common::HALF_PI;
            } else {
                $lat = -Common::HALF_PI;
            }
        } else {
            $con = 1.0 / $this->bl;
            $ts1 = pow( ($this->el / sqrt( (1.0 + $ul) / (1.0 - $ul) ) ), $con );
            $lat = Common::phi2z( $this->e, $ts1 );
            //if ($flag != 0)
            //return($flag);
            //~ con = cos($this->bl * us /al);
            $theta = $this->longc - atan2( ($s * $this->cosgam - $vl * $this->singam ), $con ) / $this->bl;
            $lon = Common::adjust_lon( $theta );
        }

        $p->x = $lon;
        $p->y = $lat;

        return $p;
    }
454136
function inverse$10(p) {
        var u, deltav, s, d, eps, ro, fi1;
        var ok;

        /* Transformation */
        /* revert y, x*/
        var tmp = p.x;
        p.x = p.y;
        p.y = tmp;
        if (!this.czech) {
            p.y *= -1;
            p.x *= -1;
        }
        ro = Math.sqrt(p.x * p.x + p.y * p.y);
        eps = Math.atan2(p.y, p.x);
        d = eps / Math.sin(this.s0);
        s = 2 * (Math.atan(Math.pow(this.ro0 / ro, 1 / this.n) * Math.tan(this.s0 / 2 + this.s45)) - this.s45);
        u = Math.asin(Math.cos(this.ad) * Math.sin(s) - Math.sin(this.ad) * Math.cos(s) * Math.cos(d));
        deltav = Math.asin(Math.cos(s) * Math.sin(d) / Math.cos(u));
        p.x = this.long0 - deltav / this.alfa;
        fi1 = u;
        ok = 0;
        var iter = 0;
        do {
            p.y = 2 * (Math.atan(Math.pow(this.k, - 1 / this.alfa) * Math.pow(Math.tan(u / 2 + this.s45), 1 / this.alfa) * Math.pow((1 + this.e * Math.sin(fi1)) / (1 - this.e * Math.sin(fi1)), this.e / 2)) - this.s45);
            if (Math.abs(fi1 - p.y) < 0.0000000001) {
                ok = 1;
            }
            fi1 = p.y;
            iter += 1;
        } while (ok === 0 && iter < 15);
        if (iter >= 15) {
            return null;
        }

        return (p);
    }
1304977
def spin1y_from_xi1_phi_a_phi_s(xi1, phi_a, phi_s):
    
    phi1 = phi1_from_phi_a_phi_s(phi_s, phi_a)
    return xi1 * numpy.sin(phi1)
171523
def pole(conic, plane):
        
        v = dot(N.linalg.inv(conic),plane)
        return v[:-1]/v[-1]
967365
function computeMirrorDimensions({source, ...args}) {
  return withPromise((resolve) => {
    const sourceRect = source.getBoundingClientRect();
    resolve({source, sourceRect, ...args});
  });
}
48284
def _phi2deriv(self,R,phi=0.,t=0.):
        
        return self._Pot.phi2deriv(R,0.,phi=phi,t=t,use_physical=False)
1038308
function(p,phi,theta) {
        var r = 0;
        r += Math.pow(mathUtils.sin(this.m[0] * theta), this.m[1]);
        r += Math.pow(mathUtils.cos(this.m[2] * theta), this.m[3]);
        r += Math.pow(mathUtils.sin(this.m[4] * phi), this.m[5]);
        r += Math.pow(mathUtils.cos(this.m[6] * phi), this.m[7]);

        var sinTheta = mathUtils.sin(theta);
        p.x = r * sinTheta * mathUtils.cos(phi);
        p.y = r * mathUtils.cos(theta);
        p.z = r * sinTheta * mathUtils.sin(phi);
        return p;
    }
458987
def spherical(cls, mag, theta, phi=0):
        ''''''
        return cls(
            mag * math.sin(phi) * math.cos(theta),  # X
            mag * math.sin(phi) * math.sin(theta),  # Y
            mag * math.cos(phi)  # Z
        )
342266
function inverse$17(p) {
        var lon, lat, x, y, i;
        var al, bl;
        var phi, dphi;
        x = p.x - this.x0;
        y = p.y - this.y0;

        if (this.sphere) {
            if (Math.abs(y + this.a * this.lat0) <= EPSLN) {
                lon = adjust_lon(x / this.a + this.long0);
                lat = 0;
            }
            else {
                al = this.lat0 + y / this.a;
                bl = x * x / this.a / this.a + al * al;
                phi = al;
                var tanphi;
                for (i = MAX_ITER$2; i; --i) {
                    tanphi = Math.tan(phi);
                    dphi = -1 * (al * (phi * tanphi + 1) - phi - 0.5 * (phi * phi + bl) * tanphi) / ((phi - al) / tanphi - 1);
                    phi += dphi;
                    if (Math.abs(dphi) <= EPSLN) {
                        lat = phi;
                        break;
                    }
                }
                lon = adjust_lon(this.long0 + (Math.asin(x * Math.tan(phi) / this.a)) / Math.sin(lat));
            }
        }
        else {
            if (Math.abs(y + this.ml0) <= EPSLN) {
                lat = 0;
                lon = adjust_lon(this.long0 + x / this.a);
            }
            else {

                al = (this.ml0 + y) / this.a;
                bl = x * x / this.a / this.a + al * al;
                phi = al;
                var cl, mln, mlnp, ma;
                var con;
                for (i = MAX_ITER$2; i; --i) {
                    con = this.e * Math.sin(phi);
                    cl = Math.sqrt(1 - con * con) * Math.tan(phi);
                    mln = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, phi);
                    mlnp = this.e0 - 2 * this.e1 * Math.cos(2 * phi) + 4 * this.e2 * Math.cos(4 * phi) - 6 * this.e3 * Math.cos(6 * phi);
                    ma = mln / this.a;
                    dphi = (al * (cl * ma + 1) - ma - 0.5 * cl * (ma * ma + bl)) / (this.es * Math.sin(2 * phi) * (ma * ma + bl - 2 * al * ma) / (4 * cl) + (al - ma) * (cl * mlnp - 2 / Math.sin(2 * phi)) - mlnp);
                    phi -= dphi;
                    if (Math.abs(dphi) <= EPSLN) {
                        lat = phi;
                        break;
                    }
                }

                //lat=phi4z(this.e,this.e0,this.e1,this.e2,this.e3,al,bl,0,0);
                cl = Math.sqrt(1 - this.es * Math.pow(Math.sin(lat), 2)) * Math.tan(lat);
                lon = adjust_lon(this.long0 + Math.asin(x * cl / this.a) / Math.sin(lat));
            }
        }

        p.x = lon;
        p.y = lat;
        return p;
    }
1044962
def _linear_inverse_kamb(cos_dist, sigma=3):
    """"""
    n = float(cos_dist.size)
    radius = _kamb_radius(n, sigma)
    f = 2 / (1 - radius)
    cos_dist = cos_dist[cos_dist >= radius]
    count = (f * (cos_dist - radius))
    return count, _kamb_units(n, radius)
219600
def _cartesian_to_spherical(cls, coord, center):
        
        x, y, z, vx, vy, vz = coord
        r = np.linalg.norm(coord[:3])
        phi = arcsin(z / r)
        theta = arctan2(y, x)

        r_dot = (x * vx + y * vy + z * vz) / r
        phi_dot = (vz * (x ** 2 + y ** 2) - z * (x * vx + y * vy)) / (r ** 2 * sqrt(x ** 2 + y ** 2))
        theta_dot = (x * vy - y * vx) / (x ** 2 + y ** 2)

        return np.array([r, theta, phi, r_dot, theta_dot, phi_dot], dtype=float)
128386
public function inverse($p) {
        $p->x -= $this->x0;
        $p->y -= $this->y0;
        $x = $p->x / $this->a;
        $y = $p->y / $this->a;

        if( $this->sphere ) {
            $cosz = 0.0;
            #$rh;
            $sinz = 0.0;

            $rh = sqrt(($x * $x) + ($y * $y));
            $phi = $rh * 0.5;

            if ($phi > 1.0) {
                Proj4php::reportError('laea:Inv:DataError');
                return null;
            }

            $phi = 2. * asin( $phi );

            if ($this->mode == $this->OBLIQ || $this->mode == $this->EQUIT) {
                $sinz = sin($phi);
                $cosz = cos($phi);
            }
            switch( $this->mode ) {
                case $this->EQUIT:
                    $phi = (abs( $rh ) <= Common::EPSLN) ? 0. : asin( $y * $sinz / $rh );
                    $x *= $sinz;
                    $y = $cosz * $rh;
                    break;
                case $this->OBLIQ:
                    $phi = (abs( $rh ) <= Common::EPSLN) ? $this->phi0 : asin( $cosz * $this->sinph0 + $y * $sinz * $this->cosph0 / $rh );
                    $x *= $sinz * $this->cosph0;
                    $y = ($cosz - sin( $phi ) * $this->sinph0) * $rh;
                    break;
                case $this->N_POLE:
                    $y = -$y;
                    $phi = Common::HALF_PI - $phi;
                    break;
                case $this->S_POLE:
                    $phi -= Common::HALF_PI;
                    break;
            }

            $lam = ($y == 0.0 && ($this->mode == $this->EQUIT || $this->mode == $this->OBLIQ)) ? 0. : atan2($x, $y);
        } else {
            /*
            $cCe;
            $sCe;
            $q;
            $rho;
            */
            $ab = 0.0;

            switch($this->mode) {
                case $this->EQUIT:
                case $this->OBLIQ:
                    $x /= $this->dd;
                    $y *= $this->dd;
                    $rho = sqrt( $x * $x + $y * $y );

                    if ($rho < Common::EPSLN) {
                        $p->x = 0.;
                        $p->y = $this->phi0;
                        return $p;
                    }

                    $sCe = 2. * asin( .5 * $rho / $this->rq );
                    $cCe = cos( $sCe );
                    $x *= ($sCe = sin($sCe));

                    if ($this->mode == $this->OBLIQ) {
                        $ab = $cCe * $this->sinb1 + $y * $sCe * $this->cosb1 / $rho;
                        $q = $this->qp * $ab;
                        $y = $rho * $this->cosb1 * $cCe - $y * $this->sinb1 * $sCe;
                    } else {
                        $ab = $y * $sCe / $rho;
                        $q = $this->qp * $ab;
                        $y = $rho * $cCe;
                    }
                    break;
                case $this->N_POLE:
                    $y = -$y;
                case $this->S_POLE:
                    $q = ($x * $x + $y * $y);

                    if ( ! $q) {
                        $p->x = 0.;
                        $p->y = $this->phi0;
                        return $p;
                    }
                    /*
                      q = $this->qp - q;
                     */
                    $ab = 1.0 - $q / $this->qp;

                    if ($this->mode == $this->S_POLE) {
                        $ab = - $ab;
                    }
                    break;
            }
            $lam = atan2($x, $y);
            $phi = $this->authlat(asin($ab), $this->apa);
        }

        /*
          $Rh = sqrt($p->x *$p->x +$p->y * $p->y);
          $temp = Rh / (2.0 * $this->a);

          if (temp > 1) {
          Proj4php::reportError("laea:Inv:DataError");
          return null;
          }

          $z = 2.0 * Common::asinz(temp);
          $sin_z=sin(z);
          $cos_z=cos(z);

          $lon =$this->long0;
          if (abs(Rh) > Common::EPSLN) {
          $lat = Common::asinz($this->sin_lat_o * cos_z +$this-> cos_lat_o * sin_z *$p->y / Rh);
          $temp =abs($this->lat0) - Common::HALF_PI;
          if (abs(temp) > Common::EPSLN) {
          temp = cos_z -$this->sin_lat_o * sin(lat);
          if(temp!=0.0) lon=Common::adjust_lon($this->long0+atan2($p->x*sin_z*$this->cos_lat_o,temp*Rh));
          } else if ($this->lat0 < 0.0) {
          lon = Common::adjust_lon($this->long0 - atan2(-$p->x,$p->y));
          } else {
          lon = Common::adjust_lon($this->long0 + atan2($p->x, -$p->y));
          }
          } else {
          lat = $this->lat0;
          }
         */
        //return(OK);
        $p->x = Common::adjust_lon($this->long0 + $lam);
        $p->y = $phi;
        return $p;
    }
1306349
def direction(theta, phi):
    '''
    '''
    return np.array([np.cos(phi) * np.sin(theta), np.sin(phi) * np.sin(theta),
                     np.cos(theta)])
144988
function(p) {

            p = new Point(p);

            // Invert the y-axis.
            var y = -(p.y - this.y);
            var x = p.x - this.x;
            var rad = atan2(y, x); // defined for all 0 corner cases

            // Correction for III. and IV. quadrant.
            if (rad < 0) {
                rad = 2 * PI + rad;
            }

            return 180 * rad / PI;
        }
1243387
function inverse$11(p) {
        p.x -= this.x0;
        p.y -= this.y0;
        var x = p.x / this.a;
        var y = p.y / this.a;
        var phi, lam;

        if (this.sphere) {
            var dd = y + this.lat0;
            phi = Math.asin(Math.sin(dd) * Math.cos(x));
            lam = Math.atan2(Math.tan(x), Math.cos(dd));
        }
        else {
            /* ellipsoid */
            var ml1 = this.ml0 / this.a + y;
            var phi1 = imlfn(ml1, this.e0, this.e1, this.e2, this.e3);
            if (Math.abs(Math.abs(phi1) - HALF_PI) <= EPSLN) {
                p.x = this.long0;
                p.y = HALF_PI;
                if (y < 0) {
                    p.y *= -1;
                }
                return p;
            }
            var nl1 = gN(this.a, this.e, Math.sin(phi1));

            var rl1 = nl1 * nl1 * nl1 / this.a / this.a * (1 - this.es);
            var tl1 = Math.pow(Math.tan(phi1), 2);
            var dl = x * this.a / nl1;
            var dsq = dl * dl;
            phi = phi1 - nl1 * Math.tan(phi1) / rl1 * dl * dl * (0.5 - (1 + 3 * tl1) * dl * dl / 24);
            lam = dl * (1 - dsq * (tl1 / 3 + (1 + 3 * tl1) * tl1 * dsq / 15)) / Math.cos(phi1);

        }

        p.x = adjust_lon(lam + this.long0);
        p.y = adjust_lat(phi);
        return p;

    }
363963
def inverseDeg!(point)
      inverse!(point)
      point.x *= Proj4::RAD_TO_DEG
      point.y *= Proj4::RAD_TO_DEG
      point
    end