Skip to main content

2D vector classes

Project description

ROX Vectors

A lightweight and simple 2D vector class for Python, providing essential vector operations, geometric transformations, and utility functions. Perfect for mathematical simulations and robotics.

Features

  • Basic Vector Operations: Addition, subtraction, multiplication, division, negation.
  • Geometric Properties: Vector length, angle, normalization, and perpendicular vectors.
  • Transformation Utilities: Translation and rotation.
  • Dot and Cross Product calculations.
  • Line Segment manipulation and properties.

Installation

pip install rox-vectors

Usage Examples

Creating Vectors

from rox_vectors import Vector

v1 = Vector(3, 4)
v2 = Vector(1, 2)
print(v1)  # (3.000, 4.000)
print(v2)  # (1.000, 2.000)

Basic Operations

v3 = v1 + v2  # (4.000, 6.000)
v4 = v1 - v2  # (2.000, 2.000)
v5 = v1 * 2   # (6.000, 8.000)
v6 = v1 / 2   # (1.500, 2.000)
v7 = -v1      # (-3.000, -4.000)

Geometric Properties

length = v1.r        # 5.0
angle = v1.phi       # 0.927 (in radians)
v8 = v1.u            # (0.600, 0.800)
v9 = v1.v            # (-0.800, 0.600)

Dot and Cross Products

dot_product = v1.dot(v2)       # 11.0
cross_product = v1.cross(v2)   # 2.0

Vector Transformation

v10 = v1.translate(2, 3)       # (5.000, 7.000)
v11 = v1.rotate(math.radians(90))  # (-4.000, 3.000)

Line Segment

from rox_vectors import Line

line = Line(Vector(0, 0), Vector(1, 1))
line.shift_y(1)
print(line)  # <Line(start=(0.000,1.000), end=(1.000,2.000))>
line_angle = line.phi  # 0.785 (in radians)

Distance and Projection Utilities

from rox_vectors import point_on_line, distance_to_line, distance_to_b

a = Vector(0, 0)
b = Vector(4, 4)
x = Vector(2, 3)

projection = point_on_line(a, b, x)  # (2.500, 2.500)
distance = distance_to_line(a, b, x) # 0.707
distance_b = distance_to_b(a, b, x)  # -0.707

Development

  1. Init host system with init_host.sh. This will build a dev image.

  2. Launch in VSCode devcontainer.

  3. develop and test in devcontainer (VSCode)

  4. trigger ci builds by bumping version with a tag. (see .gitlab-ci.yml)

Tooling

  • Automation: invoke - run invoke -l to list available commands. (uses tasks.py)
  • Verisoning : bump2version
  • Linting and formatting : ruff
  • Typechecking: mypy

What goes where

  • src/rox_vectors app code. pip install . .
  • tasks.py automation tasks.
  • .gitlab-ci.yml takes care of the building steps.

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

rox_vectors-0.2.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

rox_vectors-0.2.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file rox_vectors-0.2.1.tar.gz.

File metadata

  • Download URL: rox_vectors-0.2.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for rox_vectors-0.2.1.tar.gz
Algorithm Hash digest
SHA256 fb50748ef8679dea43f24c002f6d8823249a42354554ccd2d1c71f99f7fceb91
MD5 139eabbfd45d949ba939f161e2f12b93
BLAKE2b-256 c6efc51b8621664d794e7e190e2993ae8d0d4d7b07b3e2f5a0e5d880cd15b72c

See more details on using hashes here.

File details

Details for the file rox_vectors-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: rox_vectors-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for rox_vectors-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0d30b6cf181b40195818395c713c04c3decedac286f4f0a5bf6e1bf912aa270c
MD5 6287d5dba732a1f901faaff0e8346a49
BLAKE2b-256 f3452d11d180ffedc319978b21bb7db81ce32c181537c136460be9d7d38477a3

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