本文整理汇总了Python中UM.Math.Float.Float类的典型用法代码示例。如果您正苦于以下问题:Python Float类的具体用法?Python Float怎么用?Python Float使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Float类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rotationTo
def rotationTo(v1, v2):
d = v1.dot(v2)
if d >= 1.0:
return Quaternion() # Vectors are equal, no rotation needed.
q = None
if Float.fuzzyCompare(d, -1.0, 1e-6):
axis = Vector.Unit_X.cross(v1)
if Float.fuzzyCompare(axis.length(), 0.0):
axis = Vector.Unit_Y.cross(v1)
axis.normalize()
q = Quaternion()
q.setByAngleAxis(math.pi, axis)
else:
s = math.sqrt((1.0 + d) * 2.0)
invs = 1.0 / s
c = v1.cross(v2)
q = Quaternion(
c.x * invs,
c.y * invs,
c.z * invs,
s * 0.5
)
q.normalize()
return q
示例2: slerp
def slerp(start, end, amount):
if Float.fuzzyCompare(amount, 0.0):
return start
elif Float.fuzzyCompare(amount, 1.0):
return end
rho = math.acos(start.dot(end))
return (start * math.sin((1 - amount) * rho) + end * math.sin(amount * rho)) / math.sin(rho)
示例3: test_setByAxis
def test_setByAxis(self):
q = Quaternion()
q.setByAngleAxis(math.pi / 2, Vector.Unit_Z)
self.assertEqual(q.x, 0.0)
self.assertEqual(q.y, 0.0)
self.assertTrue(Float.fuzzyCompare(q.z, math.sqrt(2.0) / 2.0, 1e-6))
self.assertTrue(Float.fuzzyCompare(q.w, math.sqrt(2.0) / 2.0, 1e-6))
示例4: test_rotateVector
def test_rotateVector(self):
q1 = Quaternion()
q1.setByAngleAxis(math.pi / 2, Vector.Unit_Z)
v = Vector(0, 1, 0)
v = q1.rotate(v)
self.assertTrue(Float.fuzzyCompare(v.x, -1.0, 1e-6))
self.assertTrue(Float.fuzzyCompare(v.y, 0.0, 1e-6))
self.assertTrue(Float.fuzzyCompare(v.z, 0.0, 1e-6))
示例5: test_fromMatrix
def test_fromMatrix(self):
m = Matrix()
m.setByRotationAxis(math.pi / 2, Vector.Unit_Z)
q1 = Quaternion.fromMatrix(m)
q2 = Quaternion()
q2.setByAngleAxis(math.pi / 2, Vector.Unit_Z)
self.assertTrue(Float.fuzzyCompare(q1.x, q2.x, 1e-6))
self.assertTrue(Float.fuzzyCompare(q1.y, q2.y, 1e-6))
self.assertTrue(Float.fuzzyCompare(q1.z, q2.z, 1e-6))
self.assertTrue(Float.fuzzyCompare(q1.w, q2.w, 1e-6))
示例6: _onChangeTimerFinished
def _onChangeTimerFinished(self):
root = self._controller.getScene().getRoot()
for node in BreadthFirstIterator(root):
if node is root or type(node) is not SceneNode:
continue
bbox = node.getBoundingBox()
if not bbox or not bbox.isValid():
continue
# Mark the node as outside the build volume if the bounding box test fails.
if self._build_volume.getBoundingBox().intersectsBox(bbox) != AxisAlignedBox.IntersectionResult.FullIntersection:
node._outside_buildarea = True
else:
node._outside_buildarea = False
# Move the node upwards if the bottom is below the build platform.
move_vector = Vector()
if not Float.fuzzyCompare(bbox.bottom, 0.0):
move_vector.setY(-bbox.bottom)
# If there is no convex hull for the node, start calculating it and continue.
if not hasattr(node, "_convex_hull"):
if not hasattr(node, "_convex_hull_job"):
job = ConvexHullJob.ConvexHullJob(node)
job.start()
node._convex_hull_job = job
elif Selection.isSelected(node):
pass
else:
# Check for collisions between convex hulls
for other_node in BreadthFirstIterator(root):
# Ignore root, ourselves and anything that is not a normal SceneNode.
if other_node is root or type(other_node) is not SceneNode or other_node is node:
continue
# Ignore nodes that do not have the right properties set.
if not hasattr(other_node, "_convex_hull") or not other_node.getBoundingBox():
continue
# Check to see if the bounding boxes intersect. If not, we can ignore the node as there is no way the hull intersects.
if node.getBoundingBox().intersectsBox(other_node.getBoundingBox()) == AxisAlignedBox.IntersectionResult.NoIntersection:
continue
# Get the overlap distance for both convex hulls. If this returns None, there is no intersection.
overlap = node._convex_hull.intersectsPolygon(other_node._convex_hull)
if overlap is None:
continue
move_vector.setX(overlap[0] * 1.1)
move_vector.setZ(overlap[1] * 1.1)
if move_vector != Vector():
op = PlatformPhysicsOperation.PlatformPhysicsOperation(node, move_vector)
op.push()
if node.getBoundingBox().intersectsBox(self._build_volume.getBoundingBox()) == AxisAlignedBox.IntersectionResult.FullIntersection:
op = ScaleToBoundsOperation(node, self._build_volume.getBoundingBox())
op.push()
示例7: test_mirror
def test_mirror(self, data):
polygon = Polygon(numpy.array(data["points"], numpy.float32)) #Create a polygon with the specified points.
polygon.mirror(data["axis_point"], data["axis_direction"]) #Mirror over the specified axis.
points = polygon.getPoints()
assert len(points) == len(data["points"]) #Must have the same amount of vertices.
for point_index in range(len(points)):
assert len(points[point_index]) == len(data["answer"][point_index]) #Same dimensionality (2).
for dimension in range(len(points[point_index])):
assert Float.fuzzyCompare(points[point_index][dimension], data["answer"][point_index][dimension]) #All points must be equal.
示例8: test_project
def test_project(self):
p = Polygon(numpy.array([
[0.0, 1.0],
[1.0, 1.0],
[1.0, 2.0],
[0.0, 2.0]
], numpy.float32))
normal = numpy.array([0.0, 1.0])
self.assertEqual((1.0, 2.0), p.project(normal))
normal = numpy.array([1.0, 0.0])
self.assertEqual((0.0, 1.0), p.project(normal))
normal = numpy.array([math.sqrt(0.5), math.sqrt(0.5)])
result = p.project(normal)
self.assertTrue(Float.fuzzyCompare(result[0], 0.70710678), "{0} does not equal {1}".format(result[0], 0.70710678))
self.assertTrue(Float.fuzzyCompare(result[1], 2.12132034), "{0} does not equal {1}".format(result[1], 2.12132034))
示例9: test_project
def test_project(self, data):
p = Polygon(numpy.array([
[0.0, 1.0],
[1.0, 1.0],
[1.0, 2.0],
[0.0, 2.0]
], numpy.float32))
result = p.project(data["normal"]) #Project the polygon onto the specified normal vector.
assert len(result) == len(data["answer"]) #Same dimensionality (2).
for dimension in range(len(result)):
assert Float.fuzzyCompare(result[dimension], data["answer"][dimension])
示例10: setObjectHeight
def setObjectHeight(self, height):
obj = Selection.getSelectedObject(0)
if obj:
height = float(height)
obj_height = obj.getBoundingBox().height
if not Float.fuzzyCompare(obj_height, height, DIMENSION_TOLERANCE):
scale_factor = height / obj_height
if self._non_uniform_scale:
scale_vector = Vector(1, scale_factor, 1)
else:
scale_vector = Vector(scale_factor, scale_factor, scale_factor)
Selection.applyOperation(ScaleOperation, scale_vector)
示例11: setObjectDepth
def setObjectDepth(self, depth):
obj = Selection.getSelectedObject(0)
if obj:
depth = float(depth)
obj_depth = obj.getBoundingBox().depth
if not Float.fuzzyCompare(obj_depth, depth, DIMENSION_TOLERANCE):
scale_factor = depth / obj_depth
if self._non_uniform_scale:
scale_vector = Vector(1, 1, scale_factor)
else:
scale_vector = Vector(scale_factor, scale_factor, scale_factor)
Selection.applyOperation(ScaleOperation, scale_vector)
示例12: setObjectWidth
def setObjectWidth(self, width):
obj = Selection.getSelectedObject(0)
if obj:
width = float(width)
obj_width = obj.getBoundingBox().width
if not Float.fuzzyCompare(obj_width, width, DIMENSION_TOLERANCE):
scale_factor = width / obj_width
if self._non_uniform_scale:
scale_vector = Vector(scale_factor, 1, 1)
else:
scale_vector = Vector(scale_factor, scale_factor, scale_factor)
Selection.applyOperation(ScaleOperation, scale_vector, scale_around_point = obj.getWorldPosition())
示例13: setX
def setX(self, x):
parsed_x = self._parseInt(x)
bounding_box = Selection.getBoundingBox()
op = GroupedOperation()
if not Float.fuzzyCompare(parsed_x, float(bounding_box.center.x), DIMENSION_TOLERANCE):
for selected_node in Selection.getAllSelectedObjects():
world_position = selected_node.getWorldPosition()
new_position = world_position.set(x=parsed_x + (world_position.x - bounding_box.center.x))
node_op = TranslateOperation(selected_node, new_position, set_position = True)
op.addOperation(node_op)
op.push()
self._controller.toolOperationStopped.emit(self)
示例14: setObjectWidth
def setObjectWidth(self, width):
obj = Selection.getSelectedObject(0)
if obj:
width = float(width)
obj_width = obj.getBoundingBox().width
if not Float.fuzzyCompare(obj_width, width, DIMENSION_TOLERANCE):
scale_factor = width / obj_width
if self._non_uniform_scale:
scale_vector = Vector(scale_factor, 1, 1)
else:
scale_vector = Vector(scale_factor, scale_factor, scale_factor)
self._scaleSelectedNodes(scale_vector)
示例15: intersectsRay
def intersectsRay(self, ray):
w = ray.origin - (self._normal * self._distance)
nDotR = self._normal.dot(ray.direction)
nDotW = -self._normal.dot(w)
if Float.fuzzyCompare(nDotR, 0.0):
return False
t = nDotW / nDotR
if t < 0:
return False
return t