MCPcopy Create free account
hub / github.com/PageBot/PageBot / Transform3D

Class Transform3D

Lib/pagebot/mathematics/transform3d.py:40–178  ·  view source on GitHub ↗

>>> t = Transform3D() >>> t = t.translate(30, 30, 0) >>> t = t.scale(2) >>> point = (30, 30, 0) >>> point2 = t.transformPoint(point) >>> print(point2) (90.0, 90.0, 0.0) >>> at = t.getAffineTransform2D(2) >>> print(at) [2.0, 0.0, 0.0, 2.0, 30.0, 30.0]

Source from the content-addressed store, hash-verified

38 yield x+dx, y+dy, z+dz
39
40class Transform3D:
41 """
42 >>> t = Transform3D()
43 >>> t = t.translate(30, 30, 0)
44 >>> t = t.scale(2)
45 >>> point = (30, 30, 0)
46 >>> point2 = t.transformPoint(point)
47 >>> print(point2)
48 (90.0, 90.0, 0.0)
49 >>> at = t.getAffineTransform2D(2)
50 >>> print(at)
51 [2.0, 0.0, 0.0, 2.0, 30.0, 30.0]
52 """
53 """
54 t = t.rotateX(self.angleX)
55 t = t.rotateY(self.angleY)
56 angle = self.angleY + math.radians(45)
57 localT = t.rotateY(math.radians(-90) * (angle // math.radians(90)))
58 self.affine = localT.getAffineTransform2D(2)
59 for item in self.items:
60 item.transformedPoint = t.transformPoint(item.point)
61 self.items.sort(key=lambda item: item.transformedPoint[2])
62 """
63
64 def __init__(self, matrix=None, offset=None):
65 if matrix is None:
66 matrix = ((1.0, 0.0, 0.0),
67 (0.0, 1.0, 0.0),
68 (0.0, 0.0, 1.0))
69
70 if offset is None:
71 offset = [0, 0, 0]
72
73 self.matrix = matrix
74 self.offset = offset
75
76 def translate(self, dx, dy, dz):
77 return self.transform(None, (dx, dy, dz))
78
79 def scale(self, xScale=1.0, yScale=None, zScale=None):
80 if yScale is None:
81 yScale = xScale
82
83 if zScale is None:
84 zScale = yScale
85
86 matrix = ((xScale, 0, 0), (0, yScale, 0), (0, 0, zScale))
87 return self.transform(matrix)
88
89 def rotate(self, angle):
90 c = math.cos(angle)
91 s = math.sin(angle)
92 return self.transform(((c, s, 0), (-s, c, 0), (0, 0, 1)))
93
94 def rotateX(self, angle):
95 s = math.sin(angle)
96 c = math.cos(angle)
97 return self.transform(((1, 0, 0), (0, c, -s), (0, s, c)))

Callers 1

setTransform3DMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected