(self, axis, degree)
| 304 | |
| 305 | |
| 306 | def rotate(self, axis, degree): |
| 307 | for index in range(len(self.v)): |
| 308 | self.v[index][0] -= self.center[0] |
| 309 | self.v[index][1] -= self.center[1] |
| 310 | self.v[index][2] -= self.center[2] |
| 311 | |
| 312 | theta = -degree * pi / 180 |
| 313 | if axis in (0, "x"): |
| 314 | rotation = ( |
| 315 | (1, 0, 0,), |
| 316 | (0, cos(theta), -sin(theta),), |
| 317 | (0, sin(theta), cos(theta),), |
| 318 | ) |
| 319 | self.x_r += degree |
| 320 | self.rotation = ( |
| 321 | (self.rotation[0][0], self.rotation[0][1] * rotation[1][1] + self.rotation[0][2] * rotation[1][2], self.rotation[0][1] * rotation[2][1] + self.rotation[0][2] * rotation[2][2],), |
| 322 | (self.rotation[1][0], self.rotation[1][1] * rotation[1][1] + self.rotation[1][2] * rotation[1][2], self.rotation[1][1] * rotation[2][1] + self.rotation[1][2] * rotation[2][2],), |
| 323 | (self.rotation[2][0], self.rotation[2][1] * rotation[1][1] + self.rotation[2][2] * rotation[1][2], self.rotation[2][1] * rotation[2][1] + self.rotation[2][2] * rotation[2][2],), |
| 324 | ) |
| 325 | for index, vertex in enumerate(self.v): |
| 326 | self.v[index] = [ |
| 327 | vertex[0], |
| 328 | vertex[1] * rotation[1][1] + vertex[2] * rotation[1][2], |
| 329 | vertex[1] * rotation[2][1] + vertex[2] * rotation[2][2], |
| 330 | ] |
| 331 | for index, normal in enumerate(self.vn): |
| 332 | self.vn[index] = [ |
| 333 | normal[0], |
| 334 | normal[1] * rotation[1][1] + normal[2] * rotation[1][2], |
| 335 | normal[1] * rotation[2][1] + normal[2] * rotation[2][2], |
| 336 | ] |
| 337 | elif axis in (1, "y"): |
| 338 | rotation = ( |
| 339 | (cos(theta), 0, sin(theta),), |
| 340 | (0, 1, 0,), |
| 341 | (-sin(theta), 0, cos(theta),), |
| 342 | ) |
| 343 | self.y_r += degree |
| 344 | self.rotation = ( |
| 345 | (self.rotation[0][0] * rotation[0][0] + self.rotation[0][2] * rotation[0][2], self.rotation[0][1], self.rotation[0][0] * rotation[2][0] + self.rotation[0][2] * rotation[2][2],), |
| 346 | (self.rotation[1][0] * rotation[0][0] + self.rotation[1][2] * rotation[0][2], self.rotation[1][1], self.rotation[1][0] * rotation[2][0] + self.rotation[1][2] * rotation[2][2],), |
| 347 | (self.rotation[2][0] * rotation[0][0] + self.rotation[2][2] * rotation[0][2], self.rotation[2][1], self.rotation[2][0] * rotation[2][0] + self.rotation[2][2] * rotation[2][2],), |
| 348 | ) |
| 349 | for index, vertex in enumerate(self.v): |
| 350 | self.v[index] = [ |
| 351 | vertex[0] * rotation[0][0] + vertex[2] * rotation[0][2], |
| 352 | vertex[1], |
| 353 | vertex[0] * rotation[2][0] + vertex[2] * rotation[2][2], |
| 354 | ] |
| 355 | for index, normal in enumerate(self.vn): |
| 356 | self.vn[index] = [ |
| 357 | normal[0] * rotation[0][0] + normal[2] * rotation[0][2], |
| 358 | normal[1], |
| 359 | normal[0] * rotation[2][0] + normal[2] * rotation[2][2], |
| 360 | ] |
| 361 | elif axis in (2, "z"): |
| 362 | rotation = ( |
| 363 | (cos(theta), -sin(theta), 0,), |
no outgoing calls
no test coverage detected