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

Function rotatePoint

src/gamesbyexample/rotatingcube.py:104–134  ·  view source on GitHub ↗

Returns an (x, y, z) tuple of the x, y, z arguments rotated. The rotation happens 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

102
103
104def rotatePoint(x, y, z, ax, ay, az):
105 """Returns an (x, y, z) tuple of the x, y, z arguments rotated.
106
107 The rotation happens around the 0, 0, 0 origin by angles
108 ax, ay, az (in radians).
109 Directions of each axis:
110 -y
111 |
112 +-- +x
113 /
114 +z
115 """
116
117 # Rotate around x axis:
118 rotatedX = x
119 rotatedY = (y * math.cos(ax)) - (z * math.sin(ax))
120 rotatedZ = (y * math.sin(ax)) + (z * math.cos(ax))
121 x, y, z = rotatedX, rotatedY, rotatedZ
122
123 # Rotate around y axis:
124 rotatedX = (z * math.sin(ay)) + (x * math.cos(ay))
125 rotatedY = y
126 rotatedZ = (z * math.cos(ay)) - (x * math.sin(ay))
127 x, y, z = rotatedX, rotatedY, rotatedZ
128
129 # Rotate around z axis:
130 rotatedX = (x * math.cos(az)) - (y * math.sin(az))
131 rotatedY = (x * math.sin(az)) + (y * math.cos(az))
132 rotatedZ = z
133
134 return (rotatedX, rotatedY, rotatedZ)
135
136
137def adjustPoint(point):

Callers 1

rotatingcube.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected