MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / rotatePoint

Function rotatePoint

src/gamesbyexample/fireflies.py:139–168  ·  view source on GitHub ↗

Returns a 3D point that is rotated from the x, y, z point arguments. This new point is rotated around the (0, 0, 0) origin by angles ax, ay, az (in radians). Directions of each axis: -y | +-- +x / +z

(x, y, z, ax, ay, az)

Source from the content-addressed store, hash-verified

137
138
139def rotatePoint(x, y, z, ax, ay, az):
140 """Returns a 3D point that is rotated from the x, y, z point
141 arguments. This new point is rotated around the (0, 0, 0) origin
142 by angles ax, ay, az (in radians).
143 Directions of each axis:
144 -y
145 |
146 +-- +x
147 /
148 +z
149 """
150
151 # Rotate around x axis:
152 rotatedX = x
153 rotatedY = (y * math.cos(ax)) - (z * math.sin(ax))
154 rotatedZ = (y * math.sin(ax)) + (z * math.cos(ax))
155 x, y, z = rotatedX, rotatedY, rotatedZ
156
157 # Rotate around y axis:
158 rotatedX = (z * math.sin(ay)) + (x * math.cos(ay))
159 rotatedY = y
160 rotatedZ = (z * math.cos(ay)) - (x * math.sin(ay))
161 x, y, z = rotatedX, rotatedY, rotatedZ
162
163 # Rotate around z axis:
164 rotatedX = (x * math.cos(az)) - (y * math.sin(az))
165 rotatedY = (x * math.sin(az)) + (y * math.cos(az))
166 rotatedZ = z
167
168 return (rotatedX, rotatedY, rotatedZ)
169
170
171def transformPoint(point):

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected