# `pymunk.vec2d` Module

This module contain the Vec2d class that is used in all of pymunk when a vector is needed.

The Vec2d class is used almost everywhere in pymunk for 2d coordinates and vectors, for example to define gravity vector in a space. However, pymunk is smart enough to convert tuples or tuple like objects to Vec2ds so you usually do not need to explicitly do conversions if you happen to have a tuple:

    >>> import pymunk
    >>> space = pymunk.Space()
    >>> space.gravity
    Vec2d(0.0, 0.0)
    >>> space.gravity = 3,5
    >>> space.gravity
    Vec2d(3.0, 5.0)
    >>> space.gravity += 2,6
    >>> space.gravity
    Vec2d(5.0, 11.0)

More examples:

    >>> from pymunk.vec2d import Vec2d
    >>> Vec2d(7.3, 4.2)
    Vec2d(7.3, 4.2)
    >>> Vec2d((7.3, 4.2))
    Vec2d(7.3, 4.2)
    >>> Vec2d(7.3, 4.2) + Vec2d((1,2))
    Vec2d(8.3, 6.2)

class `pymunk.vec2d.``Vec2d`(x_or_pair=None, y=None)

  Bases: `object`

  2d vector class, supports vector and scalar operators, and also provides some high level functions.

  `__init__`(x_or_pair=None, y=None)

    x.__init__(…) initializes x; see help(type(x)) for signature

  `angle`

    Gets or sets the angle (in radians) of a vector

  `angle_degrees`

    Gets or sets the angle (in degrees) of a vector

  `convert_to_basis`(x_vector, y_vector)
  `cpvrotate`(other)

    Uses complex multiplication to rotate this vector by the other.

  `cpvunrotate`(other)

    The inverse of cpvrotate

  `cross`(other)
    The cross product between the vector and other vector
      v1.cross(v2) -> v1.x*v2.y - v1.y*v2.x

    Returns: | The cross product

  `dot`(other)
    The dot product between the vector and other vector
      v1.dot(v2) -> v1.x*v2.x + v1.y*v2.y

    Returns: | The dot product

  `get_angle`()
  `get_angle_between`(other)

    Get the angle between the vector and the other in radians

    Returns: | The angle

  `get_angle_degrees`()
  `get_angle_degrees_between`(other)

    Get the angle between the vector and the other in degrees

    Returns: | The angle (in degrees)

  `get_dist_sqrd`(other)

    The squared distance between the vector and other vector It is more efficent to use this method than to call get_distance() first and then do a sqrt() on the result.

    Returns: | The squared distance

  `get_distance`(other)

    The distance between the vector and other vector

    Returns: | The distance

  `get_length`()

    Get the length of the vector.

    Returns: | The length

  `get_length_sqrd`()

    Get the squared length of the vector. It is more efficent to use this method instead of first call get_length() or access .length and then do a sqrt().

    Returns: | The squared length

  `int_tuple`

    Return the x and y values of this vector as ints

  `interpolate_to`(other, range)
  `length`

    Gets or sets the magnitude of the vector

  `normalize_return_length`()

    Normalize the vector and return its length before the normalization

    Returns: | The length before the normalization

  `normalized`()

    Get a normalized copy of the vector Note: This function will return 0 if the length of the vector is 0.

    Returns: | A normalized vector

  static `ones`()

    A vector where both x and y is 1

  `perpendicular`()
  `perpendicular_normal`()
  `projection`(other)
  `rotate`(angle_radians)

    Rotate the vector by angle_radians radians.

  `rotate_degrees`(angle_degrees)

    Rotate the vector by angle_degrees degrees.

  `rotated`(angle_radians)

    Create and return a new vector by rotating this vector by angle_radians radians.

    Returns: | Rotated vector

  `rotated_degrees`(angle_degrees)

    Create and return a new vector by rotating this vector by angle_degrees degrees.

    Returns: | Rotade vector

  static `unit`()

    A unit vector pointing up

  `x`
  `y`
  static `zero`()

    A vector of zero length