packagize
This commit is contained in:
parent
abb54935ad
commit
002e7963c9
1 changed files with 5 additions and 202 deletions
31
transform.py
31
transform.py
|
|
@ -1,31 +0,0 @@
|
|||
import numpy
|
||||
from numpy import sin, cos
|
||||
|
||||
|
||||
def rotate(poly, theta: float, axis: int):
|
||||
s, c = sin(theta), cos(theta)
|
||||
v0 = poly['vertices'][:, axis - 2].copy()
|
||||
v1 = poly['vertices'][:, axis - 1].copy()
|
||||
poly['vertices'][:, axis - 2] = c * v0 - s * v1
|
||||
poly['vertices'][:, axis - 1] = s * v1 + c * v0
|
||||
|
||||
|
||||
def translate(poly, shift):
|
||||
poly['vertices'] += shift
|
||||
|
||||
|
||||
def scale(poly, factor):
|
||||
poly['vertices'] *= factor
|
||||
|
||||
|
||||
def shear(poly, factor: float, axb: int, axs: int):
|
||||
poly['vertices'][:, axb] += factor * poly['vertices'][:, axs]
|
||||
|
||||
|
||||
def affine(poly, mat):
|
||||
mat4x3 = mat[:, :3]
|
||||
mat4x1 = mat[:, 3]
|
||||
vh = mat4x3 @ poly['vertices'].T + mat4x1
|
||||
poly['vertices'] = vh[:3, :] / vh[3, :]
|
||||
|
||||
|
||||
Loading…
Reference in a new issue