Skip to main content

implement 2D vectors

Project description

#vector2.py

Module to handle vectors in a 2D space.

vector2.Vector :

Represent a 2D vector. It can be interpreted as a tuple of length 2 like (x, y).

You can declare a vector by passing :

Vector() -> null vector

Vector( (x, y) ) -> vector of coordinates (x, y)

Vector( angle, length ) -> vector of length length pointing towards angle in radians

Vector( angle=a, len=l ) -> same as Vector(a, l)

Vector( coords=t ) -> same as Vector(t)

Vector( x=x, y=y ) -> same as Vector((x, y))

Positional arguments, if they’re given correctly, will override keyword arguments.

The x and y will override coords, wich will override angle and len.

You can add/substact two vectors together, or multiply/divide them by a scalar.

vector.length() -> return the distance from the origin to the extremity of the vector.

You can compare a vector to another or to a number (the length of the vector(s) will be used).

vector.xint() -> return the integer part of the x-coordinate.

vector.yint() -> same, but with the y-coordinate.

vector.as_tuple() -> convert to a tuple.

vector.as_int_tuple() -> shortcut for (vector.xint(), vector.yint()).

vector.is_equal_to(other) -> with the == or the != operators, two vectors will be compared by their length. use is_equal_to to test if they’re exactly the same.

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

kvector2-1.4.1.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

kvector2-1.4.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file kvector2-1.4.1.tar.gz.

File metadata

  • Download URL: kvector2-1.4.1.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.1

File hashes

Hashes for kvector2-1.4.1.tar.gz
Algorithm Hash digest
SHA256 81aff32e2fb74a804c7d3cff77d3abff8cb3733080c5f79c50f76c5001958655
MD5 be38caee37f11ef073773dd6b88df7c1
BLAKE2b-256 d1eed84768a2cfff23a31c2d23e324aedc376df0d89be3bbf370e07e3a65200d

See more details on using hashes here.

File details

Details for the file kvector2-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: kvector2-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.1

File hashes

Hashes for kvector2-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a856d2bbe386c53cf0707db0bf537e9ff7bfe7437060f3e0b9c9e9bf62711f28
MD5 c6b9d7ab1ed446991437020710e22ce7
BLAKE2b-256 13bc20928654eaa0c5e80b0979477ede23e0769684991946501daa5e36d6dcec

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