Skip to main content

A library for 2D transformations and vector operations

Project description

from src.matiopy.transform2d.transform2d import Transform2D

Matiopy

(Transform Python)

License: MIT Github: Repo


A library for 2D transformations and vector operations

Dependencies


Install


You can install Matiopy from PyPI

pip install matiopy

Examples


  1. Constructor
import math
import numpy
from matiopy import Transform2D as t2d

# Make new Transform from SVG
"""
    a c e
    b d f
    0 0 1
"""
matrix = t2d.svg(1, 0, 0, 1, 0, 0)
print(matrix) # Result: Transform2D(1.0, 0.0, 0.0, 1.0, 0.0, 0.0)

# Make new Transform from components
_matrix = t2d.compose(
    translate_x=0,
    translate_y=0,
    scale_x=3,
    scale_y=4,
    angle=math.pi/3 # radians default
)
print(_matrix) # Result: Transform2D(1.50.., 3.46.., -2.59.., 2.00.., 0.0, 0.0)
  1. Translation
# Translate by dx=2, dy=2
matrix.translate(2, 2)
print(matrix) # Result: Transform2D(1.0, 0.0, 0.0, 1.0, 2.0, 2.0)
  1. Scaling
# Scale by x=2, y=3
matrix.scale(2, 3)
print(matrix) # Result: Transform2D(2.0, 0.0, 0.0, 3.0, 2.0, 2.0)
  1. Rotation
# Rotate by 45 degrees/radians (radians default)
matrix.rotate(45, atype='deg')
print(matrix) # Result: Transform2D(1.41.., 2.12.., -1.41.., 2.12.., 2.0, 2.0)
matrix.rotate(-math.pi/4)
print(matrix) # Result: Transform2D(2.0.., 0.0.., 0.00.., 3.0.., 2.0, 2.0)
  1. Use
# Apply to a dot list or Numpy array
dots_numpy = numpy.array([[0, 0], [1, 0], [1, 1], [0, 1]])
# You can use tuple as dots
dots_list = [[0, 0], (1, 0), [1, 1], (0, 1)]
print(matrix * dots_numpy)
# Result:
# [[2. 2.]
#  [4. 2.]
#  [4. 5.]
#  [2. 5.]]
print(matrix * dots_list)
# Result:
# [[2. 2.]
#  [4. 2.]
#  [4. 5.]
#  [2. 5.]]
  1. Inversion
# Invert Transform Matrix
matrix.inverse()
print(matrix)
# Original: Transform2D(2.0.., 0.0.., 0.00.., 3.0.., 2.0, 2.0)
# Result:   Transform2D(0.49.., 0.00.., 0.00.., 0.33.., -0.99.., -0.66..)
  1. Set Origin
# Set Transform origin
matrix.set_origin(0, 0)
print(matrix)
# Result:   Transform2D(0.49.., 0.00.., 0.00.., 0.33.., 0.0, 0.0)
  1. Reflect by axis
# Reflect Matrix
matrix.reflect(rtype='origin')
print(matrix) # Result: Transform2D(-0.49.., 0.00.., 0.00.., -0.33.., 0.0, 0.0)
matrix.reflect(rtype='x')
print(matrix) # Result: Transform2D(-0.49.., 0.00.., 0.00.., 0.33.., 0.0, 0.0)
matrix.reflect(rtype='y')
print(matrix) # Result: Transform2D(0.49.., 0.00.., 0.00.., 0.33.., 0.0, 0.0)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matiopy-1.0.5.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matiopy-1.0.5-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file matiopy-1.0.5.tar.gz.

File metadata

  • Download URL: matiopy-1.0.5.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.4

File hashes

Hashes for matiopy-1.0.5.tar.gz
Algorithm Hash digest
SHA256 e9f4ca6e8ebbc73c8eacdc6ac249ebff5bc1701073c42005ec54757188030046
MD5 31b9cc7aaf1b63f7696fc1ee0dcdb527
BLAKE2b-256 315bff0dc353a8ae3bb3711a7ca5c87b0873d5771772688546493f75d68b3c74

See more details on using hashes here.

File details

Details for the file matiopy-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: matiopy-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.4

File hashes

Hashes for matiopy-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c4466fa2cd3ec8d2da0595cacb970af5d7a82c6540a600beec85e58d9a6083c8
MD5 d44540cc2696bd4accd2a3a2ace6f0c0
BLAKE2b-256 334f5d4ba228f66cabb7aebc7334b707e6ae8d93c3f0da5ea78e04391c40df90

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page