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


Python Vector.dot方法代码示例

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


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

示例1: test_float_dot

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot [as 别名]
def test_float_dot():
    v1 = Vector(7.887, 4.138)
    v2 = Vector(-8.802, 6.776)

    assert v1.dot(v2) == -41.382286

    v1 = Vector(-5.955, -4.904, -1.874)
    v2 = Vector(-4.496, -8.755, 7.103)

    assert v1.dot(v2) == 56.397178000000004
开发者ID:ryanleland,项目名称:Linear.py,代码行数:12,代码来源:test_vector.py

示例2: reflex_factor

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot [as 别名]
	def reflex_factor(self, eartip):
		A, B, C = self.tri_at(eartip)
		AB = B - A
		BC = C - B
		# vector pointing outside
		AB_out = Vector.cross(AB, self.normal).unit()
		return Vector.dot(AB_out, BC.unit())
开发者ID:Anti-Mage,项目名称:ogre,代码行数:9,代码来源:pgon.py

示例3: cull_faces

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot [as 别名]
    def cull_faces(self, view_vector):
        """
        Given a Vector representing the view, this method returns a copy of
        this PolygonMatrix minus all the faces that are not visible to the view.

        view_vector: Vector, the view vector to cull in relation to.
        """
        if not isinstance(view_vector, Vector):
            raise TypeError("%s is not valid view Vector" % view_vector)
        culled_polygonmatrix = PolygonMatrix()
        for polygon in self:
            v1 = Vector([
                polygon[2][0] - polygon[0][0],
                polygon[2][1] - polygon[0][1],
                polygon[2][2] - polygon[0][2]
            ])
            v2 = Vector([
                polygon[1][0] - polygon[0][0],
                polygon[1][1] - polygon[0][1],
                polygon[1][2] - polygon[0][2]
            ])
            normal = Vector.cross(v1, v2)
            if Vector.dot(normal, view_vector) < 0:
                culled_polygonmatrix.add_polygon(*polygon)
        return culled_polygonmatrix
开发者ID:omgimanerd,项目名称:graphics,代码行数:27,代码来源:matrix.py

示例4: __init__

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot [as 别名]
class Plane:
	def __init__(self, dict, shader_dict):
		self.face_normal = Vector(*dict['face_normal']).normalize()
		self.offset = dict['offset']
		self.shader = shader_dict[dict['shader']]
	
	def intersect(self, ray):
		normalDotOrigin = self.face_normal.dot(ray.origin)
		normalDotDirection = self.face_normal.dot(ray.direction)
		
		if normalDotDirection >= 0:
			return None
		else:
			return Intersection(self, ray, (self.offset - normalDotOrigin) / normalDotDirection)
	
	def normal(self, point):
		return self.face_normal
开发者ID:sdao,项目名称:cloudraytracer,代码行数:19,代码来源:plane.py

示例5: collide

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot [as 别名]
    def collide(self, surface):
        """ Checks if the shape has collided with the surface.
            If it has, return True, else return False. """
        points = surface.get_points()

        surfaceVectors = surface.get_surface_vectors()
        normal = surfaceVectors[1]
        size = surface.get_size()

        distance = Vector(surface.get_center()) - Vector(self.get_center())

        if (
            abs(distance.dot(surfaceVectors[0])) < size[1]
            and abs(distance.dot(surfaceVectors[2])) < size[0]
            and abs(distance.dot(normal)) <= self.get_border_distance() + abs(self._velocity.dot(normal))
        ):
            return normal, normal * distance.dot(normal)
        else:
            return False, normal * distance.dot(normal)
开发者ID:axelri,项目名称:fluffy_spheres,代码行数:21,代码来源:shapes.py

示例6: rotation_of

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot [as 别名]
    def rotation_of(source, dest):
        """
        Returns a :class:`Quaternion` that represents a rotation from
        vector *source* to *dest*.

        :param source: A vector object.
        :param dest: A vector object.
        :return: :class:`Quaternion`
        """

        source = Vector(source.x, source.y, source.z)
        dest = Vector(dest.x, dest.y, dest.z)
        cross = source.cross(dest)
        cos_theta = source.dot(dest)

        # Return identity if the vectors are the same direction.
        if cos_theta >= 1.0:
            return Quaternion.identity()

        # Product of the square of the magnitudes.
        k = math.sqrt(source.dot(source), dest.dot(dest))

        # Return identity in the degenerate case.
        if k <= 0.0:
            return Quaternion.identity()

        # Special handling for vectors facing opposite directions.
        if cos_theta / k <= -1:
            x_axis = Vector(1, 0, 0)
            y_axis = Vector(0, 1, 1)
            if abs(source.dot(x_ais)) < 1.0:
                cross = source.cross(x_axis)
            else:
                cross = source.cross(y_axis)

        return Quaternion(cross.x, cross.y, cross.z, k + cos_theta)
