本文整理汇总了C++中Poly::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ Poly::resize方法的具体用法?C++ Poly::resize怎么用?C++ Poly::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poly
的用法示例。
在下文中一共展示了Poly::resize方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sub
// Add b to a or Subs b from a.
void sub(Poly& a, const Poly& b) {
if(a.size() < b.size())
a.resize(b.size(), 0);
for(int i = 0; i < b.size(); ++i)
a[i] ^= b[i];
tidy(a);
}
示例2: divide
Poly divide(Poly const &a, Poly const &b, Poly &r) {
Poly c;
r = a; // remainder
assert(!b.empty());
const unsigned k = a.degree();
const unsigned l = b.degree();
c.resize(k, 0.);
for(unsigned i = k; i >= l; i--) {
assert(i >= 0);
double ci = r.back()/b.back();
c[i-l] += ci;
Poly bb = ci*b;
//std::cout << ci <<"*(" << b.shifted(i-l) << ") = "
// << bb.shifted(i-l) << " r= " << r << std::endl;
r -= bb.shifted(i-l);
r.pop_back();
}
//std::cout << "r= " << r << std::endl;
r.normalize();
c.normalize();
return c;
}
示例3: get
bool get(Poly& p) {
int N;
if(!(cin >> N)) return false;
p.resize(N + 1);
for(int i = 0; i <= N; ++i)
cin >> p[N - i];
return true;
}
示例4:
Poly Poly::operator*(const Poly& p) const {
Poly result;
result.resize(degree() + p.degree()+1);
for(unsigned i = 0; i < size(); i++) {
for(unsigned j = 0; j < p.size(); j++) {
result[i+j] += (*this)[i] * p[j];
}
}
return result;
}
示例5: deconv
// Slow deconvolution, polynomial dividing.
// q returns the quotient, r returns the remainder.
void deconv(const Poly& u, const Poly& v, Poly& q, Poly& r) {
int n = u.size() - 1;
int nv = v.size() - 1;
q.assign(n+1, 0.0);
r = u;
for(int k = n-nv; k >= 0; k--) {
q[k] = r[nv+k] / v[nv];
for(int j = nv+k-1; j >= k; j--)
r[j] -= q[k] * v[j-k];
}
r.resize(nv);
}
示例6: deconv
// Slow deconvolution, polynomial dividing.
// q returns the quotient, r returns the remainder.
void deconv(const Poly& u, const Poly& v, Poly& q, Poly& r) {
int n = u.size() - 1;
int nv = v.size() - 1;
q.assign(n + 1, 0);
r = u;
for(int k = n-nv; k >= 0; k--) {
q[k] = r[nv+k];
for(int j = nv+k-1; j >= k; j--)
r[j] ^= (q[k] & v[j-k]);
}
r.resize(nv);
tidy(q);
tidy(r);
}
示例7: convexHull
Poly convexHull( Poly p ){
sort( p.begin(), p.end() );
int n = p.size(), k = 0;
Poly h ( 2 * n );
for( int i = 0; i < n; i++ ){
while( k >= 2 && ccw( h[k-2], h[k-1], p[i] ) <= 0 ) k--;
h[k++] = p[i];
}
int t = k + 1;
for( int i = n - 2; i >= 0; i-- ){
while( k >= t && ccw( h[k-2], h[k-1], p[i] ) <= 0 ) k--;
h[k++] = p[i];
}
h.resize( k - 1 );
return h;
}
示例8: setNumLoops
/**
Set the number of loops for one particular poly.
An \c EIndexError exception is thrown if \a poly is out of range.
*/
void PolyhedronGeom::setNumLoops(int poly, int num)
{
if ((poly<0) || (poly>=getNumPolys()))
throw EIndexError("Poly index out of range.");
if (num<0)
num=0;
Poly* polygon = polys[poly];
// Number of loops before the modification
int prevsize = polygon->size();
// Number of vertices removed (this number is used to adjust the constraint
// size for facevarying variables)
int lostverts = 0;
int i;
// Delete loops if the number of loops was decreased
if (num<prevsize)
{
for(i=num; i<prevsize; i++)
{
// Add the number of verts in the loop
lostverts += (*polygon)[i]->size();
// Delete the loop
delete (*polygon)[i];
}
}
// Resize loop list
polygon->resize(num);
// Allocate new loops...
// (the new loops have no verts, so lostverts doesn't have to be modified)
for(i=prevsize; i<num; i++)
{
(*polygon)[i] = new VertexLoop();
}
// Update the size constraint for facevarying variables...
// Todo: This probably shouldn't be done for every single modification
// again and again...
UserSizeConstraint* usc = dynamic_cast<UserSizeConstraint*>(faceVaryingSizeConstraint.get());
// std::cout<<"LOSTVERTS: "<<lostverts<<std::endl;
if (usc!=0)
usc->setSize(usc->getSize()-lostverts);
}
示例9: main
int main() {
init();
Poly now;
int N;
double left, right, ans;
while(cin >> N) {
now.resize(N+1);
for(int i = N; i >= 0; --i)
cin >> now[i];
cin >> left >> right;
for(int i = 0; i <= N; ++i) {
if(right > 0 || i % 2 == 0)
ans += now[i] * polyval(S[i], fabs(right)+1);
else
ans -= now[i] * polyval(S[i], fabs(right)+1);
if(left > 0 || i % 2)
ans -= now[i] * polyval(S[i], fabs(left - 1.0)+1);
else
ans += now[i] * polyval(S[i], fabs(left - 1.0)+1);
}
if(fabs(ans) < 1e-5) ans = 0;
printf("%.6le\n", ans);
}
}
示例10: add
// Polynomial addition a(x) += k * b(x).
void add(Poly& a, const Poly& b, double k = 1.0) {
if(a.size() < b.size())
a.resize(b.size(), 0);
for(int i = 0; i < b.size(); ++i)
a[i] += k * b[i];
}
示例11: if
std::vector<double> EllipticalArc::allNearestPoints( Point const& p, double from, double to ) const
{
std::vector<double> result;
if ( from > to ) std::swap(from, to);
if ( from < 0 || to > 1 )
{
THROW_RANGEERROR("[from,to] interval out of range");
}
if ( ( are_near(ray(X), 0) && are_near(ray(Y), 0) ) || are_near(from, to) )
{
result.push_back(from);
return result;
}
else if ( are_near(ray(X), 0) || are_near(ray(Y), 0) )
{
LineSegment seg(pointAt(from), pointAt(to));
Point np = seg.pointAt( seg.nearestPoint(p) );
if ( are_near(ray(Y), 0) )
{
if ( are_near(_rot_angle, M_PI/2)
|| are_near(_rot_angle, 3*M_PI/2) )
{
result = roots(np[Y], Y);
}
else
{
result = roots(np[X], X);
}
}
else
{
if ( are_near(_rot_angle, M_PI/2)
|| are_near(_rot_angle, 3*M_PI/2) )
{
result = roots(np[X], X);
}
else
{
result = roots(np[Y], Y);
}
}
return result;
}
else if ( are_near(ray(X), ray(Y)) )
{
Point r = p - center();
if ( are_near(r, Point(0,0)) )
{
THROW_INFINITESOLUTIONS(0);
}
// TODO: implement case r != 0
// Point np = ray(X) * unit_vector(r);
// std::vector<double> solX = roots(np[X],X);
// std::vector<double> solY = roots(np[Y],Y);
// double t;
// if ( are_near(solX[0], solY[0]) || are_near(solX[0], solY[1]))
// {
// t = solX[0];
// }
// else
// {
// t = solX[1];
// }
// if ( !(t < from || t > to) )
// {
// result.push_back(t);
// }
// else
// {
//
// }
}
// solve the equation <D(E(t),t)|E(t)-p> == 0
// that provides min and max distance points
// on the ellipse E wrt the point p
// after the substitutions:
// cos(t) = (1 - s^2) / (1 + s^2)
// sin(t) = 2t / (1 + s^2)
// where s = tan(t/2)
// we get a 4th degree equation in s
/*
* ry s^4 ((-cy + py) Cos[Phi] + (cx - px) Sin[Phi]) +
* ry ((cy - py) Cos[Phi] + (-cx + px) Sin[Phi]) +
* 2 s^3 (rx^2 - ry^2 + (-cx + px) rx Cos[Phi] + (-cy + py) rx Sin[Phi]) +
* 2 s (-rx^2 + ry^2 + (-cx + px) rx Cos[Phi] + (-cy + py) rx Sin[Phi])
*/
Point p_c = p - center();
double rx2_ry2 = (ray(X) - ray(Y)) * (ray(X) + ray(Y));
double sinrot, cosrot;
sincos(_rot_angle, sinrot, cosrot);
double expr1 = ray(X) * (p_c[X] * cosrot + p_c[Y] * sinrot);
Poly coeff;
coeff.resize(5);
coeff[4] = ray(Y) * ( p_c[Y] * cosrot - p_c[X] * sinrot );
coeff[3] = 2 * ( rx2_ry2 + expr1 );
coeff[2] = 0;
//.........这里部分代码省略.........