當前位置: 首頁>>代碼示例>>C++>>正文


C++ std::cos方法代碼示例

本文整理匯總了C++中std::cos方法的典型用法代碼示例。如果您正苦於以下問題:C++ std::cos方法的具體用法?C++ std::cos怎麽用?C++ std::cos使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在std的用法示例。


在下文中一共展示了std::cos方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: cos

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;
}
開發者ID:hovr2pi,項目名稱:MASA,代碼行數:7,代碼來源:ad_cns_2d_crossterms.cpp

示例2: sqrt

/*!
 * 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;
        }
}
開發者ID:MoriokaReimen,項目名稱:GPS,代碼行數:37,代碼來源:wgs84.cpp

示例3: TEST

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]);
}
開發者ID:actuariat,項目名稱:stan,代碼行數:28,代碼來源:tan_test.cpp

示例4: cos

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;
}
開發者ID:jfelts1,項目名稱:3dGraphics,代碼行數:30,代碼來源:Shapes.cpp

示例5: tan

 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_)));
 }
開發者ID:HerraHuu,項目名稱:stan,代碼行數:7,代碼來源:tan.hpp

示例6: TEST

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_);
}
開發者ID:javaosos,項目名稱:stan,代碼行數:26,代碼來源:cos_test.cpp

示例7: varying_data

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)));
}
開發者ID:RhysU,項目名稱:suzerain,代碼行數:8,代碼來源:test_l2xz.cpp

示例8: dsFindSphereCenter

// 輸入 點的直角坐標 和點相對於球心的球坐標,輸出 球心的直角坐標 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];
}
開發者ID:mikuhatsune,項目名稱:ds15gl,代碼行數:10,代碼來源:dsVector.cpp

示例9: cos

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;
}
開發者ID:hovr2pi,項目名稱:MASA,代碼行數:9,代碼來源:euler_transient.cpp

示例10: dsSphereToOrtho3dv

// 輸入 點相對於球心的球坐標 和 球心的直角坐標,輸出 點的直角坐標 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]);
}
開發者ID:mikuhatsune,項目名稱:ds15gl,代碼行數:10,代碼來源:dsVector.cpp

示例11: evalZ

  /** 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
  }
開發者ID:ccecka,項目名稱:fmmtl,代碼行數:86,代碼來源:SphericalMultipole3D.hpp

示例12: build_topodim2_faces

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};
}
開發者ID:tjolsen,項目名稱:YAFEL,代碼行數:55,代碼來源:build_topodim2_faces.cpp

示例13: Exact

  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;
    }
開發者ID:jeanluct,項目名稱:rodent,代碼行數:11,代碼來源:simpharmonic.hpp

示例14: accumulateLatLon

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);
}
開發者ID:bcdev,項目名稱:s3-synergy,代碼行數:12,代碼來源:Ave.cpp

示例15: sph2cart

 /** 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);
 }
開發者ID:ccecka,項目名稱:fmmtl,代碼行數:14,代碼來源:SphericalMultipole3D.hpp


注:本文中的std::cos方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。