当前位置: 首页>>代码示例>>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;未经允许,请勿转载。