Skip to main content

A math engine for controlling 3D objects

Project description

Py4DMath

Py4DMath is a math engine that contains functions which allows a 3D object to translate and rotate.

It consists of the following classes:

  1. Vectors
  2. Matrix
  3. Quaternions

Usage

Install the package using,

pip install Py4DMath

This package contains three main classes that are briefly described below. To learn more about each class please read through the comments found in the source code.

Vector3D

A class to represent a vector in 3D space.

...
Attributes
----------
  x: float
    the x position of the vector
  y: float
    the y position of the vector
  z: float
    the z position of the vector

Methods
----------
  copy():
    Returns a copy of the vector.
  show():
    Prints visual representation of the vector.
  add():
    Returns the result of vector addition.
  subtract():
    Returns the result of vector subtraction.
  multiply():
    Returns a vector multiplied by a scalar value.
  divide():
    Returns a vector divided by a scalar value.
  dot():
    Returns the dot product between two vectors.
  cross():
    Returns the cross product between two vectors.
  magnitude():
    Returns the magnitude of the vector.
  normalize():
    Returns the normalized unit vector.
  rotate():
    Rotates a vector using an angle and an axis.

Matrix3D

A class to represent a 3x3 matrix.

...
Attributes
----------
  matrix: float[9]
    the array representing the matrix (column-major format)

Static/Class Methods
----------
  getIdentityMatrix():
    Returns an identity matrix.

Methods
----------
  copy():
    Returns a copy of the matrix.
  show():
    Prints visual representation of matrix.
  add():
    Returns the result of matrix addition.
  subtract():
    Returns the result of matrix subtraction.
  scalar_multiply():
    Returns a vector multiplied by a scalar value.
  matrix_multiply():
    Returns a vector multiplied by another matrix.
  inverse():
    Returns the inverse of the matrix.
  transpose():
    Returns the transpose of the matrix.
  transform():
    Returns vector transformed by matrix.

Quaternion

A class representing a Quaternion.

q = s + v

where s is a scalar number, v is a vector representing an axis

...
Attributes
----------
  s: float
    the scalar number
  v: Vector3D
    the vector representing an axis

Static/Class Methods
----------
  getRotationQuaternion():
    Returns the rotation quaternion.

Methods
----------
  copy():
    Returns a copy of the quaternion.
  add():
    Returns the result of quaternion addition.
  subtract():
    Returns the result of quaternion subtraction.
  scalar_multiply():
    Returns the result of a quaternion multiplied by a scalar value.
  quaternion_multiply():
    Returns the result of quaternion multiplication.
  norm():
    Returns the norm of the quaternion.
  normalize():
    Returns the normalized quaternion (unit norm).
  conjugate():
    Returns the conjugate of the quaternion.
  inverse():
    Returns the inverse of the quaternion.

Developer's Guide

Prerequistes

  • Python 3.10+
  • virtualenv

Getting Started

The quickest way to get started working on this package is to run the command,

make init

Otherwise, you can follow these steps,

  1. Create a new virtual environment, if not already created
python -m virtualenv venv
  1. Activate the virtual environment
source venv/bin/activate
  1. Install dependencies
make install-deps
  1. Setup pre-commit hooks
pre-commit install

Version Changes

NOTE: When making updates to the source code, make sure to bump versions.

  1. Update the version number in Py4DMath/version.py, using semantic versioning.

  2. Update the CHANGES.txt with the new version number and detail what changed.

Deployment

This package is available on PyPi.

To deploy to PyPi,

  1. Build the dist package using make build

  2. Upload to PyPi using make upload

Contact

Nicholas Chumney - nicholas.chumney@outlook.com

Acknowledgements

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

Py4DMath-1.0.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

Py4DMath-1.0.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file Py4DMath-1.0.0.tar.gz.

File metadata

  • Download URL: Py4DMath-1.0.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for Py4DMath-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4b2293f43f72b7eab023fc9c30003acbcec62666f0996c23082eba987bf0b6a4
MD5 5c05955135b94c026de322faf3f05ccc
BLAKE2b-256 c9a4b24eaa31e3dc2d7ae51425832866bd7961ad6db0ea7f94690178b3521866

See more details on using hashes here.

File details

Details for the file Py4DMath-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: Py4DMath-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for Py4DMath-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9fb5cb908df7ddcd4d19e05659c9ab98da6b1d54669e59ed860113a9ec77f6ab
MD5 73e7894a810a7b4e7dc8e68fd461f4e7
BLAKE2b-256 19c949f8b285154c4b6d57926b265c27cf5e8c85fd1faae7f532d36bf4f88097

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