Scalar MASA::ad_cns_2d_crossterms<Scalar>::eval_exact_p(Scalar x, Scalar y)
{
  using std::cos;

  Scalar P = p_0 + p_x * cos(a_px * PI * x / L) * p_y * cos(a_py * PI * y / L);
  return P;
}
Exemple #2
0
/*!
 * Convert X, Y, Z in wgs84 to longitude, latitude, height
 * @param[in] x in meter
 * @param[in] y in meter
 * @param[in] z in meter
 * @return llh vector<double> contains longitude, latitude, height
 */
vector<double> ecef2llh(const double& x, const double& y, const double& z)
{
        double longitude {0.0}; /*< longitude in radian */
        double latitude {0.0}; /*< latitude in radian */
        double height {0.0}; /*< height in meter */

        double p = sqrt((x * x) + (y * y));
        double theta = atan2((z * A), (p * B));

        /* Avoid 0 division error */
        if(x == 0.0 && y == 0.0) {
                vector<double>
                llh {0.0, copysign(90.0,z), z - copysign(B,z)};
                return llh;
        } else {

                latitude = atan2(
                                   (z + (Er * Er * B * pow(sin(theta), 3))),
                                   (p - (E * E * A * pow(cos(theta), 3)))
                           );
                longitude = atan2(y, x);
                double n = A / sqrt(1.0 - E * E * sin(latitude) * sin(latitude));
                height = p / cos(latitude) - n;

                vector<double>
                llh {toDeg(longitude), toDeg(latitude), height};

                return llh;
        }
}
Exemple #3
0
TEST(AgradFwdTan, FvarFvarVar_2ndDeriv) {
  using stan::agrad::fvar;
  using stan::agrad::var;
  using std::tan;
  using std::cos;

  fvar<fvar<var> > x;
  x.val_.val_ = 1.5;
  x.val_.d_ = 2.0;

  fvar<fvar<var> > a = tan(x);

  AVEC p = createAVEC(x.val_.val_);
  VEC g;
  a.val_.d_.grad(p,g);
  EXPECT_FLOAT_EQ(2.0 * 2.0 * tan(1.5) / (cos(1.5) * cos(1.5)), g[0]);

  fvar<fvar<var> > y;
  y.val_.val_ = 1.5;
  y.d_.val_ = 2.0;

  fvar<fvar<var> > b = tan(y);

  AVEC q = createAVEC(y.val_.val_);
  VEC r;
  b.d_.val_.grad(q,r);
  EXPECT_FLOAT_EQ(2.0 * 2.0 * tan(1.5) / (cos(1.5) * cos(1.5)), r[0]);
}
Exemple #4
0
array<vector<vec3>, NUM_HORIZONTAL_SLICES_SPHERE> Shapes::Sphere::calculatePoints()
{
	constexpr float sliceDiff = static_cast<float>(PI) / static_cast<float>(NUM_HORIZONTAL_SLICES_SPHERE);
	constexpr float vertSliceDiff = static_cast<float>(TWOPI) / static_cast<float>(NUM_VERTICAL_SLICES_SPHERE);
	printf("sliceDiff:%f\nvertSlideDiff:%f\n", sliceDiff, vertSliceDiff);
	float x = 0.0f;
	float z = 0.0f;
	float y = 0.0f;
	float phi = static_cast<float>(PI) / 4.0f;
	float theta;
	array<vector<vec3>, NUM_HORIZONTAL_SLICES_SPHERE> horizontalCircles;
	//move down the sphere
	for (size_t i = 0;i < NUM_HORIZONTAL_SLICES_SPHERE;i++)
	{
		phi -= sliceDiff;
		vector<vec3> curCircle;
		theta = 0.0f;
		//move around the vertical axis calculating points
		for (size_t j = 0;j < NUM_VERTICAL_SLICES_SPHERE;j++)
		{
			x = cos(theta)*sin(phi);
			y = cos(phi);
			z = sin(theta)*sin(phi);
			curCircle.emplace_back(vec3(x, y, z));
			theta += vertSliceDiff;
		}
		horizontalCircles[i] = move(curCircle);
	}
	return horizontalCircles;
}
Exemple #5
0
 inline
 fvar<T>
 tan(const fvar<T>& x) {
   using std::cos;
   using std::tan;
   return fvar<T>(tan(x.val_), x.d_ / (cos(x.val_) * cos(x.val_)));
 }