开发者ID:DrustZ,项目名称:Fluxa,代码行数:38,代码来源:quaternion.py

示例7: all_outside

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot [as 别名]
	def all_outside(self, eartip, verts):
		tri = self.tri_at(eartip)
		A, B, C = tri
		sides = B - A, C - B, A - C
		# vector pointing outside
		normals = map(lambda x: Vector.cross(x, self.normal), sides)
		for vert in map(lambda x: self.pgon[x], verts):
			out = 0
			for i in range(3):
				outside_edge = Vector.dot(vert - tri[i], normals[i])
				if outside_edge:
					out = 1
			# vertex inside triangle
			if not out: return 0
		return 1
开发者ID:Anti-Mage,项目名称:ogre,代码行数:17,代码来源:pgon.py

示例8: test_dot_product

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot [as 别名]
    def test_dot_product(self):
        v = Vector([7.887, 4.138])
        w = Vector([-8.802, 6.776])

        self.assertEqual(round(v.dot(w), 6), -41.382286)
        self.assertEqual(v.dot(w), w.dot(v), "Vector dot multiplication is commutative")

        v = Vector([-5.955, -4.904, -1.874])
        w = Vector([-4.496, -8.755, 7.103])

        self.assertEqual(round(v.dot(w), 6), 56.397178)
        self.assertEqual(v.dot(w), w.dot(v), "Vector dot multiplication is commutative")
开发者ID:calebpowell,项目名称:linear-algebra-py,代码行数:14,代码来源:test_vector.py

示例9: TestVector

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot [as 别名]
class TestVector(unittest.TestCase):

    def setUp(self):
        self.vector1 = Vector(1, 0, 0)
        self.vector2 = Vector(0, 1, 0)
        self.vector3 = Vector(1, 0)
        self.vector4 = Vector(0, 1)

    def test_module(self):
        self.assertEqual(self.vector1.module, 1)

    def test_module2(self):
        self.assertEqual(self.vector1.module2, 1)

    def test_unit(self):
        self.assertEqual(self.vector1, Vector(1, 0, 0))

    def test_eq(self):
        self.assertTrue(self.vector1 == Vector(1, 0, 0))

    def test_mul(self):
        self.assertEqual(2 * self.vector1, Vector(2, 0, 0))

    def test_truediv(self):
        self.assertEqual(self.vector1 / 2, Vector(0.5, 0, 0))

    def test_add(self):
        self.assertEqual(self.vector1 + self.vector2, Vector(1, 1, 0))

    def test_neg(self):
        self.assertEqual(- self.vector1, Vector(-1, 0, 0))

    def test_sub(self):
        self.assertEqual(self.vector1 - self.vector2, Vector(1, -1, 0))

    def test_dot(self):
        self.assertEqual(self.vector1.dot(self.vector2), 0)

    def test_cross_3d(self):
        self.assertEqual(self.vector1.cross(self.vector2), Vector(0, 0, 1))

    def test_cross_not_3d(self):
        self.assertRaises(Exception, lambda: self.vector3.cross(self.vector4))
开发者ID:germtb,项目名称:Pysics,代码行数:45,代码来源:test_vector.py

示例10: TestVector

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot [as 别名]
class TestVector (unittest.TestCase):

	def setUp(self):
		self.vec5 = Vector(5,5)
		self.vec1 = Vector(1,1)
		self.vec0 = Vector(0,0)
		self.vecu = Vector(4,0)
		self.veci = Vector(0,4)
	
	def test_eq(self):
		v5 = Vector(0,0)
		v5.x = 5
		v5.y = 5
		#self.assertEqual(v5,self.vec5)
		self.assertTrue(v5 == self.vec5)
		self.assertTrue((v5 == self.vec1) is False)
	
	def test_ne(self):
		v5 = Vector(0,0)
		v5.x = 5
		v5.y = 5
		self.assertEqual(v5,self.vec5)
		self.assertTrue(v5 != self.vec1)
		self.assertTrue((v5 != self.vec5) is False)
	
	def test_add(self):
		v4 = self.vecu + self.veci
		self.assertEqual(v4,Vector(4,4))
		self.assertEqual(v4+self.vec1,self.vec5)
	
	def test_scale(self):
		v5 = self.vec1*4
		self.assertEqual(v5,self.vec5)
		self.assertRaises(TypeError,v5.__mul__,self.vec5)
	
	def test_dot(self):
		self.assertEqual(self.vecu.dot(self.veci),32)
	
	def test_str(self):
		#time.sleep(10)
		self.assertEqual(str("{'y': 5, 'x': 5}"),str(self.vec5))
