Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
Hamolicious edited this page Jul 5, 2021 · 3 revisions

A 2 dimensional vector data structure. I highly recommend reading the instantiation page before anything else to get an understanding of what *args will take

Properties

Property Description
x the 0th element of the vector
y the 1st element of the vector
w same as x
h same as y
length calculates and returns the magnitude of the vector

Methods

Method Description
__init__(*args) Have a look at the instantiation page
random_unit() Static method, returns a vector where x and y are between -1 and 1
random_pos() Static method, returns a vector where x and y are between 0 and 1
from_angle(angle) Static method, creates a vector pointing to the passed in angle (in radians)
zero() Static method, returns a zero vector, same as instantiating an empty vector Vec2d()
get() returns all elements as a list in float form
get_int() returns all elements as a list in integer form
set(*args) same as __init__(*args)
copy() returns a copy of the vector
clear() sets all elements to 0
dist_sqrt(*args) returns the distance to the passed in vector (uses sqrt)
rotate(a) rotate the vector in place around the origin by a radians
dist(*args) returns the distance squared to the passed in vector (does not use sqrt so will be much faster)
get_heading_angle() returns the heading angle (in radians)
get_magnitude() same as length
normalise() normalises the vector in place
clamp(*args) clamps each element to the passed in value
add(*args) adds each element with the passed in elements
sub(*args) subtracts each element with the passed in elements
mult(*args) multiplies each element with the passed in elements
div(*args) divides each element with the passed in elements
linear_interpolate(*args, t=0.5) linearly interpolates the vector to the passed in values
dot_product(*args) returns the dot product to the passed in values
Clone this wiki locally