示例#1
0
 def _contains(self, other):
     if not is_Tuple(other) or len(other) != 3:
         return false
     v = Mat(other)
     p = v - self.center
     if self.closed:
         return norm(cross(p, self.direction)) <= self.slope*dot(p, self.direction)
     else:
         return norm(cross(p, self.direction)) < self.slope*dot(p, self.direction)
示例#2
0
 def _contains(self, other):
     if not is_Tuple(other) or len(other) != 3:
         return false
     v = Mat(other)
     p = v - self.center
     if self.closed:
         return norm(cross(p, self.direction))**2 <= self.radius**2
     else:
         return norm(cross(p, self.direction))**2 < self.radius**2
示例#3
0
    def _contains(self, other):
        if not is_Tuple(other) or len(other) != 3:
            return false
        v = Mat(other)

        if self.closed:
            return norm(v-self.center)**2 <= self.radius**2
        else:
            return norm(v-self.center)**2 < self.radius**2
示例#4
0
 def as_abstract(self):
     """
     >>> from sympy import *
     >>> from symplus.strplus import init_mprinting
     >>> init_mprinting()
     >>> Sphere().as_abstract()
     {(x, y, z) | x**2 + y**2 + z**2 < 1}
     >>> Sphere(3, [1,0,2]).as_abstract()
     {(x, y, z) | y**2 + (x - 1)**2 + (z - 2)**2 < 9}
     """
     if self.closed:
         expr = norm(r-self.center)**2 <= self.radius**2
     else:
         expr = norm(r-self.center)**2 < self.radius**2
     return AbstractSet((x,y,z), expr)
示例#5
0
def rquat2rmat(rquat):
    """
    >>> from sympy import *
    >>> from symplus.strplus import init_mprinting
    >>> init_mprinting()
    >>> t = Symbol('t', positive=True)
    >>> simplify(rquat2rmat(rquat(pi/3, i+j)))
    <BLANKLINE>
    [       3/4       1/4  sqrt(6)/4]
    [       1/4       3/4 -sqrt(6)/4]
    [-sqrt(6)/4 sqrt(6)/4        1/2]
    >>> simplify(rquat2rmat(rquat(t, i)))
    <BLANKLINE>
    [1      0       0]
    [0 cos(t) -sin(t)]
    [0 sin(t)  cos(t)]
    >>> simplify(rquat2rmat(rquat(t, i+k)))
    <BLANKLINE>
    [     cos(t/2)**2 -sqrt(2)*sin(t)/2       sin(t/2)**2]
    [sqrt(2)*sin(t)/2            cos(t) -sqrt(2)*sin(t)/2]
    [     sin(t/2)**2  sqrt(2)*sin(t)/2       cos(t/2)**2]
    """
    w = rquat[0]
    xyz = Mat(rquat[1:])
    return (1-2*norm(xyz)**2)*eye3 + 2*xyz*xyz.T + 2*w*cross(xyz)
示例#6
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)
示例#7
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)
示例#8
0
 def as_abstract(self):
     """
     >>> from sympy import *
     >>> from symplus.strplus import init_mprinting
     >>> init_mprinting()
     >>> SemiInfiniteCone().as_abstract()
     {(x, y, z) | sqrt(x**2 + y**2) < z}
     >>> SemiInfiniteCone(5, [0,0,0], [3,4,0]).as_abstract()
     {(x, y, z) | sqrt(z**2 + (4*x/5 - 3*y/5)**2) < 3*x + 4*y}
     """
     p = r - self.center
     if self.closed:
         expr = norm(cross(p, self.direction)) <= self.slope*dot(p, self.direction)
     else:
         expr = norm(cross(p, self.direction)) < self.slope*dot(p, self.direction)
     return AbstractSet((x,y,z), expr)
示例#9
0
 def as_abstract(self):
     """
     >>> from sympy import *
     >>> from symplus.strplus import init_mprinting
     >>> init_mprinting()
     >>> InfiniteCylinder().as_abstract()
     {(x, y, z) | x**2 + y**2 < 1}
     >>> InfiniteCylinder(2, [0,0,0], [0,1,1]).as_abstract()
     {(x, y, z) | x**2 + (-sqrt(2)*y/2 + sqrt(2)*z/2)**2 < 4}
     """
     p = r - self.center
     if self.closed:
         expr = norm(cross(p, self.direction))**2 <= self.radius**2
     else:
         expr = norm(cross(p, self.direction))**2 < self.radius**2
     return AbstractSet((x,y,z), expr)
示例#10
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)
示例#11
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)
示例#12
0
 def as_abstract(self):
     """
     >>> from sympy import *
     >>> from symplus.strplus import init_mprinting
     >>> init_mprinting()
     >>> Revolution(lambda h, s: h**2<s**2).as_abstract()
     {(x, y, z) | z**2 < x**2 + y**2}
     >>> Revolution(lambda h, s: h+1<s**2, [0,0,0], [3,4,0]).as_abstract()
     {(x, y, z) | 3*x/5 + 4*y/5 + 1 < z**2 + (4*x/5 - 3*y/5)**2}
     """
     p = r - self.center
     expr = self.func(dot(p, self.direction), norm(cross(p, self.direction)))
     return AbstractSet((x,y,z), expr)
示例#13
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)
示例#14
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)
示例#15
0
 def _contains(self, other):
     if not is_Tuple(other) or len(other) != 3:
         return false
     v = Mat(other)
     p = v - self.center
     return self.func(dot(p, self.direction), norm(cross(p, self.direction)))