本文整理汇总了Python中UM.Math.Vector.Vector类的典型用法代码示例。如果您正苦于以下问题:Python Vector类的具体用法?Python Vector怎么用?Python Vector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add
def test_add(self):
vector = Vector(0, 1, 0)
vector2 = Vector(1, 0, 1)
assert vector + vector2 == Vector(1, 1, 1)
assert vector + vector2.getData() == Vector(1, 1, 1)
vector += vector2
assert vector == Vector(1, 1, 1)
示例2: _rotateCamera
def _rotateCamera(self, x, y):
camera = self._scene.getActiveCamera()
if not camera or not camera.isEnabled():
return
self._scene.acquireLock()
dx = math.radians(x * 180.0)
dy = math.radians(y * 180.0)
diff = camera.getPosition() - self._origin
diff_flat = Vector(diff.x, 0.0, diff.z).getNormalized()
try:
new_angle = math.acos(diff_flat.dot(diff.getNormalized())) + dy
except ValueError:
return
m = Matrix()
m.setByRotationAxis(dx, Vector.Unit_Y)
if new_angle < (math.pi / 2 - 0.01):
m.rotateByAxis(dy, Vector.Unit_Y.cross(diff).normalize())
n = diff.multiply(m)
n += self._origin
camera.setPosition(n)
camera.lookAt(self._origin)
self._scene.releaseLock()
示例3: findFirstAngleNormal
def findFirstAngleNormal():
for i in range(1, ns - 1):
spt = spine[i]
z = (spine[i + 1] - spt).cross(spine[i - 1] - spt)
if z.length() > EPSILON:
return z
# All the spines are collinear. Fallback to the rotated source
# XZ plane.
# TODO: handle the situation where the first two spine points match
if len(spine) < 2:
return Vector(0, 0, 1)
v = spine[1] - spine[0]
orig_y = Vector(0, 1, 0)
orig_z = Vector(0, 0, 1)
if v.cross(orig_y).length() > EPSILON:
# Spine at angle with global y - rotate the z accordingly
a = v.cross(orig_y) # Axis of rotation to get to the Z
(x, y, z) = a.normalized().getData()
s = a.length()/v.length()
c = sqrt(1-s*s)
t = 1-c
m = numpy.array((
(x * x * t + c, x * y * t + z*s, x * z * t - y * s),
(x * y * t - z*s, y * y * t + c, y * z * t + x * s),
(x * z * t + y * s, y * z * t - x * s, z * z * t + c)))
orig_z = Vector(*m.dot(orig_z.getData()))
return orig_z
示例4: __init__
def __init__(self, *args, **kwargs):
super().__init__()
self._min = Vector()
self._max = Vector()
if len(args) == 3:
self.setLeft(-args[0] / 2)
self.setRight(args[0] / 2)
self.setTop(args[1] / 2)
self.setBottom(-args[1] / 2)
self.setBack(-args[2] / 2)
self.setFront(args[2] / 2)
if "minimum" in kwargs:
self._min = kwargs["minimum"]
if "maximum" in kwargs:
self._max = kwargs["maximum"]
## Sometimes the min and max are not correctly set.
if not self._max:
self._max = Vector()
if not self._min:
self._min = Vector()
self._ensureMinMax()
示例5: compose
def compose(self, scale: Vector = None, shear: Vector = None, angles: Vector = None, translate: Vector = None, perspective: Vector = None, mirror: Vector = None) -> None:
M = numpy.identity(4)
if perspective is not None:
P = numpy.identity(4)
P[3, :] = perspective.getData()[:4]
M = numpy.dot(M, P)
if translate is not None:
T = numpy.identity(4)
T[:3, 3] = translate.getData()[:3]
M = numpy.dot(M, T)
if angles is not None:
R = Matrix()
R.setByEuler(angles.x, angles.y, angles.z, "sxyz")
M = numpy.dot(M, R.getData())
if shear is not None:
Z = numpy.identity(4)
Z[1, 2] = shear.x
Z[0, 2] = shear.y
Z[0, 1] = shear.z
M = numpy.dot(M, Z)
if scale is not None:
S = numpy.identity(4)
S[0, 0] = scale.x
S[1, 1] = scale.y
S[2, 2] = scale.z
M = numpy.dot(M, S)
if mirror is not None:
mir = numpy.identity(4)
mir[0, 0] *= mirror.x
mir[1, 1] *= mirror.y
mir[2, 2] *= mirror.z
M = numpy.dot(M, mir)
M /= M[3, 3]
self._data = M
示例6: project
def project(self, position: Vector) -> Tuple[float, float]:
projection = self._projection_matrix
view = self.getWorldTransformation()
view.invert()
position = position.preMultiply(view)
position = position.preMultiply(projection)
return position.x / position.z / 2.0, position.y / position.z / 2.0
示例7: test_multiply
def test_multiply(self):
vector = Vector(2, 2, 2)
vector2 = Vector(2, 2, 2)
assert vector * vector2 == Vector(4, 4, 4)
assert vector * 2 == Vector(4, 4, 4)
assert vector.scale(vector2) == Vector(4, 4, 4)
vector *= vector2
assert vector == Vector(4, 4, 4)
示例8: test_subtract
def test_subtract(self):
vector = Vector(2, 2, 2)
vector2 = Vector(1, 1, 1)
assert vector - vector2 == Vector(1, 1, 1)
assert vector - vector2.getData() == Vector(1, 1, 1)
assert vector2 - vector == Vector(-1, -1, -1)
assert vector2 - vector.getData() == Vector(-1, -1, -1)
vector -= vector2
assert vector == Vector(1, 1, 1)
示例9: test_setValues
def test_setValues(self):
x = 10
y = 10
z = 10
temp_vector = Vector(x,y,z)
numpy.testing.assert_array_almost_equal(temp_vector.getData(), numpy.array([x,y,z]))
temp_vector2 = temp_vector.set(1, 2, 3)
numpy.testing.assert_array_almost_equal(temp_vector2.getData(), numpy.array([1, 2, 3]))
示例10: __init__
def __init__(self, minimum: Vector = Vector.Null, maximum: Vector = Vector.Null) -> None:
if minimum.x > maximum.x or minimum.y > maximum.y or minimum.z > maximum.z:
swapped_minimum = Vector(min(minimum.x, maximum.x), min(minimum.y, maximum.y), min(minimum.z, maximum.z))
swapped_maximum = Vector(max(minimum.x, maximum.x), max(minimum.y, maximum.y), max(minimum.z, maximum.z))
minimum = swapped_minimum
maximum = swapped_maximum
minimum.setRoundDigits(3)
maximum.setRoundDigits(3)
self._min = minimum #type: Vector
self._max = maximum #type: Vector
示例11: __init__
def __init__(self, *args, **kwargs):
self._position = Vector()
self._normal = None
if len(args) == 3:
self._position = Vector(args[0], args[1], args[2])
if "position" in kwargs:
self._position = kwargs["position"]
if "normal" in kwargs:
self._normal = kwargs["normal"]
示例12: Vertex
class Vertex(object):
## Construct a vertex.
#
# Possible keyword parameters:
# - position: Vector with the vertex' position.
# - normal: Vector with the vertex' normal
#
# Unnamed arguments:
# - x, y, z passed as numbers.
def __init__(self, *args, **kwargs):
self._position = Vector()
self._normal = None
if len(args) == 3:
self._position = Vector(args[0], args[1], args[2])
if "position" in kwargs:
self._position = kwargs["position"]
if "normal" in kwargs:
self._normal = kwargs["normal"]
## Get the position the vertex
# \returns position Vector
@property
def position(self):
return self._position
## Set the position the vertex
# \param position Vector
def setPosition(self, position):
self._position = position
## Get the normal the vertex
# \returns normal Vector
@property
def normal(self):
return self._normal
## Set the normal the vertex
# \param normal Vector
def setNormal(self, normal):
self._normal = normal
def hasNormal(self):
return self._normal != None
## Convert the vertex into a string, which is required for parsing over sockets / streams
# It's kinda hackish to do it this way, but it would take to much effort to implement myself.
def toString(self):
return numpy.array([self._position.x(),self._position.y(),self._position.z(),self._normal.x(),self._normal.y(),self._normal.z()]).tostring()
示例13: __init__
def __init__(self, parent = None):
super().__init__() # Call super to make multiple inheritence work.
self._children = []
self._mesh_data = None
self._position = Vector()
self._scale = Vector(1.0, 1.0, 1.0)
self._orientation = Quaternion()
self._transformation = None
self._world_transformation = None
self._derived_position = None
self._derived_orientation = None
self._derived_scale = None
self._inherit_orientation = True
self._inherit_scale = True
self._parent = parent
self._enabled = True
self._selectable = False
self._calculate_aabb = True
self._aabb = None
self._aabb_job = None
self._visible = True
self._name = ""
if parent:
parent.addChild(self)
示例14: __init__
def __init__(self, vertices=None, normals=None, indices=None, colors=None, uvs=None, file_name=None,
center_position=None, zero_position=None, type = MeshType.faces, attributes=None):
self._application = None # Initialize this later otherwise unit tests break
self._vertices = NumPyUtil.immutableNDArray(vertices)
self._normals = NumPyUtil.immutableNDArray(normals)
self._indices = NumPyUtil.immutableNDArray(indices)
self._colors = NumPyUtil.immutableNDArray(colors)
self._uvs = NumPyUtil.immutableNDArray(uvs)
self._vertex_count = len(self._vertices) if self._vertices is not None else 0
self._face_count = len(self._indices) if self._indices is not None else 0
self._type = type
self._file_name = file_name # type: Optional[str]
# original center position
self._center_position = center_position
# original zero position, is changed after transformation
if zero_position is not None:
self._zero_position = zero_position
else:
self._zero_position = Vector(0, 0, 0) # type: Vector
self._convex_hull = None # type: Optional[scipy.spatial.ConvexHull]
self._convex_hull_vertices = None # type: Optional[numpy.ndarray]
self._convex_hull_lock = threading.Lock()
self._attributes = {}
if attributes is not None:
for key, attribute in attributes.items():
new_value = {}
for attribute_key, attribute_value in attribute.items():
if attribute_key == "value":
new_value["value"] = NumPyUtil.immutableNDArray(attribute_value)
else:
new_value[attribute_key] = attribute_value
self._attributes[key] = new_value
示例15: __init__
def __init__(self, parent=None):
super().__init__() # Call super to make multiple inheritence work.
self._children = []
self._mesh_data = None
self._position = Vector()
self._scale = Vector(1.0, 1.0, 1.0)
self._orientation = Quaternion()
self._transformation = None
self._world_transformation = None
self._derived_position = None
self._derived_orientation = None
self._derived_scale = None
self._inherit_orientation = True
self._inherit_scale = True
self._parent = parent
self._enabled = True
self._selectable = False
self._calculate_aabb = True
self._aabb = None
self._aabb_job = None
self._visible = True
self._name = ""
self._decorators = []
self._bounding_box_mesh = None
self.boundingBoxChanged.connect(self.calculateBoundingBoxMesh)
self.parentChanged.connect(self._onParentChanged)
if parent:
parent.addChild(self)