Positions > Vektor#
- class miniworlds.positions.vector.Vector(x, y)[Quellcode]#
Represents a 2D vector for use in movement, geometry, and physics.
Supports arithmetic with both other Vectors and 2D tuples.
Beispiele
>>> v = Vector(1, 2) >>> v2 = Vector(3, 4) >>> v + v2 Vector(4.0, 6.0) >>> v + (1, 1) Vector(2.0, 3.0) >>> (1, 1) + v Vector(2.0, 3.0)
Öffentliche Methoden:
__init__(x, y)__getitem__(index)from_position(position)from_positions(p1, p2)from_direction(direction)Creates a vector from miniworlds direction.
from_actors(t1, t2)Create a vector from two actors.
from_actor_and_position(t1, pos)Create a vector from actor and position
from_actor_direction(actor)Creates a vector from actor direction
rotate(theta)length()limit(max_length)multiply(other)add_to_position(position)dot(other)distance_to(other)Calculates Euclidean distance to another vector or position.
angle_to(other)Computes the angle between this vector and another in degrees.
__add__(other)__radd__(other)__sub__(other)__rsub__(other)__mul__(other)__rmul__(other)__neg__()__eq__(other)Return self==value.
__str__()Gib str(self) zurück.
__repr__()Return repr(self).
Private Methods:
_to_vector(value)
- add_to_position(position)[Quellcode]#
- angle_to(other)[Quellcode]#
Computes the angle between this vector and another in degrees.
- Rückgabetyp:
- Parameter:
other – A Vector or tuple.
- Rückgabe:
Angle in degrees between 0 and 180.
Beispiele
>>> Vector(1, 0).angle_to((0, 1)) 90.0
- distance_to(other)[Quellcode]#
Calculates Euclidean distance to another vector or position.
- Rückgabetyp:
- Parameter:
other – A Vector or tuple.
- Rückgabe:
The distance as float.
Beispiele
>>> Vector(0, 0).distance_to((3, 4)) 5.0
- dot(other)[Quellcode]#
- Rückgabetyp:
- classmethod from_actor_and_position(t1, pos)[Quellcode]#
Create a vector from actor and position
Der Vektor wird erzeugt aus: actor2.center - position
- Rückgabetyp:
Vector
- classmethod from_actor_direction(actor)[Quellcode]#
Creates a vector from actor direction
Examples: :rtype: Vector
Erstellt ein rotierendes Rechteck
from miniworlds import * world = World() player = Rectangle((200,200),40, 40) player.speed = 1 player.direction = 80 @player.register def act(self): v1 = Vector.from_actor_direction(self) v1.rotate(-1) self.direction = v1 world.run()
- classmethod from_actors(t1, t2)[Quellcode]#
Create a vector from two actors.
Der Vektor wird erzeugt aus: actor2.center - actor1.center
- Rückgabetyp:
Vector
- classmethod from_direction(direction)[Quellcode]#
Creates a vector from miniworlds direction.
- Rückgabetyp:
- classmethod from_position(position)[Quellcode]#
- Rückgabetyp:
- classmethod from_positions(p1, p2)[Quellcode]#
- Rückgabetyp:
- get_normal()[Quellcode]#
- Rückgabetyp:
- length()[Quellcode]#
- Rückgabetyp:
- limit(max_length)[Quellcode]#
- Rückgabetyp:
- multiply(other)[Quellcode]#
- normalize()[Quellcode]#
- Rückgabetyp:
- rotate(theta)[Quellcode]#
- Rückgabetyp:
- to_direction()[Quellcode]#
- Rückgabetyp:
- to_position()[Quellcode]#