コード例 #1
0
ファイル: euclid.py プロジェクト: worldmaker18349276/magicpy
 def _contains(self, other):
     if not is_Tuple(other) or len(other) != 3:
         return false
     v = Mat(other)
     if self.closed:
         return dot(v, self.direction) >= self.offset
     else:
         return dot(v, self.direction) > self.offset
コード例 #2
0
ファイル: euclid.py プロジェクト: worldmaker18349276/magicpy
 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)
コード例 #3
0
ファイル: euclid.py プロジェクト: worldmaker18349276/magicpy
 def as_abstract(self):
     """
     >>> from sympy import *
     >>> from symplus.strplus import init_mprinting
     >>> init_mprinting()
     >>> Halfspace().as_abstract()
     {(x, y, z) | z > 0}
     >>> Halfspace(3, [1,2,0]).as_abstract()
     {(x, y, z) | sqrt(5)*x/5 + 2*sqrt(5)*y/5 > 3}
     """
     if self.closed:
         expr = dot(r, self.direction) >= self.offset
     else:
         expr = dot(r, self.direction) > self.offset
     return AbstractSet((x,y,z), expr)
コード例 #4
0
ファイル: affine.py プロジェクト: worldmaker18349276/magicpy
def qmult(q1, q2):
    """
    >>> from sympy import *
    >>> from symplus.strplus import init_mprinting
    >>> init_mprinting()
    >>> q1 = rquat(pi/2, i)
    >>> q2 = rquat(pi/3, j)
    >>> rquat2rmat(q1) * rquat2rmat(q2)
    <BLANKLINE>
    [      1/2 0 sqrt(3)/2]
    [sqrt(3)/2 0      -1/2]
    [        0 1         0]
    >>> rquat2rmat(qmult(q1, q2))
    <BLANKLINE>
    [      1/2 0 sqrt(3)/2]
    [sqrt(3)/2 0      -1/2]
    [        0 1         0]
    """
    w1 = q1[0]
    xyz1 = Mat(q1[1:])
    w2 = q2[0]
    xyz2 = Mat(q2[1:])
    w = w1*w2 - dot(xyz1, xyz2)
    xyz = w1*xyz2 + w2*xyz1 + cross(xyz1, xyz2)
    return Mat([w] + xyz[:])
コード例 #5
0
ファイル: affine.py プロジェクト: worldmaker18349276/magicpy
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
コード例 #6
0
ファイル: euclid.py プロジェクト: worldmaker18349276/magicpy
 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)
コード例 #7
0
ファイル: affine.py プロジェクト: worldmaker18349276/magicpy
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
コード例 #8
0
ファイル: euclid.py プロジェクト: worldmaker18349276/magicpy
 def _image(self, func):
     if isinstance(func, EuclideanTransformation):
         direction = simplify(qrotate(func.rquat, func.parity*self.direction))
         offset = simplify(self.offset + dot(func.tvec, direction))
         closed = self.closed
         return Halfspace(
             offset=offset,
             direction=direction,
             closed=closed,
             normalization=False)
コード例 #9
0
ファイル: euclid.py プロジェクト: worldmaker18349276/magicpy
 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)
コード例 #10
0
ファイル: euclid.py プロジェクト: worldmaker18349276/magicpy
 def as_algebraic(self):
     coffset = dot(self.center, self.direction)
     return Intersection(
         SemiInfiniteCone(
             slope=self.radius/self.height,
             center=self.center,
             direction=self.direction,
             closed=self.closed,
             normalization=False),
         Halfspace(
             offset=-coffset - self.height,
             direction=-self.direction,
             closed=self.closed,
             normalization=False))
コード例 #11
0
ファイル: euclid.py プロジェクト: worldmaker18349276/magicpy
 def as_algebraic(self):
     center = simplify(self.center - project(self.center, self.direction))
     coffset = dot(self.center, self.direction)
     return Intersection(
         InfiniteCylinder(
             radius=self.radius,
             center=center,
             direction=self.direction,
             closed=self.closed,
             normalization=False),
         Halfspace(
             offset= coffset - self.height/sympify(2),
             direction= self.direction,
             closed=self.closed,
             normalization=False),
         Halfspace(
             offset=-coffset - self.height/sympify(2),
             direction=-self.direction,
             closed=self.closed,
             normalization=False))
コード例 #12
0
ファイル: euclid.py プロジェクト: worldmaker18349276/magicpy
 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)))