本文整理汇总了Python中Matrix.Matrix.setValue方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.setValue方法的具体用法?Python Matrix.setValue怎么用?Python Matrix.setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.setValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSubtraction
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import setValue [as 别名]
def testSubtraction(self):
testMatrix1 = Matrix()
testMatrix2 = Matrix()
testMatrix3 = testMatrix1 - testMatrix2
for row in range(4):
for col in range(4):
self.assertTrue(testMatrix3.getValue(row, col) == 0)
testMatrix1.setValue(0, 3, 2.5)
testMatrix1.setValue(2, 2, 4.2)
testMatrix1.setValue(3, 0, -301)
testMatrix2.setValue(0, 3, -1)
testMatrix2.setValue(0, 0, -2)
testMatrix2.setValue(3, 0, 2)
testMatrix4 = testMatrix1 - testMatrix2
self.assertTrue(testMatrix4.getValue(0, 3) == 3.5)
self.assertTrue(testMatrix4.getValue(2, 2) == 4.2)
self.assertTrue(testMatrix4.getValue(3, 0) == -303)
self.assertTrue(testMatrix4.getValue(0, 0) == 2.0)
self.assertTrue(testMatrix4.getValue(2, 1) == 0)
示例2: testCreation
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import setValue [as 别名]
def testCreation(self):
testMatrix = Matrix()
for row in range(4):
for col in range(4):
self.assertTrue(testMatrix.getValue(row, col) == 0)
testMatrix.setValue(0, 0, 1.893)
testMatrix.setValue(2, 1, -200.1)
testMatrix.setValue(3, 2, 4)
self.assertTrue(testMatrix.getValue(0, 0) == 1.893)
self.assertTrue(testMatrix.getValue(2, 1) == -200.1)
self.assertTrue(testMatrix.getValue(3, 2) == 4)
示例3: testTransform
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import setValue [as 别名]
def testTransform(self):
testVector1 = Vector3(8.2, 1.524, 1.5)
testMatrix = Matrix()
testMatrix.setValue(3, 3, 1)
testMatrix.setValue(2, 2, 3)
testMatrix.setValue(1, 1, -1)
testMatrix.setValue(0, 0, 2)
testVector2 = testVector1.transform(testMatrix)
self.assertTrue(testVector2.x == 16.4)
self.assertTrue(testVector2.y == -1.524)
self.assertTrue(testVector2.z == 4.5)
示例4: Matrix
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import setValue [as 别名]
from Matrix import Matrix
m = Matrix (3,3)
m.setValue (3, 5.5)
print m.getValue(3)
m.printMatrix()
示例5: testMultiplication
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import setValue [as 别名]
def testMultiplication(self):
testMatrix1 = Matrix()
testMatrix2 = Matrix()
testMatrix3 = testMatrix1 * testMatrix2
for row in range(4):
for col in range(4):
self.assertTrue(testMatrix3.getValue(row, col) == 0)
testMatrix1.setValue(0, 3, 2.5)
testMatrix1.setValue(2, 2, 4.2)
testMatrix1.setValue(3, 0, -301)
testMatrix2.setValue(0, 3, -1)
testMatrix2.setValue(0, 0, -2)
testMatrix2.setValue(3, 0, 2)
testMatrix4 = testMatrix1 * testMatrix2
self.assertTrue(testMatrix4.getValue(0, 3) == 0)
self.assertTrue(testMatrix4.getValue(2, 2) == 0)
self.assertTrue(testMatrix4.getValue(3, 0) == 602)
self.assertTrue(testMatrix4.getValue(0, 0) == 5)
self.assertTrue(testMatrix4.getValue(2, 1) == 0)
self.assertTrue(testMatrix4.getValue(3, 3) == 301)
testMatrix5 = Matrix()
testMatrix5.setValue(0, 0, .5)
testMatrix5.setValue(0, 1, 7)
testMatrix5.setValue(0, 2, 2.9)
testMatrix5.setValue(0, 3, -1.0)
testMatrix5.setValue(1, 0, 9)
testMatrix5.setValue(1, 1, 1.1)
testMatrix5.setValue(1, 2, -302.01)
testMatrix5.setValue(1, 3, 21.0)
testMatrix5.setValue(2, 0, 0)
testMatrix5.setValue(2, 1, 1.8)
testMatrix5.setValue(2, 2, 9.9)
testMatrix5.setValue(2, 3, 10)
testMatrix5.setValue(3, 0, -4)
testMatrix5.setValue(3, 1, 2)
testMatrix5.setValue(3, 2, 1)
testMatrix5.setValue(3, 3, 8.9)
testMatrix6 = Matrix()
testMatrix6.setValue(0, 0, 18.2)
testMatrix6.setValue(0, 1, 2)
testMatrix6.setValue(0, 2, 4)
testMatrix6.setValue(0, 3, 6)
testMatrix6.setValue(1, 0, 1)
testMatrix6.setValue(1, 1, 2)
testMatrix6.setValue(1, 2, 4)
testMatrix6.setValue(1, 3, 3)
testMatrix6.setValue(2, 0, 9)
testMatrix6.setValue(2, 1, 8)
testMatrix6.setValue(2, 2, 7)
testMatrix6.setValue(2, 3, 5)
testMatrix6.setValue(3, 0, .1)
testMatrix6.setValue(3, 1, .8)
testMatrix6.setValue(3, 2, -.5)
testMatrix6.setValue(3, 3, -12)
testMatrix7 = testMatrix5 * testMatrix6
self.assertTrue(round(testMatrix7.getValue(0, 0), 2) == 42.1)
self.assertTrue(round(testMatrix7.getValue(0, 1), 2) == 37.4)
self.assertTrue(round(testMatrix7.getValue(0, 2), 2) == 50.8)
self.assertTrue(round(testMatrix7.getValue(0, 3), 2) == 50.5)
self.assertTrue(round(testMatrix7.getValue(1, 0), 2) == -2551.09)
self.assertTrue(round(testMatrix7.getValue(1, 1), 2) == -2379.08)
self.assertTrue(round(testMatrix7.getValue(1, 2), 2) == -2084.17)
self.assertTrue(round(testMatrix7.getValue(1, 3), 2) == -1704.75)
self.assertTrue(round(testMatrix7.getValue(2, 0), 2) == 91.9)
self.assertTrue(round(testMatrix7.getValue(2, 1), 2) == 90.8)
self.assertTrue(round(testMatrix7.getValue(2, 2), 2) == 71.5)
self.assertTrue(round(testMatrix7.getValue(2, 3), 2) == -65.1)
self.assertTrue(round(testMatrix7.getValue(3, 0), 2) == -60.91)
self.assertTrue(round(testMatrix7.getValue(3, 1), 2) == 11.12)
self.assertTrue(round(testMatrix7.getValue(3, 2), 2) == -5.45)
self.assertTrue(round(testMatrix7.getValue(3, 3), 2) == -119.8)
示例6: Raytracer
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import setValue [as 别名]
class Raytracer(object):
"""Raytracer defines a renderer that accepts a Scene and uses the basic ray tracing algorithm to render it"""
def __init__(self, scene, maxRayDepth=3):
"""
Create a Raytracer object
Keyword arguments:
scene (Scene) -- the scene to render
maxRayDepth (int) -- the maximum recursive steps for the ray tracing
"""
self.scene = scene
self.maxRayDepth = maxRayDepth
#initialize private variables to be used at render time
self._curRayDepth = 1
self._toWorldTrans = Matrix()
self._viewWidth = 0
self._viewHeight = 0
def _initWorldTransformations(self):
"""
Initiliaze transformations and viewport variables to allow straigtforward world-to-view transformations
at render time.
"""
#initialize the transformation matrix using the scene's camera
self._toWorldTrans.setValue(0, 0, self.scene.camera.u.x)
self._toWorldTrans.setValue(1, 0, self.scene.camera.u.y)
self._toWorldTrans.setValue(2, 0, self.scene.camera.u.z)
self._toWorldTrans.setValue(0, 1, self.scene.camera.v.x)
self._toWorldTrans.setValue(1, 1, self.scene.camera.v.y)
self._toWorldTrans.setValue(2, 1, self.scene.camera.v.z)
self._toWorldTrans.setValue(0, 2, self.scene.camera.n.x)
self._toWorldTrans.setValue(1, 2, self.scene.camera.n.y)
self._toWorldTrans.setValue(2, 2, self.scene.camera.n.z)
self._toWorldTrans.setValue(0, 3, self.scene.camera.lookAt.x)
self._toWorldTrans.setValue(1, 3, self.scene.camera.lookAt.y)
self._toWorldTrans.setValue(2, 3, self.scene.camera.lookAt.z)
self._toWorldTrans.setValue(3, 3, 1.0)
#compute the dimensions of the viewport using the scene's camera
self._viewWidth = math.tan(math.radians(self.scene.camera.fov)) * abs(self.scene.camera.lookFrom.z - \
self.scene.camera.lookAt.z) * 2
self._viewHeight = self._viewWidth
def renderScene(self, imageWidth, imageHeight, outputPath):
"""
Render the scene with the specified parameters
Keyword arguments:
imageWidth (int) -- width in pixels of the image to render, this value must be the same as imageHeight
imageHeight (int) -- height in pixels of the image to render, this value must be the same as imageWidth
outputPath (str) -- path to write the rendered image
Note -- the current impelementation is limited to square images, so imageWidth must equal imageHeight
"""
if not imageWidth == imageHeight:
print "Error -- imageWidth must equal imageHeight"
return
#initialize world-to-view transformations and image
self._initWorldTransformations()
outputImg = Image.new("RGB", (imageWidth, imageHeight))
#iterate over each pixel
for i in range(imageWidth):
for j in range(imageHeight):
#get the direction from the camera to the current pixel
direction = self._rayDirection(j, i, imageWidth, imageHeight, self.scene.camera)
self._curRayDepth = 1
#recursively trace a ray into the scene
color = self._shootRay(self.scene.camera.lookFrom, direction)
#set the pixel in the image
outputImg.putpixel((j, i), (int(color.x * 255), int(color.y * 255), int(color.z * 255)))
#save the output image
outputImg.save(outputPath)
def _rayDirection(self, pixelX, pixelY, imageWidth, imageHeight, camera):
"""
Compute the direction of the ray with the given parameters
Keyword arguments:
pixelX (int) -- the horizontal pixel index of the image, (0, 0) is the top left of the image
pixelY (int) -- the vertical pixel index of the image, (0, 0) is the top left of the image
imageWidth (int) -- the total number of pixels horizontally in the image
imageHeight (int) -- the total number of pixels vertically in the image
#.........这里部分代码省略.........