Exemple #6
0
TEST(AgradFwdTan, FvarFvarDouble) {
  using stan::agrad::fvar;
  using std::tan;
  using std::cos;

  fvar<fvar<double> > x;
  x.val_.val_ = 1.5;
  x.val_.d_ = 2.0;

  fvar<fvar<double> > a = tan(x);

  EXPECT_FLOAT_EQ(tan(1.5), a.val_.val_);
  EXPECT_FLOAT_EQ(2.0 / (cos(1.5) * cos(1.5)), a.val_.d_);
  EXPECT_FLOAT_EQ(0, a.d_.val_);
  EXPECT_FLOAT_EQ(0, a.d_.d_);

  fvar<fvar<double> > y;
  y.val_.val_ = 1.5;
  y.d_.val_ = 2.0;

  a = tan(y);
  EXPECT_FLOAT_EQ(tan(1.5), a.val_.val_);
  EXPECT_FLOAT_EQ(0, a.val_.d_);
  EXPECT_FLOAT_EQ(2.0 / (cos(1.5) * cos(1.5)), a.d_.val_);
  EXPECT_FLOAT_EQ(0, a.d_.d_);
}
Exemple #7
0
TEST(AgradFwdCos,FvarFvarDouble) {
  using stan::agrad::fvar;
  using std::sin;
  using std::cos;

  fvar<fvar<double> > x;
  x.val_.val_ = 1.5;
  x.val_.d_ = 2.0;

  fvar<fvar<double> > a = cos(x);

  EXPECT_FLOAT_EQ(cos(1.5), a.val_.val_);
  EXPECT_FLOAT_EQ(-2.0 * sin(1.5), a.val_.d_);
  EXPECT_FLOAT_EQ(0, a.d_.val_);
  EXPECT_FLOAT_EQ(0, a.d_.d_);

  fvar<fvar<double> > y;
  y.val_.val_ = 1.5;
  y.d_.val_ = 2.0;

  a = cos(y);
  EXPECT_FLOAT_EQ(cos(1.5), a.val_.val_);
  EXPECT_FLOAT_EQ(0, a.val_.d_);
  EXPECT_FLOAT_EQ(-2.0 * sin(1.5), a.d_.val_);
  EXPECT_FLOAT_EQ(0, a.d_.d_);
}
Scalar MASA::ad_cns_2d_crossterms<Scalar>::eval_exact_rho(Scalar x, Scalar y)
{
  using std::cos;

  Scalar RHO = rho_0 + rho_x * cos(a_rhox * PI * x / L) * rho_y * cos(a_rhoy * PI * y / L);
  return RHO;
}
Exemple #9
0
static inline
Scalar varying_data(const Scalar& x, const Scalar& L)
{
    using boost::math::constants::pi;
    using std::cos;
    const Scalar twopi_L = 2*pi<Scalar>()/L;
    return cos(twopi_L*(x + 2*cos(twopi_L*3*x)));
}
Exemple #10
0
Scalar MASA::ad_cns_2d_crossterms<Scalar>::eval_exact_u(Scalar x, Scalar y)
{
  using std::cos;

  Scalar exact_u;
  exact_u = u_0 + u_x * cos(a_ux * PI * x / L) * u_y * cos(a_uy * PI * y / L);
  return exact_u;
}
Exemple #11
0
Scalar MASA::ad_cns_2d_crossterms<Scalar>::eval_exact_v(Scalar x, Scalar y)
{
  using std::cos;

  Scalar exact_v;
  exact_v = v_0 + v_x * cos(a_vx * PI * x / L) * v_y * cos(a_vy * PI * y / L);
  return exact_v;
}
Exemple #12
0
// 输入 点的直角坐标 和点相对于球心的球坐标,输出 球心的直角坐标 GLdouble
void dsFindSphereCenter(
    const GLdouble sphere[3],
    const GLdouble ortho[3],
    GLdouble center[3]
) {
    center[0] = sphere[0] * sin(sphere[1]) * cos(sphere[2]) - ortho[0];
    center[1] = sphere[0] * sin(sphere[1]) * sin(sphere[2]) - ortho[1];
    center[2] = sphere[0] * cos(sphere[1]) - ortho[2];
}
Exemple #13
0
Scalar MASA::euler_transient_1d<Scalar>::eval_exact_p(Scalar x,Scalar t)
{
  using std::cos;
  using std::sin;

  Scalar exact_p;
  exact_p = p_0 + p_x * cos(a_px * pi * x / L) + p_t * cos(a_pt * pi * t / L);
  return exact_p;
}
Exemple #14
0
// 输入 点相对于球心的球坐标 和 球心的直角坐标,输出 点的直角坐标 GLdouble
void dsSphereToOrtho3dv(
    const GLdouble sphere[3],
    const GLdouble center[3],
    GLdouble ortho[3]
) {
    ortho[0] = center[0] + sphere[0] * sin(sphere[1]) * cos(sphere[2]);
    ortho[1] = center[1] + sphere[0] * sin(sphere[1]) * sin(sphere[2]);
    ortho[2] = center[2] + sphere[0] * cos(sphere[1]);
}
Exemple #15
0
  /** Computes the function
   * Z[n*(n+1)/2+m]
   *        = Z_n^m
   *        = i^-|m| A_n^m (-1)^n rho^n Y_n^m(theta, phi)
   *        = i^-|m| (-1)^n/sqrt((n+m)!(n-m)!) (-1)^n rho^n Y_n^m(theta, phi)
   *        = rho^n/(n+|m|)! P_n^|m|(cos theta) exp(i m phi) i^-|m|
   * for all 0 <= n < P and all 0 <= m <= n.
   *
   * @param[in] rho    The radial distance, rho > 0.
   * @param[in] theta  The inclination or polar angle, 0 <= theta <= pi.
   * @param[in] phi    The azimuthal angle, 0 <= phi <= 2pi.
   * @param[in] P      The maximum degree spherical harmonic to compute, P > 0.
   * @param[out] Y,dY  The output arrays to store Znm and its theta-derivative.
   *                     Each has storage for P*(P+1)/2 elements.
   *
   * Note this uses the spherical harmonics definition
   * Y_n^m(\theta, \phi) =
   *        \sqrt{\frac{(n-|m|)!}{(n+|m|)!}} P_n^{|m|}(\cos \theta) e^{i m \phi)
   * which has symmetries
   *   Y_n^m(\pi - \theta, \pi + \phi) = (-1)^n Y_n^m(\theta, \phi)
   *   Y_n^{-m} = (-1)^m conj(Y_n^m)
   *
   * Note the symmetry in the result of this function
   *    Z_n^{-m} = (-1)^m conj(Z_n^m)
   * where conj denotes complex conjugation.
   *
   * These are not the spherical harmonics, but are the spherical
   * harmonics with the prefactor (often denoted A_n^m) included. These are useful
   * for computing multipole and local expansions in an FMM.
   */
  inline static
  void evalZ(real_type rho, real_type theta, real_type phi, int P,
             complex_type* Y, complex_type* dY = nullptr) {
    typedef real_type     real;
    typedef complex_type  complex;
    using std::cos;
    using std::sin;

    const real    ct = cos(theta);
    const real    st = sin(theta);
    const complex ei = complex(sin(phi),-cos(phi)); // exp(i*phi) i^-1

    int m = 0;
    int nm;
    real    Pmm = 1;                                // Init Legendre Pmm(ct)
    real   rhom = 1;                                // Init rho^n / (n+m)!
    complex eim = 1;                                // Init exp(i*m*phi) i^-m
    while (true) {                                  // For all 0 <= m < P
      // n == m
      nm = m*(m+1)/2 + m;                           //  Index of Znm for m > 0
      Y[nm] = rhom * Pmm * eim;                     //  Znm for m > 0
      if (dY)
        dY[nm] = m*ct/st * Y[nm];                   //  Theta derivative of Znm

      // n == m+1
      int n = m + 1;
      if (n == P) return;                           //  Done! m == P-1

      real Pnm  = ct * (2*m+1) * Pmm;               //  P_{m+1}^m(x) = x(2m+1)Pmm
      real rhon = rhom * rho / (n+m);               //  rho^n / (n+m)!
      nm += n;                                      //  n*(n+1)/2 + m
      Y[nm] = rhon * Pnm * eim;                     //  Znm for m > 0
      if (dY)
        dY[nm] = (n*ct-(n+m)*Pmm/Pnm)/st * Y[nm];   //  Theta derivative of Znm

      // m+1 < n < P
      real Pn1m = Pmm;                              //  P_{n-1}^m
      while (++n != P) {
        real Pn2m = Pn1m;                           //   P_{n-2}^m
        Pn1m = Pnm;                                 //   P_{n-1}^m
        Pnm = (ct*(2*n-1)*Pn1m-(n+m-1)*Pn2m)/(n-m); //   P_n^m recurrence
        rhon *= rho / (n + m);                      //   rho^n / (n+m)!

        nm += n;                                    //   n*(n+1)/2 + m
        Y[nm] = rhon * Pnm * eim;                   //   Znm for m > 0
        if (dY)
          dY[nm] = (n*ct-(n+m)*Pn1m/Pnm)/st * Y[nm];//   Theta derivative of Znm
      }

      ++m;                                          //  Increment m

      rhom *= rho / (2*m*(2*m-1));                  //  rho^m / (2m)!
      Pmm  *= -st * (2*m-1);                        //  P_{m+1}^{m+1} recurrence
      eim  *= ei;                                   //  exp(i*m*phi) i^-m
    }                                               // End loop over m in Znm
  }