开发者ID:Narcolapser,项目名称:Gedit-PyUnit-Plugin,代码行数:43,代码来源:test_vector.py

示例11: getValue

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot [as 别名]
    def getValue(self, x, y):
        # project point (x, y) onto vector
        v1 = Vector(x - self.centerX, y - self.centerY)
        # vector
        p = v1.project(self.direction);
        # adjust so the point is correct
        p.x += self.centerX
        p.y += self.centerY
        # get the vector from the point to (x, y)
        d = Vector(x - p.x, y - p.y)
        l = d.length()
							
        # normal of current vector
        n = Vector(self.direction.y, -self.direction.x)
						
        # adjust for sign on each side of the vector
        p = v1.dot(n)
        sign = 1.0
        if p > 0:
            sign = -1.0
						
        #print self.waveLength
        #print math.sin(self.theta + sign * l / self.waveLength)
        return math.sin(self.theta + sign * l / self.waveLength);
开发者ID:madisonb,项目名称:PysiCrystals,代码行数:26,代码来源:cartesian_wave.py

示例12: test_dot_product_with_zero_vector

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot [as 别名]
    def test_dot_product_with_zero_vector(self):
        v1 = Vector([1,2,-1])
        v2 = Vector([0,0,0])

        self.assertEqual(v1.dot(v2), 0)
        self.assertEqual(v2.dot(v1), 0)
开发者ID:aenfield,项目名称:UdacityLinearAlgebra,代码行数:8,代码来源:vector_test.py

示例13: test_dot

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot [as 别名]
 def test_dot(self):
     v1 = Vector()
     v1[1]=5;v1[2]=10;
     self.assertEqual(v1.dot({1:5}),25)
     self.assertEqual(v1.dot({1:2,2:1}), 20)
开发者ID:Nishchita,项目名称:library,代码行数:7,代码来源:vector_tests.py

示例14: str

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot [as 别名]
    l1=Line(p1,p2)
    print "p1 = " + str(p1)
    print "p2 = " + str(p2)
    print "l1 = " + str(l1)
    print "l1.length() = %f" % l1.length()
    pl1=Polyline([Point(0,0),Point(1,1),Point(1,0),Point(0,0)],closed=True)
    print "pl1 = " + str(pl1)
    print "pl1.length() = %f" % pl1.length()
    print "pl1.area() = %f" % pl1.area()
    v1 = Vector(1,2,3)
    print "v1 = " + str(v1)
    v2 = Vector(1,0,0)
    print "v2 = " + str(v2)
    v3 = Vector(0,1,0)
    print "v3 = " + str(v3)
    print "v1 dot v2 = " + str(v1.dot(v2))
    print "v2 cross v3= " + str(v2.cross(v3))
    print "v1 * 3 = " + str(v1 * 3)
    print "2 * v1 = " + str(2.0 * v1) #this doesn;t work becuse of the ordering of the arguments to __mul__, that sucks!
    print "v1 / 3 = " + str(v1/3)
    print "abs(v1) = " + str(abs(v1))
    print "v1 + 1 = " + str(v1+1)
    print "1 + v1 = " + str(1+v1)
    print "v1 - 1= " + str(v1 -1)
    print "v1 - p1 = " + str(v1-p1)

    am1 = AffineMatrix()
    am1 = am1.identity()
    print "am1 * p1 = %s" % str(am1 * p1)
    
开发者ID:ryansturmer,项目名称:gears,代码行数:31,代码来源:__init__.py

示例15: Vector

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot [as 别名]
from vector import Vector

k = Vector(1,3)
l = Vector(4,5)

print k, l
print k + l
print 2*k
print k*2
print k.dot(l)
print k * l # cross product

开发者ID:alvesjnr,项目名称:nature-of-code,代码行数:13,代码来源:exemplo_vector.py


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