Exemplo n.º 1
0
 length() { return p.size(); }
Exemplo n.º 2
0
    return qs;
}

// ベクトルp, qのなす角(q->pの方向が正)
double thetaPP(P p, P q) {
    int sgn = cross(q, p) > 0 ? +1 : -1;
    return sgn * acos(dot(p, q) / abs(p) / abs(q));
}

// lがx軸となす角
double thetaL(L l) {
    return thetaPP(l.v, P(1, 0));
}

G rotG(G g, P p, double theta) {
    rep(i, g.size()) {
        g[i] = rotP(g[i], p, theta);
    }
    return g;
}

P centroidG(G g) {
    int n = g.size();
    double x = 0, y = 0;
    rep(i, n) {
        x += g[i].real();
        y += g[i].imag();
    }
    return P(x / n, y / n);
}