Skip to main content

A vector-geometry toolbelt for dealing with 3D points and vectors

Project description

vg

version python version license build code style

A very good vector-geometry toolbelt for dealing with 3D points and vectors. These are simple NumPy operations made readable, built to scale from prototyping to production.

:book: See the complete documentation: https://vgpy.dev/

Examples

Normalize a stack of vectors:

# 😮
vs_norm = vs / np.linalg.norm(vs, axis=1)[:, np.newaxis]

# 😀
vs_norm = vg.normalize(vs)

Check for the zero vector:

# 😣
is_almost_zero = np.allclose(v, np.array([0.0, 0.0, 0.0]), rtol=0, atol=1e-05)

# 🤓
is_almost_zero = vg.almost_zero(v, atol=1e-05)

Find the major axis of variation (first principal component):

# 😩
mean = np.mean(coords, axis=0)
_, _, pcs = np.linalg.svd(coords - mean)
first_pc = pcs[0]

# 😍
first_pc = vg.major_axis(coords)

Compute pairwise angles between two stacks of vectors:

# 😭
dot_products = np.einsum("ij,ij->i", v1s.reshape(-1, 3), v2s.reshape(-1, 3))
cosines = dot_products / np.linalg.norm(v1s, axis=1) / np.linalg.norm(v1s, axis=1)
angles = np.arccos(np.clip(cosines, -1.0, 1.0))

# 🤯
angles = vg.angle(v1s, v2s)

Installation

pip install numpy vg

Usage

import numpy as np
import vg

projected = vg.scalar_projection(
  np.array([5.0, -3.0, 1.0]),
  onto=vg.basis.neg_y
)

Development

First, install Poetry.

After cloning the repo, run ./bootstrap.zsh to initialize a virtual environment with the project's dependencies.

Subsequently, run ./dev.py install to update the dependencies.

Acknowledgements

This collection was developed at Body Labs by Paul Melnikow and extracted from the Body Labs codebase and open-sourced as part of blmath by Alex Weiss. blmath was subsequently forked by Paul Melnikow and later the vx namespace was broken out into its own package. The project was renamed to vg to resolve a name conflict.

License

The project is licensed under the two-clause BSD license.

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

vg-1.11.0.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

vg-1.11.0-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

Details for the file vg-1.11.0.tar.gz.

File metadata

  • Download URL: vg-1.11.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.10

File hashes

Hashes for vg-1.11.0.tar.gz
Algorithm Hash digest
SHA256 4d61d889404acecd54ad468f95b386f60fe6450e0dfa7c9c275cfd0380902d79
MD5 0db6b63686bd19d5d462a8227d17a603
BLAKE2b-256 d23cdb167f5502d10a0d8c3dc3c40d3c0adb9463c263818e086ad8aa2ba18da0

See more details on using hashes here.

Provenance

File details

Details for the file vg-1.11.0-py3-none-any.whl.

File metadata

  • Download URL: vg-1.11.0-py3-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.10

File hashes

Hashes for vg-1.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1346ee0d2ea158158ea312f258887a919c0adc27eb42e152df6d388e30da04fb
MD5 bddcd808247399b1041bf7790004aa4e
BLAKE2b-256 5d0302550cf1931246ecf693eebf2db8d50e14f9ea8d7372635bf472fb175410

See more details on using hashes here.

Provenance

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