本文整理汇总了Python中UM.Math.Vector.Vector.getData方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.getData方法的具体用法?Python Vector.getData怎么用?Python Vector.getData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UM.Math.Vector.Vector
的用法示例。
在下文中一共展示了Vector.getData方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compose
# 需要导入模块: from UM.Math.Vector import Vector [as 别名]
# 或者: from UM.Math.Vector.Vector import getData [as 别名]
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
示例2: test_subtract
# 需要导入模块: from UM.Math.Vector import Vector [as 别名]
# 或者: from UM.Math.Vector.Vector import getData [as 别名]
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)
示例3: findFirstAngleNormal
# 需要导入模块: from UM.Math.Vector import Vector [as 别名]
# 或者: from UM.Math.Vector.Vector import getData [as 别名]
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: test_add
# 需要导入模块: from UM.Math.Vector import Vector [as 别名]
# 或者: from UM.Math.Vector.Vector import getData [as 别名]
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)
示例5: test_setValues
# 需要导入模块: from UM.Math.Vector import Vector [as 别名]
# 或者: from UM.Math.Vector.Vector import getData [as 别名]
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]))
示例6: setByRotationAxis
# 需要导入模块: from UM.Math.Vector import Vector [as 别名]
# 或者: from UM.Math.Vector.Vector import getData [as 别名]
def setByRotationAxis(self, angle: float, direction: Vector, point: Optional[List[float]] = None) -> None:
sina = math.sin(angle)
cosa = math.cos(angle)
direction_data = self._unitVector(direction.getData())
# rotation matrix around unit vector
R = numpy.diag([cosa, cosa, cosa])
R += numpy.outer(direction_data, direction_data) * (1.0 - cosa)
direction_data *= sina
R += numpy.array([[ 0.0, -direction_data[2], direction_data[1]],
[ direction_data[2], 0.0, -direction_data[0]],
[-direction_data[1], direction_data[0], 0.0]], dtype = numpy.float64)
M = numpy.identity(4)
M[:3, :3] = R
if point is not None:
# rotation not around origin
point = numpy.array(point[:3], dtype = numpy.float64, copy=False)
M[:3, 3] = point - numpy.dot(R, point)
self._data = M
示例7: TestVector
# 需要导入模块: from UM.Math.Vector import Vector [as 别名]
# 或者: from UM.Math.Vector.Vector import getData [as 别名]
class TestVector(unittest.TestCase):
def setUp(self):
# Called before the first testfunction is executed
self._vector = Vector(1, 0, 0)
pass
def tearDown(self):
# Called after the last testfunction was executed
pass
def test_getData(self):
numpy.testing.assert_array_almost_equal(self._vector.getData(), numpy.array([1, 0, 0]))
pass
def test_angleBetweenVectors(self):
second_vector = Vector(1, 0, 0)
third_vector = Vector(0, 1, 0)
fourth_vector = Vector(0, 0, 1)
# Check if angle with itself is 0
self.assertEqual(self._vector.angleToVector(second_vector), 0)
# Check if angle between the two vectors that are rotated in equal angle but different direction are the same
self.assertEqual(self._vector.angleToVector(third_vector), self._vector.angleToVector(fourth_vector))
def test_normalize(self):
pass
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]))
def test_negPos(self):
v = Vector(0, 1, 0)
self.assertEqual(Vector(0, -1, 0), -v)
self.assertEqual(Vector(0, 1, 0), v) # - should have no side effects
示例8: TestVector
# 需要导入模块: from UM.Math.Vector import Vector [as 别名]
# 或者: from UM.Math.Vector.Vector import getData [as 别名]
class TestVector(unittest.TestCase):
def setUp(self):
# Called before the first testfunction is executed
self._vector = Vector(1,0,0)
pass
def tearDown(self):
# Called after the last testfunction was executed
pass
def test_getData(self):
numpy.testing.assert_array_almost_equal(self._vector.getData(), numpy.array([1,0,0]))
def test_angleBetweenVectors(self):
second_vector = Vector(1,0,0)
third_vector = Vector(0,1,0)
fourth_vector = Vector(0,0,1)
# Check if angle with itself is 0
self.assertEqual(self._vector.angleToVector(second_vector), 0)
# Check if angle between the two vectors that are rotated in equal angle but different direction are the same
self.assertEqual(self._vector.angleToVector(third_vector), self._vector.angleToVector(fourth_vector))
def test_normalize(self):
vector = Vector(10, 10, 10)
assert vector.normalized().length() == 1
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]))
def test_negPos(self):
v = Vector(0, 1, 0)
self.assertEqual(Vector(0, -1, 0), -v)
self.assertEqual(Vector(0, 1, 0), v) # - should have no side effects
def test_compare(self):
short_vector = Vector(0, 1, 0)
long_vector = Vector(200, 300, 500)
assert short_vector < long_vector
assert long_vector > short_vector
assert not long_vector == None
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)
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)
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)
示例9: setByTranslation
# 需要导入模块: from UM.Math.Vector import Vector [as 别名]
# 或者: from UM.Math.Vector.Vector import getData [as 别名]
def setByTranslation(self, direction: Vector) -> None:
M = numpy.identity(4, dtype = numpy.float64)
M[:3, 3] = direction.getData()[:3]
self._data = M