All Projects → adamlwgriffiths → Pyrr

adamlwgriffiths / Pyrr

Licence: other
3D mathematical functions using NumPy

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pyrr

Cglm
📽 Highly Optimized Graphics Math (glm) for C
Stars: ✭ 887 (+214.54%)
Mutual labels:  matrix, vector, opengl, 3d
Tiny Renderer
A tiny sotfware 3D renderer in 100 lines of Python
Stars: ✭ 120 (-57.45%)
Mutual labels:  opengl, 3d, numpy
Joml
A Java math library for OpenGL rendering calculations
Stars: ✭ 479 (+69.86%)
Mutual labels:  matrix, vector, opengl
Tensor Sensor
The goal of this library is to generate more helpful exception messages for numpy/pytorch matrix algebra expressions.
Stars: ✭ 532 (+88.65%)
Mutual labels:  matrix, vector, numpy
Mathematics for Machine Learning
Learn mathematics behind machine learning and explore different mathematics in machine learning.
Stars: ✭ 28 (-90.07%)
Mutual labels:  vector, matrix
GenericTensor
The only library allowing to create Tensors (matrices extension) with custom types
Stars: ✭ 42 (-85.11%)
Mutual labels:  vector, matrix
glm
OpenGL Mathematics (GLM)
Stars: ✭ 6,667 (+2264.18%)
Mutual labels:  vector, matrix
matlib
Matrix Functions for Teaching and Learning Linear Algebra and Multivariate Statistics, http://friendly.github.io/matlib/
Stars: ✭ 55 (-80.5%)
Mutual labels:  vector, matrix
matrixgl
Yet another matrix library for WebGL
Stars: ✭ 25 (-91.13%)
Mutual labels:  vector, matrix
saddle
SADDLE: Scala Data Library
Stars: ✭ 23 (-91.84%)
Mutual labels:  numpy, matrix
NDScala
N-dimensional arrays in Scala 3. Think NumPy ndarray, but type-safe over shapes, array/axis labels & numeric data types
Stars: ✭ 37 (-86.88%)
Mutual labels:  numpy, matrix
LinAlg
实现一个线性代数库,为Python写扩展。《程序猿的数学3 线性代数》读后笔记
Stars: ✭ 17 (-93.97%)
Mutual labels:  vector, matrix
sparse
Sparse matrix formats for linear algebra supporting scientific and machine learning applications
Stars: ✭ 136 (-51.77%)
Mutual labels:  vector, matrix
Tensor
A library and extension that provides objects for scientific computing in PHP.
Stars: ✭ 146 (-48.23%)
Mutual labels:  vector, matrix
SCNMathExtensions
Math extensions for SCNVector3, SCNQuaternion, SCNMatrix4
Stars: ✭ 32 (-88.65%)
Mutual labels:  vector, matrix
vec-la-fp
↗️ A tiny (functional) 2d linear algebra library
Stars: ✭ 21 (-92.55%)
Mutual labels:  vector, matrix
Matrix
Easy-to-use Scientific Computing library in/for C++ available for Linux and Windows.
Stars: ✭ 20 (-92.91%)
Mutual labels:  vector, matrix
Swiftish
A fully generic Swift vector & matrix library
Stars: ✭ 17 (-93.97%)
Mutual labels:  vector, matrix
geeks-for-geeks-solutions
✅ My own Amazon, Microsoft and Google SDE Coding challenge Solutions (offered by GeeksForGeeks).
Stars: ✭ 246 (-12.77%)
Mutual labels:  vector, matrix
python-twelve-tone
🎶 12-tone matrix to generate dodecaphonic melodies 🎶
Stars: ✭ 68 (-75.89%)
Mutual labels:  numpy, matrix

Pyrr

Build Status

Provides 3D mathematical functions using the power of NumPy.

Features

  • Object Oriented and Procedural interfaces
  • Matrix (3x3, 4x4)
  • Quaternion
  • Vector (3D, 4D)
  • Plane
  • Ray
  • Line / Line Segment (3D)
  • Rectangle (2D)
  • Axis Aligned Bounding Box (AABB / AAMBB)
  • Geometric collision / intersection testing