YAFEL_NAMESPACE_OPEN

static std::vector<std::vector<int>> build_topodim2_faces(const std::vector<coordinate<>> &xi_all,
                                                          const std::function<bool(coordinate<>)> &isBoundary,
                                                          double theta0)
{
    using std::cos;
    using std::sin;
    double pi = std::atan(1.0) * 4;
    auto Theta = [pi](coordinate<> xi) { return std::atan2(xi(1), xi(0)); };

    Tensor<3, 2> R;
    R(0, 0) = cos(theta0);
    R(0, 1) = -sin(theta0);
    R(1, 0) = sin(theta0);
    R(1, 1) = cos(theta0);
    R(2, 2) = 1;
    coordinate<> xi0{0.25, 0.25, 0};

    std::vector<double> thetaVec;
    std::vector<int> bnd_idxs;
    int idx = 0;
    for (auto xi : xi_all) {
        if (isBoundary(xi)) {
            bnd_idxs.push_back(idx);
            double th = Theta(R * (xi - xi0));
            thetaVec.push_back(th);
        }
        ++idx;
    }

    std::vector<int> tmp_idx(bnd_idxs.size());
    idx = 0;
    for (auto &i : tmp_idx) {
        i = idx++;
    }

    auto sort_func_f = [&thetaVec](int l, int r) { return thetaVec[l] < thetaVec[r]; };
    auto sort_func_r = [&thetaVec](int l, int r) { return thetaVec[l] > thetaVec[r]; };

    std::vector<int> f_bnd(tmp_idx);
    std::sort(f_bnd.begin(), f_bnd.end(), sort_func_f);
    for (auto &f : f_bnd) {
        f = bnd_idxs[f];
    }

    idx = 0;
    std::vector<int> r_bnd(tmp_idx);
    std::sort(r_bnd.begin(), r_bnd.end(), sort_func_r);
    for (auto &r : r_bnd) {
        r = bnd_idxs[r];
    }

    return {f_bnd, r_bnd};
}
Exemple #17
0
  std::vector<Real> Exact(Real t, const std::vector<Real>& yinit) const
    {
      using std::sin;
      using std::cos;
      std::vector<Real> yexact(n);

      yexact[q] = yinit[p]/omega*sin(omega*t) + yinit[q]*cos(omega*t);
      yexact[p] = yinit[p]*cos(omega*t) - yinit[q]*omega*sin(omega*t);

      return yexact;
    }
