Ejemplo n.º 1
0
Matrix* matrix_qr_decomposition(Matrix M)
{
    assert(is_matrix(M));
    int m = M->r;
    int n = M->c;
    Matrix Q = matrix_new_empty(m, n);
    for(int i = 0; i < n; i++) {
        double* u = matrix_column_vector(M, i);
        double* a = matrix_column_vector(M, i);
        for(int k = 0; k < i; k++) {
            double* e = matrix_column_vector(Q, k);
            double* p = vector_projection(e, a, m);
            free(e);
            for(int j = 0; j < m; j++)
                u[j] -= p[j];
            free(p);
        }
        free(a);
        double* e = vector_normalize(u, m);
        free(u);
        for(int l = 0; l < m; l++)
            Q->A[l][i] = e[l];
        free(e);
    }
    Matrix Qt = matrix_transpose(Q);
    Matrix R = matrix_multiply(Qt, M);
    matrix_free(Qt);

    Matrix* QR = calloc(2, sizeof(Matrix));
    QR[0] = Q;
    QR[1] = R;
    return QR;
}
Ejemplo n.º 2
0
void Bullet::rebound(sf::Vector2f center)
{
    sf::Vector2f diff = pos - center;
    sf::Vector2f proj = vector_projection(vel, diff);
    vel -= (float)2.0 * proj;
}