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


Python Vector.cross方法代码示例

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


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

示例1: reflex_factor

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cross [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

示例2: cull_faces

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cross [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

示例3: Camera

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cross [as 别名]
class Camera(object):

    def __init__(self, view_normal, view_up, view_reference_point):
        self.view_reference = Vector(view_reference_point)

        self.view_normal = Vector(view_normal).normalize()
        self.view_up     = Vector(view_up).normalize()
        self.view_right  = self.view_up.cross(self.view_normal).normalize()


    def make_rotation_matrix(self):
        m = Matrix(4, 4)
        m.matrix[0] = self.view_right.vec  + [0.0]
        m.matrix[1] = self.view_up.vec     + [0.0]
        m.matrix[2] = self.view_normal.vec + [0.0]
        return m


    def make_translation_matrix(self):
        view_ref = self.view_reference.scalar_multiply(-1.0)
        return Matrix(4, 4).translate_3d(view_ref.vec)

    def get_view_transforms(self):
       return [
            self.make_translation_matrix(),
            self.make_rotation_matrix(),
       ]
开发者ID:drewbanin,项目名称:computer-graphics,代码行数:29,代码来源:camera.py

示例4: TestVector

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cross [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

示例5: rotation_of

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cross [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

示例6: all_outside

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cross [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

示例7: lookAtLH

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cross [as 别名]
    def lookAtLH(eye: Vector, target: Vector, up: Vector):
        zaxis = (target - eye).normalize()
        xaxis = up.cross(zaxis).normalize()
        yaxis = zaxis.cross(xaxis).normalize()

        xeye = -xaxis.dot(eye)
        yeye = -yaxis.dot(eye)
        zeye = -zaxis.dot(eye)

        values = [
            xaxis.x, yaxis.x, zaxis.x, 0,
            xaxis.y, yaxis.y, zaxis.y, 0,
            xaxis.z, yaxis.z, zaxis.z, 0,
            xeye,    yeye,    zeye,    1,
        ]

        return Matrix(values)
开发者ID:happlebao,项目名称:rendererpy,代码行数:19,代码来源:matrix.py

示例8: test_cross_product

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cross [as 别名]
    def test_cross_product(self):
        v = Vector([5, 3, -2])
        w = Vector([-1, 0, 3])

        self.assertVecEqual([9, -13, 3], v.cross(w))
        self.assertEqual(v.cross(w), w.cross(v).times_scalar(-1), "Vector cross multiplication is anti-commutative")

        v = Vector([8.462, 7.893, -8.187])
        w = Vector([6.984, -5.975, 4.778])

        self.assertVecEqual([-11.205, -97.609, -105.685], v.cross(w), 3)
        self.assertEqual(v.cross(w), w.cross(v).times_scalar(-1), "Vector cross multiplication is anti-commutative")
开发者ID:calebpowell,项目名称:linear-algebra-py,代码行数:14,代码来源:test_vector.py

示例9: __init__

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cross [as 别名]
class Camera:
    def __init__(self):
        super().__init__()
        self.position = Vector(0, 0, 0)
        self.point_at = Vector(0, 0, 0)
        self.focal_length = 1
        self.up = Vector(0, 1, 0)
        self.fov = 60

    def normal(self):
        return (self.position - self.point_at).normalized()

    def u(self):
        return self.up.cross(self.normal()).normalized()

    def v(self):
        return self.normal().cross(self.u()).normalized()

    def __repr__(self):
        return "Camera at {0}, pointing {1}".format(self.position, self.point_at)
开发者ID:makononov,项目名称:PyRT,代码行数:22,代码来源:camera.py

示例10: test_cross_product

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cross [as 别名]
    def test_cross_product(self):
        v1 = Vector([2,3,4])
        v2 = Vector([5,6,7])

        crossed = v1.cross(v2)
        self.compareVector(crossed.vec, [-3, 6, -3])
开发者ID:drewbanin,项目名称:computer-graphics,代码行数:8,代码来源:test_transform_3d.py

示例11: test_cross

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

    assert v1.cross(v2) == Vector(9, -13, 3)
开发者ID:ryanleland,项目名称:Linear.py,代码行数:7,代码来源:test_vector.py

示例12: test_cross_product

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

        self.assertEqual(v1.cross(v2), Vector([9,-13,3]))
开发者ID:aenfield,项目名称:UdacityLinearAlgebra,代码行数:7,代码来源:vector_test.py

示例13: print

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

print('#1 cross')
v = Vector([8.462, 7.893, -8.187])
w = Vector([6.984, -5.975, 4.778])
print(v.cross(w))

print('#2 area of parallelogram')
v = Vector([-8.987, -9.838, 5.031])
w = Vector([-4.268, -1.861, -8.866])
print(v.area_parallelogram(w))

print('#3 area of triangle')
v = Vector([1.5, 9.547, 3.691])
w = Vector([-6.007, 0.124, 5.772])
print(v.area_triangle(w))
开发者ID:aqing1987,项目名称:s-app-layer,代码行数:18,代码来源:test-cross-vector.py

示例14: str

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cross [as 别名]
    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,代码行数:30,代码来源:__init__.py


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