18 lines
474 B
Python
18 lines
474 B
Python
import numpy as np
|
|
import Types as t
|
|
|
|
MAT_ISO = np.array([[0.5, 0.25], [-0.5, 0.25]])
|
|
MAT_CART = np.linalg.inv(MAT_ISO)
|
|
|
|
|
|
def from_iso(
|
|
uv: t.IsoCoord, scale: float = 1, origin: t.CartCoors = np.array([0, 0])
|
|
) -> t.CartCoors:
|
|
return (uv @ MAT_ISO) * scale + origin
|
|
|
|
|
|
def from_cart(
|
|
xy: t.CartCoors, scale: float = 1, origin: t.CartCoors = np.array([0, 0])
|
|
) -> t.IsoCoord:
|
|
return (((xy - origin) / scale) @ MAT_CART + np.array([0.5, 0.5])).astype(np.int32)
|