Documentation

View Pyrr's documentation online.

Examples

Maintain a rotation (quaternion) and translation (vector) and convert to a matrix

Object Oriented Interface

This is a long winded example to demonstrate various features.

from pyrr import Quaternion, Matrix44, Vector3
import numpy as np

point = Vector3([1.,2.,3.])
orientation = Quaternion()
translation = Vector3()
scale = Vector3([1.,1.,1.])

# translate along X by 1
translation += [1.0, 0.0, 0.0]

# rotate about Y by pi/2
rotation = Quaternion.from_y_rotation(np.pi / 2.0)
orientation = rotation * orientation

# create a matrix
matrix = Matrix44.identity()

# apply our translation
matrix = matrix * Matrix44.from_translation(translation)

# apply our orientation
# we can multiply matricies and quaternions directly!
matrix = matrix * orientation

# apply our scale
matrix = matrix * Matrix44.from_scale(scale)

# transform our point by the matrix
# vectors are transformable by matrices and quaternions directly
point = matrix * point

Procedural Interface

from pyrr import quaternion, matrix44, vector3
import numpy as np

point = vector3.create(1.,2.,3.)
orientation = quaternion.create()
translation = vector3.create()
scale = vector3.create(1,1,1)

# translate along X by 1
translation += [1.0, 0.0, 0.0]

# rotate about Y by pi/2
rotation = quaternion.create_from_y_rotation(np.pi / 2.0)
orientation = quaternion.cross(rotation, orientation)

# create a matrix
matrix = matrix44.create_identity()

# apply our translation
translation_matrix = matrix44.create_from_translation(translation)
matrix = matrix44.multiply(matrix, translation_matrix)

# apply our orientation
orientation_matrix = matrix44.create_from_quaternion(orientation)
matrix = matrix44.multiply(matrix, orientation_matrix)

# start our matrix off using the scale
scale_matrix = matrix44.create_from_scale(scale)
matrix = matrix44.multiply(matrix, scale_matrix)

# transform our point by the matrix
point = matrix44.apply_to_vector(matrix, point)

Object Oriented Features

Convertable types

from pyrr import Quaternion, Matrix33, Matrix44, Vector3, Vector4

v3 = Vector3([1.,0.,0.])
v4 = Vector4.from_vector3(v3, w=1.0)
v3, w = Vector3.from_vector4(v4)

m44 = Matrix44()
q = Quaternion(m44)
m33 = Matrix33(q)

m33 = Matrix44().matrix33
m44 = Matrix33().matrix44
q = Matrix44().quaternion
q = Matrix33().quaternion

m33 = Quaternion().matrix33
m44 = Quaternion().matrix44

Convenient Operators

from pyrr import Quaternion, Matrix44, Matrix33, Vector3, Vector4
import numpy as np

# matrix multiplication
m = Matrix44() * Matrix33()
m = Matrix44() * Quaternion()
m = Matrix33() * Quaternion()

# matrix inverse
m = ~Matrix44.from_x_rotation(np.pi)

# quaternion multiplication
q = Quaternion() * Quaternion()
q = Quaternion() * Matrix44()
q = Quaternion() * Matrix33()

# quaternion inverse (conjugate)
q = ~Quaternion()

# quaternion dot product
d = Quaternion() | Quaternion()

# vector oprations
v = Vector3() + Vector3()
v = Vector4() - Vector4()

# vector transform
v = Quaternion() * Vector3()
v = Matrix44() * Vector3()
v = Matrix44() * Vector4()
v = Matrix33() * Vector3()

# dot and cross products
dot = Vector3() | Vector3()
cross = Vector3() ^ Vector3()

Installation

Pyrr is in the PyPI database and can be installed via pip:

pip install pyrr

Pyrr requires the following software:

Changelog

View the changelog.

Authors

Contributions are welcome.

License

Pyrr is released under the BSD 2-clause license (a very relaxed licence), but it is encouraged that any modifications are submitted back to the master for inclusion.

Created by Adam Griffiths.

Copyright (c) 2012, Twisted Pair Development. All rights reserved.

twistedpairdevelopment.wordpress.com @twistedpairdev

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].