Exemple #18
0
/*!
 * Convert longitude, latitude, height to X, Y, Z in wgs84
 * @param[in] longitude in degree
 * @param[in] latitude in degree
 * @param[in] height in meter
 * @return ecef vector<double> contains X, Y, Z in wgs84
 */
vector<double> llh2ecef(const double& longitude, const double& latitude, const double& height)
{
        vector<double> ecef;
        const double n = A / sqrt(1.0 - E * E * sin(toRad(latitude)) * sin(toRad(latitude)));

        ecef.push_back((n + height) * cos(toRad(longitude)) * cos(toRad(latitude)));
        ecef.push_back((n + height) * sin(toRad(longitude)) * cos(toRad(latitude)));
        ecef.push_back(((n * (1.0 - E * E)) + height) * sin(toRad(latitude)));

        return ecef;
}
Exemple #19
0
void Ave::accumulateLatLon(double lat, double lon, double &x, double &y, double &z) {
    using std::cos;
    using std::sin;

    const double u = lon * D2R;
    const double v = lat * D2R;
    const double w = cos(v);

    x += cos(u) * w;
    y += sin(u) * w;
    z += sin(v);
}
Exemple #20
0
 /** Spherical to cartesian coordinates */
 inline static
 point_type sph2cart(real_type rho, real_type theta, real_type phi,
                     const point_type& s) {
   using std::cos;
   using std::sin;
   const real_type st = sin(theta);
   const real_type ct = cos(theta);
   const real_type sp = sin(phi);
   const real_type cp = cos(phi);
   return point_type(s[0]*st*cp + s[1]*ct*cp/rho - s[2]*sp/(rho*st),
                     s[0]*st*sp + s[1]*ct*sp/rho + s[2]*cp/(rho*st),
                     s[0]*ct    - s[1]*st/rho);
 }
