Ejemplo n.º 1
0
def test_spherical_projection():
    """Compared against tests in orix."""
    n = 10
    v_arr = np.random.random_sample(n * 3).reshape((n, 3))
    v = Vector3d(v_arr)

    # Vector3d
    polar = SphericalProjection.project(v_arr)
    assert np.allclose(polar[..., 0], v.theta.data)
    assert np.allclose(polar[..., 1], v.phi.data)
    assert np.allclose(polar[..., 2], v.r.data)
    assert np.allclose(get_theta(v), v.theta.data)
    assert np.allclose(get_phi(v), v.phi.data)
    assert np.allclose(get_r(v), v.r.data)

    # NumPy array
    polar2 = SphericalProjection.project(v)
    assert np.allclose(polar2[..., 0], v.theta.data)
    assert np.allclose(polar2[..., 1], v.phi.data)
    assert np.allclose(polar2[..., 2], v.r.data)
    assert np.allclose(get_theta(v_arr), v.theta.data)
    assert np.allclose(get_phi(v_arr), v.phi.data)
    assert np.allclose(get_r(v_arr), v.r.data)
Ejemplo n.º 2
0
    def project_cartesian(cartesian: np.ndarray,
                          radius: Optional[float] = 10) -> np.ndarray:
        """Return the Hesse normal form of plane(s) given by cartesian
        coordinates.

        Parameters
        ----------
        cartesian
            Cartesian coordinates x, y, z.
        radius
            Hesse radius. Default is 10.

        Returns
        -------
        hesse
            Hesse normal form coordinates distance and angle.
        """
        theta = get_theta(cartesian)
        hesse = np.zeros((theta.size, 2))
        hesse_distance = np.tan(0.5 * np.pi - theta)
        hesse[..., 0] = hesse_distance
        hesse[..., 1] = np.arccos(hesse_distance / radius)
        return hesse