本文整理汇总了Python中Vector.Vector.cross方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.cross方法的具体用法?Python Vector.cross怎么用?Python Vector.cross使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector.Vector
的用法示例。
在下文中一共展示了Vector.cross方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: volume
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import cross [as 别名]
def volume(self):
ps = Vector(self.p,self.s)
qs = Vector(self.q,self.s)
rs = Vector(self.r,self.s)
return ps * (qs.cross(rs))/6.0
示例2: __init__
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import cross [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."""
#.........这里部分代码省略.........