Skip to main content

Fast 2D and 3D vector geometry module

Project description

Description

npeuclid is a library that provides vector and matrix classes for 2D and 3D graphics applications.

npeuclid is a port of the https://github.com/ezag/pyeuclid library to numpy. Instead of doing matrix multiplications in native python as euclid is doing, npeuclid is delegating all calculations to numpy.

Differences to pyeuclid

  • The base type of all pyeuclid types are numpy ndarrays.
  • 2D and 3D geometry is supported. Currenly there is no quaternion support.
  • All operaters return their transformed values, i.e. there are no inline operators. E.g. t.scale(sx,sy) will return a scaled version of t, and won't modify t.
  • There is no vector point and vector support like in euclid. There is only one type Vec2, which behaves like a point under transformation. To get a vector transformation do t.linear()*p (like in Eigen).

Types

Here are the types defined by npeuclid:

2D

  • Vec2 - Holds a 2D vector (or point).
  • Vec2Array - Holds a list of points. All operations that can be done on a signal should be available on a Vec2Array as well. In particular, an Affine2 operation may be applied on a Vec2Array which will transform all the points.
  • Affine2 - An 2D affine transformation.

3D

  • Vec3 - Holds a 3D vector (or point).
  • Vec3Array - Holds a list of points. All operations that can be done on a signal should be available on a Vec3Array as well. In particular, an Affine3 operation may be applied on a Vec3Array which will transform all the points.
  • Affine3 - An 3D affine transformation.

Usage

2D

p = Vec2(2,3)
q = Vec2(5,6)
angle = math.radians(33)
t = Affine2.new_translate(p.x,p.y).rotate(angle).translate(-p.x,-p.y)
print(t*q)
t = Affine2.new_rotate_around(angle, p.x, p.y)
print(t*q)
t = Affine2.rotate_around(angle, p.x, p.y)
print(t*q)
t = Affine2.new_translate(p.x,p.y)
print(t*p, t.linear()*p) 

# Use of Vec2Array is using numpy and is *much* faster than looping.
pp = Vec2Array([[5,6],[7,8],[3,4]])
print (t*pp)[0]

3D

p = Vec2(2,3,4)
q = Vec2(5,6,7)
angle = math.radians(33)
t = Affine2.new_translate(p.x,p.y).rotatex(angle).translate(-p.x,-p.y)
print(t*q)

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

npeuclid-0.1.2.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

npeuclid-0.1.2-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: npeuclid-0.1.2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.3

File hashes

Hashes for npeuclid-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3075335aa3615cf87b6492de2a17a7d85440064127af2996a242d43d478d42bb
MD5 fc49e71dfca90a5883f6993897280dff
BLAKE2b-256 96efb587e115c2ad7dd121b9f82bcff450fdb61de2b30eca6367f2e3d7c06c7b

See more details on using hashes here.

File details

Details for the file npeuclid-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: npeuclid-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.3

File hashes

Hashes for npeuclid-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 290ca2e9f40a8448075ffab6f3abfdc2e41ba61a4dffbcfeab22b738945046e7
MD5 b03ac6ac70b133a9fa01f0dbece7469b
BLAKE2b-256 e46c9fdf4ded7dec605d5d53d36cd0c8177087a98b588c2aa3a89a87baf66c3c

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