summaryrefslogtreecommitdiff
path: root/transform.py
blob: 1321c8cd325fa8bce52a742488684bcc8adfa0f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import numpy as np

def rotate(x, phi, n):
    """
    Rotate an array of points `x` through an angle phi counter-clockwise
    around the axis `n` (when looking towards +infinity).

    Source: Weisstein, Eric W. "Rotation Formula." Mathworld.
    """
    x = np.asarray(x)
    n = np.asarray(n)/np.linalg.norm(n)

    r = np.cos(phi)*np.identity(3) + (1-np.cos(phi))*np.outer(n,n) + \
        np.sin(phi)*np.array([[0,n[2],-n[1]],[-n[2],0,n[0]],[n[1],-n[0],0]])

    return np.inner(x,r)