Ejemplo n.º 1
0
def spherical2cartesian(theta, phi):
    # Convert: Spherical -> Cartesian coordinates
    [sin_theta, cos_theta] = ek.sincos(theta)
    [sin_phi, cos_phi] = ek.sincos(phi)

    from mitsuba.core import Vector3f
    omega = Vector3f(cos_phi * sin_theta, sin_phi * sin_theta, cos_theta)
    return omega
Ejemplo n.º 2
0
def euler_to_quat(a):
    name = _ek.detail.array_name('Quaternion', a.Type, [4], a.IsScalar)
    module = _modules.get(a.__module__)
    Quat4f = getattr(module, name)

    angles = a / 2.0
    sr, cr = _ek.sincos(angles.x)
    sp, cp = _ek.sincos(angles.y)
    sy, cy = _ek.sincos(angles.z)

    w = cr * cp * cy + sr * sp * sy
    x = sr * cp * cy - cr * sp * sy
    y = cr * sp * cy + sr * cp * sy
    z = cr * cp * sy - sr * sp * cy
    return Quat4f(x, y, z, w)
Ejemplo n.º 3
0
def test09_trig():
    for i in range(-5, 5):
        for j in range(-5, 5):
            a = ek.sin(C(i, j))
            b = C(cmath.sin(complex(i, j)))
            assert ek.allclose(a, b)

            a = ek.cos(C(i, j))
            b = C(cmath.cos(complex(i, j)))
            assert ek.allclose(a, b)

            sa, ca = ek.sincos(C(i, j))
            sb = C(cmath.sin(complex(i, j)))
            cb = C(cmath.cos(complex(i, j)))
            assert ek.allclose(sa, sb)
            assert ek.allclose(ca, cb)

            # Python appears to handle the branch cuts
            # differently from Enoki, C, and Mathematica..
            a = ek.asin(C(i, j + 0.1))
            b = C(cmath.asin(complex(i, j + 0.1)))
            assert ek.allclose(a, b)

            a = ek.acos(C(i, j + 0.1))
            b = C(cmath.acos(complex(i, j + 0.1)))
            assert ek.allclose(a, b)

            if abs(j) != 1 or i != 0:
                a = ek.atan(C(i, j))
                b = C(cmath.atan(complex(i, j)))
                assert ek.allclose(a, b, atol=1e-7)
Ejemplo n.º 4
0
    def map_forward(self, p):
        from mitsuba.core import Vector3f

        cos_theta = -p.y
        sin_theta = ek.safe_sqrt(ek.fnmadd(cos_theta, cos_theta, 1))
        sin_phi, cos_phi = ek.sincos(p.x)

        return Vector3f(cos_phi * sin_theta, sin_phi * sin_theta, cos_theta)
Ejemplo n.º 5
0
def rotate(target_type, axis, angle):
    if target_type.IsQuaternion:
        s, c = _ek.sincos(angle * .5)
        quat = target_type()
        quat.imag = axis * s
        quat.real = c
        return quat
    else:
        raise Exception("Unsupported target type!")
Ejemplo n.º 6
0
def sincos_(a0):
    if not a0.IsFloat:
        raise Exception("sincos(): requires floating point operands!")
    ar0, sr0 = _check1(a0)
    ar1 = a0.empty_(sr0 if a0.Size == Dynamic else 0)
    if not a0.IsSpecial:
        for i in range(sr0):
            result = _ek.sincos(a0[i])
            ar0[i] = result[0]
            ar1[i] = result[1]
    elif a0.IsComplex:
        s, c = _ek.sincos(a0.real)
        sh, ch = _ek.sincosh(a0.imag)
        ar0.real = s * ch
        ar0.imag = c * sh
        ar1.real = c * ch
        ar1.imag = -s * sh
    else:
        raise Exception("sincos(): unsupported array type!")
    return ar0, ar1
Ejemplo n.º 7
0
def exp_(a0):
    if not a0.IsFloat:
        raise Exception("exp(): requires floating point operands!")
    ar, sr = _check1(a0)
    if not a0.IsSpecial:
        for i in range(sr):
            ar[i] = _ek.exp(a0[i])
    elif a0.IsComplex:
        s, c = _ek.sincos(a0.imag)
        exp_r = _ek.exp(a0.real)
        ar.real = exp_r * c
        ar.imag = exp_r * s
    elif a0.IsQuaternion:
        qi = a0.imag
        ri = _ek.norm(qi)
        exp_w = _ek.exp(a0.real)
        s, c = _ek.sincos(ri)
        ar.imag = qi * (s * exp_w / ri)
        ar.real = c * exp_w
    else:
        raise Exception("exp(): unsupported array type!")
    return ar
Ejemplo n.º 8
0
def cot_(a0):
    if not a0.IsFloat:
        raise Exception("cot(): requires floating point operands!")
    if not a0.IsSpecial:
        ar, sr = _check1(a0)
        for i in range(sr):
            ar[i] = _ek.cot(a0[i])
    elif a0.IsComplex:
        s, c = _ek.sincos(a0)
        return c / s
    else:
        raise Exception("cot(): unsupported array type!")
    return ar
Ejemplo n.º 9
0
def cosh_(a0):
    if not a0.IsFloat:
        raise Exception("cosh(): requires floating point operands!")
    ar, sr = _check1(a0)
    if not a0.IsSpecial:
        for i in range(sr):
            ar[i] = _ek.cosh(a0[i])
    elif a0.IsComplex:
        s, c = _ek.sincos(a0.imag)
        sh, ch = _ek.sincosh(a0.real)
        ar.real = ch * c
        ar.imag = sh * s
    else:
        raise Exception("cosh(): unsupported array type!")
    return ar
Ejemplo n.º 10
0
def exp2_(a0):
    if not a0.IsFloat:
        raise Exception("exp2(): requires floating point operands!")
    ar, sr = _check1(a0)
    if not a0.IsSpecial:
        for i in range(sr):
            ar[i] = _ek.exp2(a0[i])
    elif a0.IsComplex:
        s, c = _ek.sincos(a0.imag * _ek.LogTwo)
        exp_r = _ek.exp2(a0.real)
        ar.real = exp_r * c
        ar.imag = exp_r * s
    else:
        raise Exception("exp2(): unsupported array type!")
    return ar
Ejemplo n.º 11
0
def sph_dir(theta, phi):
    """ Map spherical to Euclidean coordinates """
    st, ct = ek.sincos(theta)
    sp, cp = ek.sincos(phi)
    return Vector3f(cp * st, sp * st, ct)