本文整理汇总了C++中polar函数的典型用法代码示例。如果您正苦于以下问题:C++ polar函数的具体用法?C++ polar怎么用?C++ polar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了polar函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compute_u_coefficients
void compute_u_coefficients(int N, double mu, double q, double L, double kcrc, double complex u[]) {
double y = M_PI/L;
double k0r0 = kcrc * exp(-L);
double t = -2*y*log(k0r0/2);
if(q == 0) {
double x = (mu+1)/2;
double lnr, phi;
for(int m = 0; m <= N/2; m++) {
lngamma_4(x, m*y, &lnr, &phi);
u[m] = polar(1.0,m*t + 2*phi);
}
}
else {
double xp = (mu+1+q)/2;
double xm = (mu+1-q)/2;
double lnrp, phip, lnrm, phim;
for(int m = 0; m <= N/2; m++) {
lngamma_4(xp, m*y, &lnrp, &phip);
lngamma_4(xm, m*y, &lnrm, &phim);
u[m] = polar(exp(q*log(2) + lnrp - lnrm), m*t + phip - phim);
}
}
for(int m = N/2+1; m < N; m++)
u[m] = conj(u[N-m]);
if((N % 2) == 0)
u[N/2] = (creal(u[N/2]) + I*0.0);
}
示例2: citi_create_vector
/* Create a valid vector for the dataset. */
static vector * citi_create_vector (struct citi_package_t * p, int i,
char * n, char * type) {
vector * vec;
vec = citi_get_vector (p, i); // fetch vector
vec = new vector (*vec); // copy vector
vec->reverse (); // reverse vector
// convert data if necessary
if (!strcmp (type, "MAGANGLE")) {
for (int i = 0; i < vec->getSize (); i++) {
nr_complex_t val = vec->get (i);
val = polar (real (val), rad (imag (val)));
vec->set (val, i);
}
}
else if (!strcmp (type, "DBANGLE")) {
for (int i = 0; i < vec->getSize (); i++) {
nr_complex_t val = vec->get (i);
val = polar (pow (10.0, real (val) / 20.0), rad (imag (val)));
vec->set (val, i);
}
}
// return named vector
vec->setName (n);
return vec;
}
示例3: spherical_pattern_maximize
real spherical_pattern_maximize(const function<real(Vector<real,3>)>& score, Vector<real,3>& n, real tol) {
static const real da = 2*M_PI/5;
static const Vector<real,2> dirs[5] = {polar(0.), polar(da), polar(2*da), polar(3*da), polar(4*da)};
const real alpha = .5;
real step = .2;
real dot = score(n);
while (step > tol) {
real best_dot = dot;
Vector<real,3> best_n = n;
Vector<real,3> orth;
orth[n.argmin()] = 1;
Vector<real,3> a = cross(n,orth).normalized(), b = cross(n,a);
for (int i = 0; i < 5; i++) {
Vector<real,3> candidate = (n + step*dirs[i].x*a + step*dirs[i].y*b).normalized();
real d = score(candidate);
if (best_dot < d) {
best_dot = d;
best_n = candidate;
}
}
if (dot < best_dot) {
dot = best_dot;
n = best_n;
} else
step *= alpha;
}
return dot;
}
示例4: intersect
cd intersect(circle a, circle b, int x = 0) {
double d = sqrt(norm(a.f-b.f));
double co = (a.s*a.s+d*d-b.s*b.s)/(2*a.s*d);
double theta = acos(co);
cd tmp = (b.f-a.f)/d;
if (x == 0) return a.f+tmp*a.s*polar(1.0,theta);
return a.f+tmp*a.s*polar(1.0,-theta);
}
示例5: z_freqz_db
double z_freqz_db(bool hpf, double f, double a, double h, double l) {
double wf = f * PI;
complex<double> hf;
if (!hpf) { hf = h + l * (1 + (1.0 + polar(a, -wf)) / (a + polar(1.0, -wf))); } else {
a = 1.0 / a;
hf = h + l * (1 - (1.0 + polar(a, -wf)) / (a + polar(1.0, -wf)));
}
double db = 10.0 * log(magsq(hf)) / log(10.0);
return (db);
}
示例6: rad
void phaseshifter::initSP (void) {
nr_double_t p = rad (getPropertyDouble ("phi"));
nr_double_t z = getPropertyDouble ("Zref");
nr_double_t r = (z0 - z) / (z0 + z);
nr_complex_t d = 1.0 - polar (r * r, 2 * p);
nr_complex_t s11 = r * (polar (1.0, 2 * p) - 1.0) / d;
nr_complex_t s21 = (1.0 - r * r) * polar (1.0, p) / d;
allocMatrixS ();
setS (NODE_1, NODE_1, s11);
setS (NODE_2, NODE_2, s11);
setS (NODE_1, NODE_2, s21);
setS (NODE_2, NODE_1, s21);
}
示例7: cos
//散乱波の計算
void Solver::scatteredWave(complex<double> *p){
double rad = wave_angle*M_PI/180; //ラジアン変換
double _cos = cos(rad), _sin = sin(rad); //毎回計算すると時間かかりそうだから,代入しておく
for(int i=mField->getNpml(); i<mField->getNpx(); i++){
for(int j=mField->getNpml(); j<mField->getNpy(); j++){
if( N_S(i,j) == 1.0 ) continue; //屈折率が1なら散乱は起きない
double ikx = k_s*(i*_cos + j*_sin);
p[index(i,j, +1)] += ray_coef*(1/_pow(N_S(i,j), 2)-1)
*(polar(1.0, ikx-w_s*(time+DT_S))+polar(1.0, ikx-w_s*(time-DT_S))-2.0*polar(1.0, ikx-w_s*time));
}
}
}
示例8: test_glide_alt
static void
test_glide_alt(const fixed h, const fixed W, const fixed Wangle,
std::ostream &hfile)
{
GlidePolar polar(fixed_zero);
polar.SetMC(fixed_one);
AircraftState ac;
ac.wind.norm = fabs(W);
if (negative(W)) {
ac.wind.bearing = Angle::degrees(fixed(180)+Wangle);
} else {
ac.wind.bearing = Angle::degrees(Wangle);
}
ac.altitude = h;
GeoVector vect(fixed(400.0));
GlideState gs(vect, fixed_zero, ac.altitude, ac.wind);
GlideResult gr = MacCready::solve(polar, gs);
hfile << (double)h << " "
<< (double)gr.altitude_difference << " "
<< (double)gr.time_elapsed << " "
<< (double)gr.v_opt << " "
<< (double)W << " "
<< (double)Wangle << " "
<< "\n";
}
示例9: basic_polar
static void
basic_polar(const fixed mc)
{
char bname[100];
sprintf(bname,"results/res-polar-%02d-best.txt",(int)(mc*10));
std::ofstream pfile("results/res-polar.txt");
std::ofstream mfile(bname);
GlidePolar polar(mc);
for (fixed V= Vmin; V<= polar.GetVMax(); V+= fixed(0.25)) {
pfile << (double)mc << " "
<< (double)V << " "
<< -(double)polar.SinkRate(V) << " "
<< (double)(V/polar.SinkRate(V))
<< "\n";
}
mfile << (double)mc
<< " " << 0
<< " " << (double)mc
<< " " << (double)polar.GetBestLD()
<< "\n";
mfile << (double)mc
<< " " << (double)polar.GetVBestLD()
<< " " << -(double)polar.GetSBestLD()
<< " " << (double)polar.GetBestLD()
<< "\n";
}
示例10: test_glide_cb
static void
test_glide_cb(const fixed h, const fixed W, const fixed Wangle,
std::ostream &hfile)
{
GlidePolar polar(fixed_one);
AircraftState ac;
ac.wind.norm = fabs(W);
if (negative(W)) {
ac.wind.bearing = Angle::degrees(fixed(180)+Wangle);
} else {
ac.wind.bearing = Angle::degrees(Wangle);
}
ac.altitude = h;
GeoVector vect(fixed(400.0));
GlideState gs (vect, fixed_zero, ac.altitude, ac.wind);
GlideResult gr = MacCready::solve(polar, gs);
gr.CalcDeferred(ac);
hfile << (double)W << " "
<< (double)Wangle << " "
<< (double)gr.vector.Bearing.value_degrees() << " "
<< (double)gr.cruise_track_bearing.value_degrees() << " "
<< "\n";
}
示例11: test_glide_stf
static void
test_glide_stf(const fixed h, const fixed W, const fixed Wangle, const fixed S,
std::ostream &hfile)
{
GlidePolar polar(fixed_zero);
polar.SetMC(fixed_one);
AircraftState ac;
ac.wind.norm = fabs(W);
if (negative(W)) {
ac.wind.bearing = Angle::degrees(fixed(180)+Wangle);
} else {
ac.wind.bearing = Angle::degrees(Wangle);
}
ac.altitude = h;
ac.netto_vario = S;
GeoVector vect(fixed(400.0));
GlideState gs(vect, fixed_zero, ac.altitude, ac.wind);
GlideResult gr = MacCready::solve(polar, gs);
fixed Vstf = polar.SpeedToFly(ac, gr, false);
hfile << (double)h << " "
<< (double)gr.altitude_difference << " "
<< (double)gr.v_opt << " "
<< (double)Vstf << " "
<< (double)W << " "
<< (double)Wangle << " "
<< (double)ac.netto_vario << " "
<< "\n";
}
示例12: fft_main
// Fast Fourier transform du signal f(deb:pas:fin) (Matlab notation).
// s=-1 pour DFT directe, s=+1 pour DFT inverse.
// Buffer est utilise comme tableau temporaire, sa longueur doit etre au moins
// celle de f.
void fft_main(complex<float> f[], int deb, int pas, int fin, float s,
complex<float> buffer[]) {
int n = (fin - deb) / pas + 1;
if (n == 1) {
return;
}
assert(n % 2 == 0);
fft_main(f, deb, 2 * pas, fin - pas, s, buffer);
fft_main(f, deb + pas, 2 * pas, fin, s, buffer);
for (int i = 0; i < n; i++) {
buffer[i] = f[deb + i * pas];
}
complex<float> t = 1;
complex<float> w = polar(1.0f, float(s * 2 * M_PI / n));
for (int i = 0; i < n / 2; i++) {
f[deb + i * pas] = buffer[2 * i] + t * buffer[2 * i + 1];
f[deb + (i + n / 2) * pas] = buffer[2 * i] - t * buffer[2 * i + 1];
t *= w;
}
}
示例13: test_glide_cb
static void
test_glide_cb(const fixed h, const fixed W, const fixed Wangle,
std::ostream &hfile)
{
GlideSettings settings;
settings.SetDefaults();
GlidePolar polar(fixed(1));
AircraftState ac;
ac.wind.norm = fabs(W);
if (negative(W)) {
ac.wind.bearing = Angle::Degrees(fixed(180)+Wangle);
} else {
ac.wind.bearing = Angle::Degrees(Wangle);
}
ac.altitude = h;
GeoVector vect(fixed(400.0), Angle::Zero());
GlideState gs (vect, fixed(0), ac.altitude, ac.wind);
GlideResult gr = MacCready::Solve(settings, polar, gs);
gr.CalcDeferred();
hfile << (double)W << " "
<< (double)Wangle << " "
<< (double)gr.vector.bearing.Degrees() << " "
<< (double)gr.cruise_track_bearing.Degrees() << " "
<< "\n";
}
示例14: fft
vector< cplx > fft(const vector< cplx > &smp, bool rev) {
int n = sz(smp);
vector< cplx > a(n), w(n);
for (int i = 0; i < n; ++i) {
int ni = 0;
for (int j = 1, x = i; j < n; j <<= 1, x >>= 1)
ni <<= 1, ni |= x & 1;
a[ni] = smp[i];
}
for (int i = 0; i < n; ++i)
w[i] = polar(1.0, (rev ? -1 : 1) * 2.0 * i * kPi / n);
for (int k = 1; k < n; k <<= 1) {
vector< cplx > y(n);
for (int i = 0, s = n / (2 * k); i < n; i += 2 * k)
for (int j = 0, p = i; j < k; ++j, ++p) {
y[p] = a[p] + w[j * s] * a[p + k];
y[p + k] = a[p] - w[j * s] * a[p + k];
}
a = y;
}
if (rev) {
for (int i = 0; i < n; ++i)
a[i] /= n;
}
return a;
}
示例15: tangent_circles
pair<circle, circle> tangent_circles(const line& l, const line& m, double r) {
double th = arg(m.b - m.a) - arg(l.b - l.a);
double ph = (arg(m.b - m.a) + arg(l.b - l.a)) / 2.0;
point p = crosspointLL(l, m);
point d = polar(r / sin(th / 2.0), ph);
return mp(circle(p - d, r), circle(p + d, r));
}