Skip to main content

vectormath: vector math utilities for Python

Project description

vectormath

Latest PyPI version MIT license Travis CI build status Code test coverage

Vector math utilities for Python built on NumPy

Why

The vectormath package provides a fast, simple library of vector math utilities by leveraging NumPy. This allows explicit geometric constructs to be created (for example, Vector3 and Plane) without redefining the underlying array math.

Scope

The vectormath package includes Vector3/Vector2 and Vector3Array/Vector2Array.

Goals

  • Speed: All low-level operations rely on NumPy arrays. These are densely packed, typed, and partially implemented in C. The VectorArray classes in particular take advantage of this speed by performing vector operations on all Vectors at once, rather than in a loop.

  • Simplicty: High-level operations are explicit and straight-forward. This library should be usable by Programmers, Mathematicians, and Geologists.

Alternatives

  • NumPy can be used for any array operations

  • Many small libraries on PyPI (e.g. vectors) implement vector math operations but are are only built with single vectors in mind.

Connections

  • properties uses vectormath as the underlying framework for Vector properties.

Installation

To install the repository, ensure that you have pip installed and run:

pip install vectormath

For the development version:

git clone https://github.com/aranzgeo/vectormath.git
cd vectormath
pip install -e .

Examples

This example gives a brief demonstration of some of the notable features of Vector3 and Vector3Array

import numpy as np
import vectormath as vmath

# Single Vectors
v = vmath.Vector3(5, 0, 0)
v.normalize()
print(v)                          # >> [1, 0, 0]
print(v.x)                        # >> 1.0

# VectorArrays are much faster than a for loop over Vectors
v_array = vmath.Vector3Array([[4, 0, 0], [0, 2, 0], [0, 0, 3]])
print(v_array.x)                  # >> [4, 0, 0]
print(v_array.length)             # >> [4, 2, 3]
print(v_array.normalize())        # >> [[1, 0, 0], [0, 1, 0], [0, 0, 1]]

# Vectors can be accessed individually or in slices
print(type(v_array[1:]))          # >> vectormath.Vector3Array
print(type(v_array[2]))           # >> vectormath.Vector3

# All these classes are just numpy arrays
print(isinstance(v, np.ndarray))  # >> True
print(type(v_array[1:, 1:]))      # >> numpy.ndarray

Current version: v0.1.2

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

vectormath-0.1.2.tar.gz (5.8 kB view details)

Uploaded Source

File details

Details for the file vectormath-0.1.2.tar.gz.

File metadata

  • Download URL: vectormath-0.1.2.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for vectormath-0.1.2.tar.gz
Algorithm Hash digest
SHA256 383a558178f0b8851ce17f487f5e0706d2b8ebea3d38c70508bb0e24ce5e790f
MD5 e35644ffc258b1526e03e9a4935d6884
BLAKE2b-256 1010d6271e24ef3f058d9628a6389d8c69e0fa38ca00a625a0f1c5e0a097487e

See more details on using hashes here.

Supported by

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