Exemple #21
0
  /** Computes the function
   * W[n*(n+1)/2+m]
   *         = W_n^m
   *         = i^|m| / A_n^m rho^{-n-1} Y_n^m(theta, phi)
   *         = i^|m| (-1)^n sqrt((n+m)!(n-m)!) rho^{-n-1} Y_n^m(theta, phi)
   *         = (-1)^n rho^{-n-1} (n-|m|)! P_n^|m|(cos theta) exp(i m phi) i^|m|
   * for all 0 <= n < P and all 0 <= m <= n.
   *
   * @param[in] rho    The radial distance, rho > 0.
   * @param[in] theta  The inclination or polar angle, 0 <= theta <= pi.
   * @param[in] phi    The azimuthal angle, 0 <= phi <= 2pi.
   * @param[in] P      The maximum degree spherical harmonic to compute, P > 0.
   * @param[out] Y,dY  The output arrays to store Wnm and its theta-derivative.
   *                     Each has storage for P*(P+1)/2 elements.
   *
   * Note this uses the spherical harmonics definition
   * Y_n^m(\theta, \phi) =
   *        \sqrt{\frac{(n-|m|)!}{(n+|m|)!}} P_n^{|m|}(\cos \theta) e^{i m \phi)
   * which has symmetries
   *   Y_n^m(\pi - \theta, \pi + \phi) = (-1)^n Y_n^m(\theta, \phi)
   *   Y_n^{-m} = (-1)^m conj(Y_n^m)
   *
   * Note the symmetry in the result of this function
   *    W_n^{-m} = (-1)^m conj(W_n^m)
   * where conj denotes complex conjugation.
   *
   * These are not the spherical harmonics, but are the spherical
   * harmonics with the prefactor (often denoted A_n^m) included. These are useful
   * for computing multipole and local expansions in an FMM.
   */
  inline static
  void evalW(real_type rho, real_type theta, real_type phi, int P,
             complex_type* Y) {
    typedef real_type     real;
    typedef complex_type  complex;
    using std::cos;
    using std::sin;

    const real    ct = cos(theta);
    const real    st = sin(theta);
    const complex ei = complex(-sin(phi),cos(phi));// exp(i*phi) i

    rho = 1 / rho;
    int m = 0;
    int nm;
    real    Pmm = 1;                               // Init Legendre Pmm(ct)
    real   rhom = rho;                             // Init -1^n rho^{-n-1} (n-m)!
    complex eim = 1;                               // Init exp(i*m*phi) i^-m
    while (true) {                                 // For all 0 <= m < P
      // n == m
      nm = m*(m+1)/2 + m;                          //  Index of Wnm for m > 0
      Y[nm] = rhom * Pmm * eim;                    //  Wnm for m > 0

      // n == m+1
      int n = m+1;
      if (n == P) return;                          //  Done! m == P-1

      real Pnm  = ct * (2*m+1) * Pmm;              //  P_{m+1}^m(x) = x(2m+1)Pmm
      real rhon = rhom * -rho;                     //  -1^n rho^{-n-1} (n-m)!
      nm += n;                                     //  n*(n+1)/2 + m
      Y[nm] = rhon * Pnm * eim;                    //  Wnm for m > 0

      // m+1 < n < P
      real Pn1m = Pmm;                              //  P_{n-1}^m
      while (++n != P) {
        real Pn2m = Pn1m;                           //   P_{n-2}^m
        Pn1m = Pnm;                                 //   P_{n-1}^m
        Pnm = (ct*(2*n-1)*Pn1m-(n+m-1)*Pn2m)/(n-m); //   P_n^m recurrence
        rhon *= -rho * (n - m);                     //   -1^n rho^{-n-1} (n-m)!

        nm += n;                                    //   n*(n+1)/2 + m
        Y[nm] = rhon * Pnm * eim;                   //   Wnm for m > 0
      }

      ++m;                                          //  Increment m

      rhom *= -rho;                                 //  -1^m rho^{-m-1} (n-m)!
      Pmm  *= -st * (2*m-1);                        //  P_{m+1}^{m+1} recurrence
      eim  *= ei;                                   //  exp(i*m*phi) i^m
    }                                               // End loop over m in Wnm
  }
