예제 #1
0
def mn2smat(mvec, nvec):
    """
    >>> from sympy import *
    >>> from symplus.strplus import init_mprinting
    >>> init_mprinting()
    >>> mn2smat(i,j)
    <BLANKLINE>
    [1 1 0]
    [0 1 0]
    [0 0 1]
    >>> mn2smat(i-j+2*k,2*j+k)
    <BLANKLINE>
    [1  2  1]
    [0 -1 -1]
    [0  4  3]
    >>> t,r,p,z,s = aff2trpzs(augment(m=_))
    >>> simplify(r)
    [sqrt(-34*sqrt(17) + 578)/34 2*sqrt(2)/sqrt(-sqrt(17) + 17) 0 0]'
    >>> simplify(z)
    [1 sqrt(17) sqrt(17)/17]'
    >>> simplify(s)
    [2 1 13/17]'
    """
    mvec = Mat(mvec)
    nvec = Mat(nvec)
    mvec = mvec - dot(mvec, normalize(nvec)) * normalize(nvec)
    return eye3 + mvec*nvec.T
예제 #2
0
def zvec2zmat(zvec):
    """
    >>> from sympy import *
    >>> from symplus.strplus import init_mprinting
    >>> init_mprinting()
    >>> zvec2zmat(j*3)
    <BLANKLINE>
    [1 0 0]
    [0 3 0]
    [0 0 1]
    >>> zvec2zmat(i-j)
    <BLANKLINE>
    [ 1/2 + sqrt(2)/2 -sqrt(2)/2 + 1/2 0]
    [-sqrt(2)/2 + 1/2  1/2 + sqrt(2)/2 0]
    [               0                0 1]
    >>> t,r,p,z,s = aff2trpzs(augment(m=_))
    >>> simplify(r)
    [2**(1/4)*3**(3/4)*sqrt(1 + sqrt(2) + sqrt(6))/6 0 0 (-6**(3/4) + 54**(1/4))/(6*sqrt(1 + sqrt(2) + sqrt(6)))]'
    >>> simplify(z)
    [sqrt(6)/2 2*sqrt(3)/3 1]'
    >>> simplify(s)
    [-1/3 0 0]'
    """
    zvec = Mat(zvec)
    nvec = normalize(zvec)
    zfac = norm(zvec)
    return eye3 + nvec*nvec.T*(zfac-1)
예제 #3
0
 def __new__(cls, func, center=[0,0,0], direction=[0,0,1], **kwargs):
     center = Mat(center)
     direction = Mat(direction)
     if norm(direction) == 0:
         raise ValueError
     direction = normalize(direction)
     return Basic.__new__(cls, func, center, direction)
예제 #4
0
 def __new__(cls, radius=1, center=[0,0,0], direction=[0,0,1], closed=False, **kwargs):
     """
     >>> from sympy import *
     >>> from symplus.strplus import init_mprinting
     >>> init_mprinting()
     >>> InfiniteCylinder()
     InfiniteCylinder(1, [0 0 0]', [0 0 1]', False)
     >>> InfiniteCylinder(2, [0,0,0], [0,1,1])
     InfiniteCylinder(2, [0 0 0]', [0 -sqrt(2)/2 -sqrt(2)/2]', False)
     >>> InfiniteCylinder().contains((1,1,1))
     False
     >>> InfiniteCylinder(2, [0,0,0], [0,1,1]).contains((1,1,1))
     True
     """
     normalization = kwargs.pop("normalization", True)
     radius = sympify(abs(radius))
     direction = Mat(direction)
     if normalization:
         if norm(direction) == 0:
             raise ValueError
         direction = simplify(normalize(direction))
     direction = max(direction, -direction, key=hash)
     center = Mat(center)
     if normalization:
         center = simplify(center - project(center, direction))
     closed = sympify(bool(closed))
     return Basic.__new__(cls, radius, center, direction, closed)
