Skip to main content

vectors of n dimensions

Project description

mvec

a simple package for handling vectors of any size.

all* your favorite vector operations are here, and generalized to n-dimensional vectors. want to add three 4D vectors? dot product a 8D and 3D vector together? you can do it!

*disclaimer: i still haven't figured out how to implement the cross product in n dimensions, so right now, it only works on vectors <= 3 dimensions. sorry

examples

defining a vector is as simple as passing the constructor an n-dimensional array of scalar values!

v = Vector([a, b, c,... y, z])

you can also create Vectors in other ways:

# the vector between two points in n-dimensional space
v2 = Vector.fromTwoPoints([a, b, c,...], [a, b, c,...])

# for the special case of 3D vectors in a spherical coordinate system 
v3 = Vector.fromSpherical(r, θ, φ)

from there, you can do all sorts of fun unary and binary operations!

v3 = v1.unitVector()

# returns the sector the vector is in, given as an array made up of either 1, 0, or -1
array = v1.sector()

# x(), y(), and z() are convenience methods to return the 1st, 2nd, or 3rd-dimensional component of a vector
f = v1.x()

v2 = v1.scale(7)

boolean = v1.parallel(v2)
boolean = v1.perpendicular(v2)

# returns the angle between v1 and v2
angle = v1.angleTo(v2)

v3 = v1.dot(v2)
v3 = v1.cross(v2)

and more! you can also access various components of the vectors:

# returns the components of a vector as a list
array = v1.toArray()

# returns the angle the vector makes from the positive axis in the i dimension (x = 0, y = 1, etc)
angle = v1.alphaRad(i)

you can also use built-in operators to do math with vectors and scalars!

# v2 is a vector in the same direction as v1 but its length is 5 more
v2 = v1 + 5 
# v1 is now the difference between v1 and v2
v1 -= v2

v3 = v1 + v2

# equivalent to scaling v1 by 6 or 1/5 respectively
v2 = v1 * 6
v1 =/ 5

# compares magnitudes
v1 >= v2
v1 < v2

you can also iterate over the components of a vector:

v1 = Vector([2, 4, 6])
for i in v1:
	print(i)
# 2
# 4
# 6
# >>>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

mvec-0.0.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file mvec-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: mvec-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.5.0.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for mvec-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8366d98e7e1c9f94aeed94d0dd438db0d1d3ef954004506082f907df970df901
MD5 207f022304c8ec4f7dbdb3b826ff5ab6
BLAKE2b-256 7bbd2539da5743ba4c1a7b078132df6e2a8c02d351d4f5411db4f62bf599c43d

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