Example #1
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_);
}
Example #2
0
void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
  if (!m_source_node || !m_dest_node) return;

  const double pi{boost::math::constants::pi<double>()};
  const double tau{boost::math::constants::two_pi<double>()};


  const QLineF line(m_source_point, m_dest_point);

  if (qFuzzyCompare(line.length(), 0.0)) return;

  // Draw the line itself
  painter->setPen(QPen(Qt::black, 1.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
  painter->drawLine(line);

  // Draw the arrows
  double angle = std::acos(line.dx() / line.length());
  if (line.dy() >= 0) angle = tau - angle;

  using std::sin;
  using std::cos;
  const QPointF sourceArrowP1{m_source_point + QPointF(sin(angle + pi / 3.0) * m_arrow_size,cos(angle + pi / 3.0) * m_arrow_size)};
  const QPointF sourceArrowP2{m_source_point + QPointF(sin(angle + pi - pi / 3.0) * m_arrow_size,cos(angle + pi - pi / 3.0) * m_arrow_size)};
  const QPointF destArrowP1{m_dest_point + QPointF(sin(angle - pi / 3.0) * m_arrow_size,cos(angle - pi / 3.0) * m_arrow_size)};
  const QPointF destArrowP2{m_dest_point + QPointF(sin(angle - pi + pi / 3.0) * m_arrow_size,cos(angle - pi + pi / 3.0) * m_arrow_size)};

  painter->setBrush(Qt::black);
  painter->drawPolygon(QPolygonF() << line.p1() << sourceArrowP1 << sourceArrowP2);
  painter->drawPolygon(QPolygonF() << line.p2() << destArrowP1 << destArrowP2);
}
Example #3
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;
}
Example #4
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;
        }
}
int if_else_tester (Vector zerovec)
{
  using std::sin;

  typedef typename Vector::value_type Scalar;

  Vector random_vec = zerovec;

  Vector error_vec = zerovec;


  std::srand(12345); // Fixed seed for reproduceability of failures

  for (unsigned int i=0; i != random_vec.size(); ++i)
    random_vec.raw_at(i) = .25 + (static_cast<Scalar>(std::rand())/RAND_MAX);

  int returnval = 0;

  one_test((random_vec > 0.75) * 1.0 - (2*random_vec > 1.5) * 1.0);

  one_test(if_else(random_vec > 0.4,  random_vec, sin(random_vec)) -
           if_else(2*random_vec > 0.8, random_vec, sin(random_vec)));

  return returnval;
}
Example #6
0
Scalar MASA::euler_transient_1d<Scalar>::eval_exact_rho(Scalar x,Scalar t)
{
  using std::sin;

  Scalar exact_rho;
  exact_rho = rho_0 + rho_x * sin(a_rhox * pi * x / L) + rho_t * sin(a_rhot * pi * t / L);
  return exact_rho;
}
Example #7
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];
}
// Convert geographic coordinates (latitude, longitude in degrees) into
// cartesian coordinates (in kilometers) using the Lambert 93 projection.
pair<float,float> geoToLambert93(float latitude,float longitude)
{
    float phi = degreeToRadian(latitude);
    float l   = degreeToRadian(longitude);
    float gl  = log(tan(M_PI/4+phi/2)*pow((1-e*sin(phi))/(1+e*sin(phi)),e/2));
    float x93 = X0 + c*exp(-n*gl)*sin(n*(l-lc));
    float y93 = ys - c*exp(-n*gl)*cos(n*(l-lc));
    return make_pair(x93/1000,y93/1000);
}
Example #9
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]);
}
Example #10
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
  }
Example #11
0
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};
}
Example #12
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;
    }
Example #13
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;
}
Example #14
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);
}
Example #15
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);
 }
Example #16
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
  }
                static States predict(const States& x, const Scalar dT) {
                    typedef typename ModelDescription::StateDescription states;
                    States xnext(x);
                    using std::sin; using std::cos;

                    const auto a = 2. * x(states::v) * sin(x(states::w) * dT / 2.) / x(states::w);
                    const auto b = x(states::th) + (x(states::w) * dT / 2.);

                    xnext(states::x) += a*cos(b);
                    xnext(states::y) += a*sin(b);
                    xnext(states::th) += x(states::w)*dT;
                    xnext(states::v) += x(states::a)*dT;
                    return xnext;
                }
Example #18
0
  void operator() ( const Particle & p,
                    const double & time,
                    const double & dt,
                          Vector<double,6u> & F ) {
    ++num_calls;
    /* copy over the dx/dt, dy/dt, and dz/dt */
    F[X] = p[VX];
    F[Y] = p[VY];
    F[Z] = p[VZ];

    /* and accelerations for a simple harmonic oscillator (kind of simple) */
    F[VX] = - k_m[X]*p[X] - a[X]*k_m[X] * sin( omega_prime[X] * time );
    F[VY] = - k_m[Y]*p[Y] - a[Y]*k_m[Y] * sin( omega_prime[Y] * time );
    F[VZ] = - k_m[Z]*p[Z] - a[Z]*k_m[Z] * sin( omega_prime[Z] * time );
  }