예제 #5
0
def rmat_k2d(d):
    d = normalize(d)
    if d == k:
        rot = eye(3)
    elif d == -k:
        rot = diag(1,-1,-1)
    else:
        rot = rquat2rmat(rquat(acos(dot(k, d)), cross(k, d)))
    return rot
예제 #6
0
 def __new__(cls, radius=1, height=2, center=[0,0,0], direction=[0,0,1], closed=False, **kwargs):
     normalization = kwargs.pop("normalization", True)
     radius = sympify(abs(radius))
     height = sympify(abs(height))
     center = Mat(center)
     direction = Mat(direction)
     if normalization:
         if norm(direction) == 0:
             raise ValueError
         direction = simplify(normalize(direction))
     direction = max(direction, -direction, key=hash)
     closed = sympify(bool(closed))
     return Basic.__new__(cls, radius, height, center, direction, closed)
예제 #7
0
def fvec2fmat(fvec):
    """
    >>> from sympy import *
    >>> from symplus.strplus import init_mprinting
    >>> init_mprinting()
    >>> fvec2fmat(i)
    <BLANKLINE>
    [-1 0 0]
    [ 0 1 0]
    [ 0 0 1]
    >>> fvec2fmat(i-sqrt(2)*j)
    <BLANKLINE>
    [        1/3 2*sqrt(2)/3 0]
    [2*sqrt(2)/3        -1/3 0]
    [          0           0 1]
    >>> t,r,p,z,s = aff2trpzs(augment(m=_))
    >>> r
    [0 sqrt(3)/3 -sqrt(6)/3 0]'
    >>> p
    -1
    """
    fvec = normalize(Mat(fvec))
    return eye3 - fvec*fvec.T*2
예제 #8
0
 def __new__(cls, offset=0, direction=[0,0,1], closed=False, **kwargs):
     """
     >>> from sympy import *
     >>> from symplus.strplus import init_mprinting
     >>> init_mprinting()
     >>> Halfspace()
     Halfspace(0, [0 0 1]', False)
     >>> Halfspace(3, [1,2,0])
     Halfspace(3, [sqrt(5)/5 2*sqrt(5)/5 0]', False)
     >>> Halfspace().contains((1,2,3))
     True
     >>> Halfspace(3, [1,2,0]).contains((1,2,3))
     False
     """
     normalization = kwargs.pop("normalization", True)
     offset = sympify(offset)
     direction = Mat(direction)
     if normalization:
         if norm(direction) == 0:
             raise ValueError
         direction = simplify(normalize(direction))
     closed = sympify(bool(closed))
     return Basic.__new__(cls, offset, direction, closed)
예제 #9
0
 def __new__(cls, slope=1, center=[0,0,0], direction=[0,0,1], closed=False, **kwargs):
     """
     >>> from sympy import *
     >>> from symplus.strplus import init_mprinting
     >>> init_mprinting()
     >>> SemiInfiniteCone()
     SemiInfiniteCone(1, [0 0 0]', [0 0 1]', False)
     >>> SemiInfiniteCone(5, [0,0,0], [3,4,0])
     SemiInfiniteCone(5, [0 0 0]', [3/5 4/5 0]', False)
     >>> SemiInfiniteCone().contains((-1,0,2))
     True
     >>> SemiInfiniteCone(5, [0,0,0], [3,4,0]).contains((-1,0,1))
     False
     """
     normalization = kwargs.pop("normalization", True)
     slope = sympify(abs(slope))
     center = Mat(center)
     direction = Mat(direction)
     if normalization:
         if norm(direction) == 0:
             raise ValueError
         direction = simplify(normalize(direction))
     closed = sympify(bool(closed))
     return Basic.__new__(cls, slope, center, direction, closed)
예제 #10
0
def rquat(th, axis):
    axis = Mat(axis)
    return Mat([cos(th/2)]).col_join(sin(th/2)*normalize(axis))