Exemple #22
0
TEST(AgradFwdTan, FvarVar_2ndDeriv) {
  using stan::agrad::fvar;
  using stan::agrad::var;
  using std::tan;
  using std::cos;

  fvar<var> x(1.5,1.3);
  fvar<var> a = tan(x);

  AVEC y = createAVEC(x.val_);
  VEC g;
  a.d_.grad(y,g);
  EXPECT_FLOAT_EQ(2.0 / (cos(1.5) * cos(1.5)) * tan(1.5) * 1.3, g[0]);
}
 /**
  *  @brief Extract angles corresponding to an YXZ transformation
  *  @param angles Resulting angles, in order: phi,theta,psi about Y,X,Z
  *
  *  @note In the case where cos(phi)==0, we set psi = 0 (gimbal lock).
  */
 void extractYXZ(float angles[3]) const
 {
     static_assert(N == 3 && M == 3, "Matrix must be a member of SO3 group");
     
     using std::cos;
     using std::atan2;
     
     const matrix <3,3>& R = *this;
     
     //  numerical rounding may cause this value to drift out of bounds
     float nsin_phi = R(1,2);
     if (nsin_phi < -1.0f) {
         nsin_phi = -1.0f;
     } else if (nsin_phi > 1.0f) {
         nsin_phi = 1.0f;
     }
     
     angles[0] = asinf( -nsin_phi );   //  phi
     if (cos(angles[0]) < 1.0e-5f)
     {
         angles[1] = atan2(R(0,1), R(0,0));  //  theta
         angles[2] = 0.0f;                   //  psi
     }
     else
     {
         angles[1] = atan2(R(0,2), R(2,2));  //  theta
         angles[2] = atan2(R(1,0), R(1,1));  //  psi
     }
 }
Exemple #24
0
int main()
{
    std::cout << "This shows how to use Boost's Catmull-Rom spline to create an Archimedean spiral.\n";

    // The Archimedean spiral is given by r = a*theta. We have set a = 1.
    std::vector<std::array<double, 2>> spiral_points(500);
    double theta_max = boost::math::constants::pi<double>();
    for (size_t i = 0; i < spiral_points.size(); ++i)
    {
        double theta = ((double) i/ (double) spiral_points.size())*theta_max;
        spiral_points[i] = {theta*cos(theta), theta*sin(theta)};
    }

    auto archimedean = catmull_rom<std::array<double,2>>(std::move(spiral_points));
    double max_s = archimedean.max_parameter();
    std::cout << "Max s = " << max_s << std::endl;
    for (double s = 0; s < max_s; s += 0.01)
    {
        auto p = archimedean(s);
        double x = p[0];
        double y = p[1];
        double r = sqrt(x*x + y*y);
        double theta = atan2(y/r, x/r);
        std::cout << "r = " << r << ", theta = " << theta << ", r - theta = " << r - theta << std::endl;
    }

    return 0;
}
Exemple #25
0
//------------------------------------------------------------------------
// resize(size_t sz, size_t firstnull, float gain) -
//------------------------------------------------------------------------
void
sinc::resize(size_t sz, size_t firstnull, float gain)
{
    using std::sin;
    using std::cos;

    // free and minimize vector.
    std::vector<float>().swap(tbl_);
    tbl_.reserve(sz);

    // sanitize input
    sz        = std::max<size_t>(1,  sz);
    firstnull = std::min<size_t>(sz, firstnull);

    convfactor_ = (float)firstnull;

    size_t i;
    double sum = 0.;
    for (i = 0; i < sz; i++)
    {
        /*Evaluate Upper half of sinc(x) * Hamming window */
        const float f = eps + (PI*i) / firstnull;
        const float v = sin(f) / f * (.54f + .46f * cos(i*PI / sz));
        tbl_.push_back(v);
        sum += v;
    }

    const float adjust = gain * firstnull / (float)(2*sum - tbl_[0]);

    // adjust the 'gain' of the sinc
    for (i = 0; i < sz; i++)
    {
        tbl_[i] *= adjust;
    }
}
Exemple #26
0
void Rotation::inverseTransform(double& lat, double& lon) const {
    const double u = toRadians(lon);
    const double v = toRadians(lat);

    const double w = cos(v);
    const double x = cos(u) * w;
    const double y = sin(u) * w;
    const double z = sin(v);

    const double x2 = a11 * x + a21 * y + a31 * z;
    const double y2 = a12 * x + a22 * y + a32 * z;
    const double z2 = a13 * x + a23 * y + a33 * z;

    lat = toDegrees(asin(z2));
    lon = toDegrees(atan2(y2, x2));
}
Exemple #27
0
 inline
 fvar<T>
 cos(const fvar<T>& x) {
   using std::sin;
   using std::cos;
   return fvar<T>(cos(x.val_), x.d_ * -sin(x.val_));
 }
