Package pymunk :: Module vec2d :: Class Vec2d
[frames] | no frames]

Class Vec2d

   object --+        
            |        
    ??._CData --+    
                |    
_ctypes.Structure --+
                    |
                   Vec2d

2d vector class, supports vector and scalar operators, and also provides some high level functions
Instance Methods
 
__init__(self, x_or_pair=None, y=None)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
 
__len__(self)
 
__getitem__(self, key)
 
__setitem__(self, key, value)
 
__repr__(self)
repr(x)
 
__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_radians)
Rotate the vector by angle_radians radians.
 
rotated(self, angle_radians)
Create and return a new vector by rotating this vector by angle_radians radians.
 
rotate_degrees(self, angle_degrees)
Rotate the vector by angle_degrees degrees.
 
rotated_degrees(self, angle_degrees)
Create and return a new vector by rotating this vector by angle_degrees degrees.
 
get_angle(self)
 
get_angle_degrees(self)
 
get_angle_between(self, other)
Get the angle between the vector and the other in radians
 
get_angle_degrees_between(self, other)
Get the angle between the vector and the other in degrees
 
normalized(self)
Get a normalized copy of the vector Note: This function will return 0 if the length of the vector is 0.
 
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)
Uses complex multiplication to rotate this vector by the other.
 
cpvunrotate(self, other)
The inverse of cpvrotate
 
__getstate__(self)
 
__setstate__(self, dict)
 
__newobj__(cls, *args)

Inherited from _ctypes.Structure: __new__

Inherited from unreachable._CData: __ctypes_from_outparam__, __hash__, __reduce__

Inherited from object: __delattr__, __format__, __getattribute__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods
 
from_param(cls, arg)
Used by ctypes to automatically create Vec2ds
Static Methods
 
zero()
A vector of zero length
 
unit()
A unit vector pointing up
 
ones()
A vector where both x and y is 1
Class Variables
  _fields_ = [('x', <class 'ctypes.c_double'>), ('y', <class 'ct...
  x = <Field type=c_double, ofs=0, size=8>
  y = <Field type=c_double, ofs=8, size=8>
Properties
  length
Gets or sets the magnitude of the vector
  angle
Gets or sets the angle (in radians) of a vector
  angle_degrees
Gets or sets the angle (in degrees) of a vector

Inherited from unreachable._CData: _b_base_, _b_needsfree_

Inherited from object: __class__

Method Details

__init__(self, x_or_pair=None, y=None)
(Constructor)

 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Overrides: object.__init__
(inherited documentation)

__repr__(self)
(Representation operator)

 
repr(x)
Overrides: object.__repr__
(inherited documentation)

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

 
Get the length of the vector.
Returns:
The length

rotated(self, angle_radians)

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

rotated_degrees(self, angle_degrees)

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

get_angle_between(self, other)

 
Get the angle between the vector and the other in radians
Returns:
The angle

get_angle_degrees_between(self, other)

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

normalized(self)

 
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

normalize_return_length(self)

 
Normalize the vector and return its length before the normalization
Returns:
The length before the normalization

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(self, other)

 
The distance between the vector and other vector
Returns:
The distance

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(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

__setstate__(self, dict)

 
Overrides: unreachable._CData.__setstate__

Class Variable Details

_fields_

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

Property Details

length

Gets or sets the magnitude of the vector
Get Method:
get_length(self) - Get the length of the vector.
Set Method:
__setlength(self, value)

angle

Gets or sets the angle (in radians) of a vector
Get Method:
get_angle(self)
Set Method:
__setangle(self, angle)

angle_degrees

Gets or sets the angle (in degrees) of a vector
Get Method:
get_angle_degrees(self)
Set Method:
__set_angle_degrees(self, angle_degrees)