Skip to main content

CHANGES

0.0.9

from __future__ import division added to fix division operator to use true division as in Python 3.0 instead of classic division.

Vectors

Vectors is a simple library toolkit dealing with common vector and point logic in the 3-dimensional space.

Supports commonly used vector math functions including:

  • Vector magnitude

  • Addition with another vector or a real number.

  • Multiplication by another vector or a real number.

  • Dot product

  • Cross/scalar product

  • Angle between vectors

  • Check if two vectors are perpendicular, parallel or non-parallel

Github Repository

Installation

pip install vectors

Documentation

Usage

There are multiple ways to create our vector instances using the vectors module.

We can first initialize some vectors and points calling their repsective class contructors as follows.

  from vectors import Point, Vector

  v1 = Vector(1, 2, 3) #=> Vector(1, 2, 3)
v2 = Vector(2, 4, 6) #=> Vector(2, 4, 6)

p1 = Point(1, 2, 6) #=> Point(1, 2, 3)
p2 = Point(2, 0, 2) #=> Point(2, 4, 6)

We can also create a Point instance or a Vector instance with a list using the class method from_list().

components = [1.2, 2.4, 3.8]

v = Vector.from_list(components) #=> Vector(1.2, 2.4, 3.8)

We can also create our Vectors from two Point instances using the classmethod from_points().

v = Vector.from_points(p1, p2) #=> Vector(1, -2, -4)

We can also get access to the vector array to use it with other libraries.

v1.vector #=> [1, 2, 3]

Magnitude

We can get the magnitude of the vector easily.

v1.magnitude() #==> 3.7416573867739413

Addition

We can add a real number to a vector or compute the vector sum of two vectors as follows.

v1.add(2) #=> Vector(3.0, 4.0, 5.0)

v1.sum(v2) #=> Vector(3.0, 6.0, 9.0)

Both methods return a Vector instance.

Multiplication

We can multiply a vector by a real number.

v1.multiply(4) #=> Vector(4.0, 8.0, 12.0)

The above returns a Vector instance.

Dot Product

We can find the dot product of two vectors.

v1.dot(v2) #=> 0.0

We can also use angle theta on the dot function.

v1.dot(v2. 180)

Dot product returns a real number.

Cross/Scalar Product

We can find the cross product of two vectors.

v1.cross(v2) #=> Vector(0, 0, 0)

Cross product returns a Vector instance, which is always perpendicular to the other two vectors.

Angle Theta

We can also find the angle theta between two vectors.

v1.angle(v2) #=> 0.0

Angle is a measured in degrees.

Parallel, Perpendicular, Non-Parallel

We can check if two vectors are parallel, perpendicular or non-parallel to each other.

v1.parallel(v2) #=> True
v1.perpendicular(v2) #=> False
v1.non_parallel(v2) #=> False

All of the above return either True or False.

TODO

  • Create Analytic Geometry Toolkit based on the vectors toolkit.

Metadata

Release files for vectors 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for vectors 1.0.0
File Interpreter ABI Platform
vectors-1.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Release files / vectors-1.0.0-py2.py3-none-any.whl

Download URL vectors-1.0.0-py2.py3-none-any.whl
Size 5.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
468b9e346e7778acf8b420dbe66f49d29c1f2e29a343652c35a77defca3e9aef
BLAKE2b-256 checksum
How to use checksums
0d6a32b0a0edad4d76241ea59c996c2eb8d5a8fcce55b01be2b6d6495d38e78a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for vectors 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page