Exemple #28
0
// ************************************************************************
// rot_z
// creates elementary rotation matrix about z
Mat3D rot_z(const double angle)
{
  Mat3D result;
  double sAngle = 0.0;          // sin of angle
  double cAngle = 0.0;          // cos of angle

  // try some popular angles for better precision
  if (angle == PI) cAngle = -1.0;               // s already 0.0
  else if (angle == PI/2) sAngle = 1.0;         // c already 0.0
  else if (angle == 0.0) cAngle = 1.0;
  else
  {
    sAngle = sin(angle);
    cAngle = cos(angle);
  }
  result.mat[0][0] = (scalarT)cAngle;
  result.mat[0][1] = (scalarT)sAngle;
  result.mat[0][2] = 0.0f;
  result.mat[1][0] = (scalarT)-sAngle;
  result.mat[1][1] = (scalarT)cAngle;
  result.mat[1][2] = 0.0f;
  result.mat[2][0] = 0.0f;
  result.mat[2][1] = 0.0f;
  result.mat[2][2] = 1.0f;

  return result;
}
Exemple #29
0
inline GAUSS gauss_ini(double e, double phi0, double &chi, double &rc)
{
    using std::asin;
    using std::cos;
    using std::sin;
    using std::sqrt;
    using std::tan;

    double sphi = 0;
    double cphi = 0;
    double es = 0;

    GAUSS en;
    es = e * e;
    en.e = e;
    sphi = sin(phi0);
    cphi = cos(phi0);
    cphi *= cphi;

    rc = sqrt(1.0 - es) / (1.0 - es * sphi * sphi);
    en.C = sqrt(1.0 + es * cphi * cphi / (1.0 - es));
    chi = asin(sphi / en.C);
    en.ratexp = 0.5 * en.C * e;
    en.K = tan(0.5 * chi + detail::FORTPI)
           / (pow(tan(0.5 * phi0 + detail::FORTPI), en.C) * srat(en.e * sphi, en.ratexp));

    return en;
}
Exemple #30
0
  void 
  circle_graph_layout(const VertexListGraph& g, PositionMap position,
                      Radius radius)
  {
    const double pi = 3.14159;

#ifndef BOOST_NO_STDC_NAMESPACE
    using std::sin;
    using std::cos;
#endif // BOOST_NO_STDC_NAMESPACE

    typedef typename graph_traits<VertexListGraph>::vertices_size_type 
      vertices_size_type;

    vertices_size_type n = num_vertices(g);
    
    typedef typename graph_traits<VertexListGraph>::vertex_iterator 
      vertex_iterator;

    vertices_size_type i = 0;
    for(std::pair<vertex_iterator, vertex_iterator> v = vertices(g); 
        v.first != v.second; ++v.first, ++i) {
      position[*v.first].x = radius * cos(i * 2 * pi / n);
      position[*v.first].y = radius * sin(i * 2 * pi / n);
    }
  }