当前位置: 首页>>代码示例>>Python>>正文


Python Vector.dot方法代码示例

本文整理汇总了Python中Vector.Vector.dot方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.dot方法的具体用法?Python Vector.dot怎么用?Python Vector.dot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector.Vector的用法示例。


在下文中一共展示了Vector.dot方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: distFromPointToLine

# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import dot [as 别名]
def distFromPointToLine(p, p1, p2):
        line = Vector(p2) - Vector(p1)
        toP = Vector(p) - Vector(p1)
        dot = toP.dot(line)
        if 0 <= dot <= line.length ** 2:
                projection = toP.proj(line)
                rejection = toP - projection
                return rejection.length
        else:
                return min(toP.length, (Vector(p) - Vector(p2)).length)
开发者ID:alex-ozdemir,项目名称:truss-analyzer,代码行数:12,代码来源:Geometry.py

示例2: __init__

# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import dot [as 别名]
class Quaternion:
    """Representation of a quaternion, defined as:

    s + ai + bj + ck
    or
    [s,v]

    where s,a,b,c are scalars, v is a vector, 

    and i, j, k are defined such that:
    i^2 = j^2 = k^2 = ijk = -1
    ij = k, jk = i, ki = j
    ji = -k, kj = -i, ik = -j
    """

    def __init__(self, s, a, b, c):
        self.mPrintSpec = '%f'
        self.mScalar = s
        self.mVector = Vector(a, b, c)

    @staticmethod
    def fromScalarVector(scalar, vector):
        """Define a quaternion from a scalar and a vector."""
        # TODO: Refactor for performance.
        return Quaternion(scalar, vector[0], vector[1], vector[2])

    def clone(self):
        v = self.mVector[:]
        return Quaternion(self.mScalar, v[0], v[1], v[2])

    def __str__(self):
        return '[ %s, %s ]' % (self.mPrintSpec % self.mScalar, self.mVector)

    def str2(self):
        """Alternate way to represent a Quaternion as a string."""
        signs = [ ('+' if f >= 0 else '-') for f in self.mVector ]
        vals = [ abs(f) for f in self.mVector ]

        return '%s %s %si %s %sj %s %sk' % (self.mScalar, 
                                            signs[0],
                                            vals[0],
                                            signs[1],
                                            vals[1],
                                            signs[2],
                                            vals[2])

    def __eq__(self, q):
        'Equality operator.'
        return self.mScalar == q.mScalar and self.mVector == q.mVector

    def __ne__(self, q):
        'Not equals'
        return not self.__eq__(q)

    def compare(self, seq):
        """Compare the quaternion to a sequence assumed to be in
        the form [ s, a, b, c ]."""
        return (len(seq) == 4 and 
                self.mScalar == seq[0] and self.mVector[0] == seq[1] and
                self.mVector[1] == seq[2] and self.mVector[2] == seq[3])

    def __add__(self, q):
        'Return self + q'
        return Quaternion(self.mScalar + q.mScalar, 
                          self.mVector[0] + q.mVector[0],
                          self.mVector[1] + q.mVector[1], 
                          self.mVector[2] + q.mVector[2])

    def __sub__(self, q):
        'Return self - q'
        return Quaternion(self.mScalar - q.mScalar, 
                          self.mVector[0] - q.mVector[0],
                          self.mVector[1] - q.mVector[1], 
                          self.mVector[2] - q.mVector[2])

    def scale(self, s):
        'Scale this quaternion by scalar s in-place.'
        self.mScalar = self.mScalar * float(s)
        self.mVector.scale(s)

    def mults(self, s):
        'Return self * scalar as a new Quaternion.'
        r = Quaternion.fromScalarVector(self.mScalar, self.mVector)
        r.scale(s)
        return r

    def mul1(self, q):
        """Multiplication Algorithm 1:
        This is a very nice definition of the quaternion multiplication
        operator, but it is terribly inefficient."""
        s = self.mScalar * q.mScalar - self.mVector.dot(q.mVector)
        v = q.mVector.mults(self.mScalar) + \
            self.mVector.mults(q.mScalar) + \
            self.mVector.cross(q.mVector)
        return Quaternion.fromScalarVector(s, v)

    def mul2(self, q):
        """Multiplication Algorithm 2: This is a much more efficient
        implementation of quaternion multiplication. It isover 3x faster than
        mul1."""
#.........这里部分代码省略.........
开发者ID:pmbrennan,项目名称:math3d,代码行数:103,代码来源:Quaternion.py

示例3: test_dotProductWorks

# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import dot [as 别名]
 def test_dotProductWorks(self):
     v1 = Vector([1, 1])
     self.assertEqual(AutoReduceFraction(2), v1.dot(v1))
开发者ID:maxshort,项目名称:MatrixOps,代码行数:5,代码来源:VectorTest.py


注:本文中的Vector.Vector.dot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。