Example #19
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);
    }
  }
Example #20
0
    /**
     * Parameters are in radians.
     * Example front vectors:
     *   Yaw 0:(0,0,1), pi/2:(-1,0,0)
     */
    void setOrientation(float yaw, float pitch)
    {
        using std::sin;
        using std::cos;

        front.x = cos(yaw) * cos(pitch);
        front.y = sin(yaw) * cos(pitch);
        front.z = sin(pitch);

        up.x = -cos(yaw) * sin(pitch);
        up.y = -sin(yaw) * sin(pitch);
        up.z = cos(pitch);

        /*DSFMOD_TRACE("Front:" << front.x << "," << front.y << "," << front.z << " Up:"
                     << up.x << "," << up.y << "," << up.z);*/
    }
float cpp_rana(double* vals, long sz, double* weights){
  //The rana function! It does more things! Wow!
  double tot = 512.0, x, y;
  for(long i = 0; i < sz; ++i){
    x = vals[i];
    if(i == (sz - 1)){
      y = vals[0];
    }
    else{
      y = vals[i + 1];
    }
    tot += weights[i] * (x * sin(sqrt(abs(y + 1 - x))) * cos(sqrt(abs(x + y + 1)))
			 + (y + 1) * cos(sqrt(abs(y + 1 - x))) * sin(sqrt(abs(x + y + 1))));
  }
  return tot;
}
Example #22
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;
    }
}
Example #23
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;
}
Example #24
0
void KigPainter::drawAngle( const Coordinate& point, double startangle, double angle, int radius )
{
    const int startangleDegrees = static_cast<int>( Goniometry::convert( startangle, Goniometry::Rad, Goniometry::Deg ) );
    const int angleDegrees = static_cast<int>( Goniometry::convert( angle, Goniometry::Rad, Goniometry::Deg ) );

    QPoint screenPoint = toScreen( point );
    QRect surroundingRect( 0, 0, radius*2, radius*2 );
    surroundingRect.moveCenter( screenPoint );

    mP.drawArc( surroundingRect, 16 * startangleDegrees, 16 * angleDegrees );

    // now for the arrow...
    QPoint end( static_cast<int>( screenPoint.x() + radius * cos( startangle + angle ) ),
                static_cast<int>( screenPoint.y() - radius * sin( startangle + angle ) ) );
    QPoint vect = (end - screenPoint);
    double vectlen = std::sqrt( float( vect.x() * vect.x() + vect.y() * vect.y() ) );
    QPoint orthvect( -vect.y(), vect.x() );
    vect = vect * 6 / vectlen;
    orthvect = orthvect * 6 / vectlen;

    QPolygon arrow( 3 );
    arrow.setPoint( 0, end );
    arrow.setPoint( 1, end + orthvect + vect );
    arrow.setPoint( 2, end + orthvect - vect );

    setBrushStyle( Qt::SolidPattern );
    mP.drawPolygon( arrow );

//  if ( mNeedOverlay ) mOverlay.push_back( toScreen( r ) );
    setWholeWinOverlay();   //mp: ugly! why not compute a correct overlay?
    //    mOverlay.push_back( arrow.boundingRect() );
}
Example #25
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));
}
Example #26
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;
}
Example #27
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;
}
Example #28
0
inline void gauss(GAUSS const& en, T& lam, T& phi)
{
    phi = 2.0 * atan(en.K * pow(tan(0.5 * phi + FORTPI), en.C)
          * srat(en.e * sin(phi), en.ratexp) ) - HALFPI;

    lam *= en.C;
}
Example #29
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_));
 }
Example #30
0
qreal SunLocator::shading(qreal lon, qreal a, qreal c) const
{
    // haversine formula
    qreal b = sin((lon-d->m_lon)/2.0);
//    qreal g = sin((lat-d->m_lat)/2.0);
//    qreal h = (g*g)+cos(lat)*cos(d->m_lat)*(b*b); 
    qreal h = (a*a) + c * (b*b); 

    /*
      h = 0.0 // directly beneath sun
      h = 0.5 // sunrise/sunset line
      h = 1.0 // opposite side of earth to the sun
      theta = 2*asin(sqrt(h))
    */

    qreal twilightZone = 0.0;

    QString planetId = d->m_planet->id();
    if ( planetId == "earth" || planetId == "venus") {
        twilightZone = 0.1; // this equals 18 deg astronomical twilight.
    }
    else if ( planetId == "mars" ) {
        twilightZone = 0.05;
    }

    qreal brightness;
    if ( h <= 0.5 - twilightZone / 2.0 )
        brightness = 1.0;
    else if ( h >= 0.5 + twilightZone / 2.0 )
        brightness = 0.0;
    else
        brightness = ( 0.5 + twilightZone/2.0 - h ) / twilightZone;

    return brightness;
}