Skip to main content

provides 3D position Vectors as Python objects

Project description

pyvectors

This is a simple Mathematical Module which is extremely user-friendly. The module deals with 3-dimensional real position Vectors centered at the Origin (0, 0, 0). Using this module, the algebra of Vectors can be easily performed in python.
Vector(x, y, z) -> xi + yj + zk
A lot of help text is included in the class, and in the error messages, hence making the module easy to use.

Attributes of class Vector

Four Vector instances have been already defined in the module. These are:

  • Vector.i -> 1i + 0j + 0k
  • Vector.j -> 0i + 1j + 0k
  • Vector.k -> 0i + 0j + 1k
  • Vector.null -> 0i + 0j + 0k

These Vectors cannot be created through the Vector() constructor. Functions evaluating to these Vectors will return the predefined objects only. If these Vectors are changed by the user, the class may misbehave. Hence, user is advised to treat these objects as "read-only".

Attributes of Vector objects

Vectors have attributes like x, y, z, magnitude, tuple, ...
Attributes of Vectors are read-only. Manually editing any of them results in unexpected behavior, which renders the object useless and prone to errors.

Methods

  • add two Vectors:

    returns resultant of the two Vectors
    can be achieved through v1 + v2

  • subtract two Vectors:

    returns the difference of the Vectors
    can be achieved through v1 - v2

  • Vector.dot(v1, v2)

    returns dot product of the two Vectors

  • Vector.cross(v1, v2)

    returns cross product of the two Vectors

  • Vector.scale(v, k)

    returns the Vector obtained by scaling the components of v by k
    can also be achieved through v * k

  • Vector.angle(v1, v2)

    returns the angle between the two Vectors

  • Vector.scalar_triple(v1, v2, v3)

    returns the scalar triple product of the Vectors taken in order

  • Vector.vector_triple(v1, v2, v3)

    returns the vector triple product of the Vectors taken in order

  • Vector.unit(v)

    returns the Unit Vector along the direction of v

  • Vector.mod(v)

    returns the magnitude or absolute value of the Vector v
    can also be achieved through abs(v) And many more... Each function contains help text that can be accessed through help() in python to know more about it. Users are advised to read help() on methods they want to use to ensure required results.

Plotting a Vector

Two methods allow you to plot the Vector on a 3-dimensional mathematical plot:

  • Vector.plot(v) -> plots single Vector
  • Vector.plot_vectors(v1, v2, v3, ..., vn) -> plots multiple Vectors on the same grid

Updates (0.2.2)

Minor bug fixes:

  • Fixed all math domain errors
  • Fixed issues with plotting multiple Vectors

Updates (0.2.3)

Added methods which allow you to rotate Vectors using the Right-Hand Rule and Matrix Rotation:

  • Vector.rotate(v, yaw=x, pitch=y, roll=z)

    rotates the Vector by the given yaw, pitch and roll angles
    formally, this corresponds to an intrinsic rotation whose Tait-Bryan angles are x, y and z about the axes Z, Y and X respectively

  • Vector.rotate_vector(v1, v2, phi=value)

    rotates Vector v1 phi degrees about Vector v2
    when phi > 0, the rotation will be counter-clockwise when v2 points towards the observer

  • Vector.rotate_axis(v, axis="A", phi=value)

    rotates the Vector phi degrees about the positive direction of the given axis
    when phi > 0, the rotation will be counter-clockwise when the positive direction of axis of rotation points towards the observer

Updates (0.2.4)

You can now compare Vectors using in-build operators < and >. These operators are used to compare the magnitude / absolute value of two Vector objects. For example:

  • v1 > v2 returns True if Vector.mod(v1) > Vector.mod(v2) and False in all other cases
  • v1 < v2 returns True if Vector.mod(v1) < Vector.mod(v2) and False in all other cases Note that relational operators <= and >= will still not be defined for Vector Objects as they lead to ambiguity. (Whether to compare magnitudes or compare for actual equality)

Reach out to me

Feel free to reach out to me if you notice any bugs or if you need any kind of help from me in understanding the usage of the module or the source code. My email: knightt1821@gmail.com

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

pyvectors-0.2.4.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

pyvectors-0.2.4-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file pyvectors-0.2.4.tar.gz.

File metadata

  • Download URL: pyvectors-0.2.4.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0

File hashes

Hashes for pyvectors-0.2.4.tar.gz
Algorithm Hash digest
SHA256 a86359b6f4f78c466aaf334f77904a77e7b31d84334f76dae9f21d5962bb2415
MD5 9f45ac496e85677582a4ed7333f7ca91
BLAKE2b-256 30995afd9051c120952ba0749b23a5fefade9607025c6689e48a7e29ae4196ee

See more details on using hashes here.

File details

Details for the file pyvectors-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: pyvectors-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0

File hashes

Hashes for pyvectors-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a10b664591564c2610f5ddb07eeb79223167d2cc2fb85ce44edcf290ece24839
MD5 a61ed0d2fe5f4090f6a9182ca3b235ce
BLAKE2b-256 680e9784ddca75ad8b793edd6798ba374883154f4743db1f8ea3ed288eb843c8

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