Class pymunk.vec2d.Vec2d

    ??._CData --+    
                |    
_ctypes.Structure --+
                    |
                   Vec2d
2d vector class, supports vector and scalar operators, and also provides a bunch of high level functions

Methods

  from_param(cls, arg)
Used by ctypes to automatically create Vec2ds
  __init__(self, x_or_pair, y=None)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
  __len__(self)
  __getitem__(self, key)
  __setitem__(self, key, value)
  __repr__(self)
  __eq__(self, other)
  __ne__(self, other)
  __nonzero__(self)
  __add__(self, other)
  __radd__(self, other)
  __iadd__(self, other)
  __sub__(self, other)
  __rsub__(self, other)
  __isub__(self, other)
  __mul__(self, other)
  __rmul__(self, other)
  __imul__(self, other)
  __div__(self, other)
  __rdiv__(self, other)
  __idiv__(self, other)
  __floordiv__(self, other)
  __rfloordiv__(self, other)
  __ifloordiv__(self, other)
  __truediv__(self, other)
  __rtruediv__(self, other)
  __itruediv__(self, other)
  __mod__(self, other)
  __rmod__(self, other)
  __divmod__(self, other)
  __rdivmod__(self, other)
  __pow__(self, other)
  __rpow__(self, other)
  __lshift__(self, other)
  __rlshift__(self, other)
  __rshift__(self, other)
  __rrshift__(self, other)
  __and__(self, other)
  __rand__(self, other)
  __or__(self, other)
  __ror__(self, other)
  __xor__(self, other)
  __rxor__(self, other)
  __neg__(self)
  __pos__(self)
  __abs__(self)
  __invert__(self)
  get_length_sqrd(self)
Get the squared length of the vector.
  get_length(self)
Get the length of the vector.
  rotate(self, angle_degrees)
Rotate the vector by angle_degrees degrees.
  rotated(self, angle_degrees)
Create and return a new vector by rotating this vector by angle_degrees degrees.
  get_angle(self)
  get_angle_between(self, other)
Get the angle between the vector and the other in degrees
  normalized(self)
Get a normalized copy of the vector
  normalize_return_length(self)
Normalize the vector and return its length before the normalization
  perpendicular(self)
  perpendicular_normal(self)
  dot(self, other)
v1.dot(v2) -> v1.x*v2.x + v1.y*v2.y
  get_distance(self, other)
The distance between the vector and other vector
  get_dist_sqrd(self, 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.
  projection(self, other)
  cross(self, other)
v1.cross(v2) -> v1.x*v2.y - v2.y-v1.x
  interpolate_to(self, other, range)
  convert_to_basis(self, x_vector, y_vector)
  cpvrotate(self, other)
  cpvunrotate(self, other)
  __getstate__(self)
  __setstate__(self, dict)
  __newobj__(cls, *args)
Inherited from _ctypes.Structure: __new__ Inherited from unreachable._CData: __ctypes_from_outparam__, __hash__

Properties

  length
Gets or sets the magnitude of the vector
  angle
Gets or sets the angle of a vector
Inherited from unreachable._CData: _b_base_, _b_needsfree_

Class Variables

  _fields_ = [('x', <class 'ctypes.c_float'>), ('y', <class 'cty...
  x = <Field type=c_float, ofs=0, size=4>
  y = <Field type=c_float, ofs=4, size=4>

Method Details

__init__

(Constructor) __init__(self, x_or_pair, y=None)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Overrides:
_ctypes.Structure.__init__

get_length_sqrd

get_length_sqrd(self)
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

get_length

get_length(self)
Get the length of the vector.
Returns:
The length

rotated

rotated(self, angle_degrees)
Create and return a new vector by rotating this vector by angle_degrees degrees.
Returns:
Rotade vector

get_angle_between

get_angle_between(self, other)
Get the angle between the vector and the other in degrees
Returns:
The angle

normalized

normalized(self)
Get a normalized copy of the vector
Returns:
A normalized vector

normalize_return_length

normalize_return_length(self)
Normalize the vector and return its length before the normalization
Returns:
The length before the normalization

dot

dot(self, 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_distance

get_distance(self, other)
The distance between the vector and other vector
Returns:
The distance

get_dist_sqrd

get_dist_sqrd(self, 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

cross

cross(self, other)
The cross product between the vector and other vector
v1.cross(v2) -> v1.x*v2.y - v2.y-v1.x
Returns:
The cross product

Property Details

length

Gets or sets the magnitude of the vector

angle

Gets or sets the angle of a vector

Class Variable Details

_fields_

Value:
[('x', <class 'ctypes.c_float'>), ('y', <class 'ctypes.c_float'>)]