Giter Club home page Giter Club logo

vectormath's Introduction

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/seequent/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.2.2

vectormath's People

Contributors

fwkoch avatar rowanc1 avatar evelyn-h avatar jjcoding01 avatar redhotsmasher avatar lheagy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.