Kraken Logo

Kraken Engine

DocumentationGuidesShowcaseCommunity
Ctrl
K
Navigating the Docs
Building Docs
Overview
Anchor
AnimationController
Audio
Batcher
Body
Camera
Capsule
CastHit
CharacterBody
Circle
Collision
Color
DistanceJoint
Effect
Event
FilterJoint
Flip (Texture)
Font
ImageLayer
InputAction
Joint
Layer
Line
Map
MapObject
Mask
MotorJoint
MouseJoint
ObjectGroup
Orchestrator
PixelArray
PolarCoordinate
Polygon
PrismaticJoint
Rect
RevoluteJoint
RigidBody
Sample
Sampler
Shader
SheetStrip
StaticBody
Stream
Style
Terrain (TileSet)
Text
TextProperties
Texture
Tile (TileLayer)
Tile (TileSet)
TileLayer
TileResult (TileLayer)
TileSet
Timer
Transform
Tween
Vec2
Vertex
WeldJoint
WheelJoint
World

Built bydurkisneer1.Kraken Engine is open source and available onGitHub.

  1. Docs
  2. Classes
  3. Vec2

Vec2

A 2D vector representing Cartesian coordinates.

Constructor

  • Vec2() → Vec2Vec2() → Vec2
  • Vec2(value: float) → Vec2Vec2(value: float) → Vec2
  • Vec2(x: float, y: float) → Vec2Vec2(x: float, y: float) → Vec2

A 2D vector representing Cartesian coordinates.

Properties


NameDescriptionType
DOWNVec2(0.0, 1.0)Vec2
LEFTVec2(-1.0, 0.0)Vec2
RIGHTVec2(1.0, 0.0)Vec2
UPVec2(0.0, -1.0)Vec2
ZEROVec2(0.0, 0.0)Vec2
angleReturn the vector angle in radians.float
lengthReturn the magnitude of this Vec2.float
length_squaredReturn the squared magnitude of this Vec2.float
xThe x component of the vector.float
xxReturn a Vec2 with both components set to x.Vec2
xyAccess or assign the (x, y) components as a Vec2.Vec2
yThe y component of the vector.float
yxAccess or assign the (y, x) components as a Vec2.Vec2
yyReturn a Vec2 with both components set to y.Vec2

Methods


As Ints

as_ints() → tuple[int, int]as_ints() → tuple[int, int]

Return the vector components truncated to integers as a tuple.

Returns

tuple[int, int] : The (x, y) components as integers.

Ceil

ceil() → Noneceil() → None

Ceil both components of this Vec2 in-place.

Ceiled

ceiled() → Vec2ceiled() → Vec2

Return a new Vec2 with both components ceiled to the nearest integer.

Returns

Vec2 : A new vector with ceiled components.

Copy

copy() → Vec2copy() → Vec2

Return a copy of this Vec2.

Returns

Vec2 : A duplicated vector with the same components.

Distance Squared To

distance_squared_to(other: Vec2) → floatdistance_squared_to(other: Vec2) → float

Compute the squared distance to another Vec2.

Args

  • other : Comparison vector.

Returns

float : Squared distance between the vectors.

Distance To

distance_to(other: Vec2) → floatdistance_to(other: Vec2) → float

Compute the Euclidean distance to another Vec2.

Args

  • other : Comparison vector.

Returns

float : Distance between the vectors.

Floor

floor() → Nonefloor() → None

Floor both components of this Vec2 in-place.

Floored

floored() → Vec2floored() → Vec2

Return a new Vec2 with both components floored to the nearest integer.

Returns

Vec2 : A new vector with floored components.

Is Zero

is_zero(tolerance: float = 1e-08) → boolis_zero(tolerance: float = 1e-08) → bool

Determine whether this Vec2 is effectively zero.

Args

  • tolerance : Largest allowed absolute component magnitude.

Returns

bool : True if both components are within the tolerance.

Move Toward

move_toward(target: Vec2, delta: float) → Nonemove_toward(target: Vec2, delta: float) → None

Move this Vec2 toward a target Vec2 by a specified delta.

Args

  • target : The target vector to move towards.
  • delta : The maximum distance to move.

Moved Toward

moved_toward(target: Vec2, delta: float) → Vec2moved_toward(target: Vec2, delta: float) → Vec2

Return a new Vec2 moved toward a target Vec2 by a specified delta.

Args

  • target : The target vector to move towards.
  • delta : The maximum distance to move.

Returns

Vec2 : A new vector moved toward the target.

Normalize

normalize() → Nonenormalize() → None

Normalize this Vec2 in place.

Normalized

normalized() → Vec2normalized() → Vec2

Return a new normalized Vec2.

Returns

Vec2 : A new vector with unit length.

Project

project(other: Vec2) → Vec2project(other: Vec2) → Vec2

Project this Vec2 onto another Vec2.

Args

  • other : The vector to project onto.

Returns

Vec2 : Projection of this vector onto the other vector.

Reflect

reflect(other: Vec2) → Vec2reflect(other: Vec2) → Vec2

Reflect this Vec2 across another Vec2.

Args

  • other : The vector used as the reflection normal.

Returns

Vec2 : Reflected vector.

Reject

reject(other: Vec2) → Vec2reject(other: Vec2) → Vec2

Compute the rejection of this Vec2 from another Vec2.

Args

  • other : The vector defining the projection axis.

Returns

Vec2 : Component of this vector orthogonal to the other vector.

Rotate

rotate(radians: float) → Nonerotate(radians: float) → None

Rotate this Vec2 in place.

Args

  • radians : Rotation angle in radians.

Rotated

rotated(radians: float) → Vec2rotated(radians: float) → Vec2

Return a new Vec2 rotated by a specified angle.

Args

  • radians : Rotation angle in radians.

Returns

Vec2 : A new vector rotated by the given angle.

Round

round() → Noneround() → None

Round both components of this Vec2 in-place.

Rounded

rounded() → Vec2rounded() → Vec2

Return a new Vec2 with both components rounded to the nearest integer.

Returns

Vec2 : A new vector with rounded components.

Scale To Length

scale_to_length(length: float) → Nonescale_to_length(length: float) → None

Scale this Vec2 to a specific magnitude.

Args

  • length : Target vector length.

Scaled To Length

scaled_to_length(length: float) → Vec2scaled_to_length(length: float) → Vec2

Return a new Vec2 scaled to a specific magnitude.

Args

  • length : Target vector length.

Returns

Vec2 : A new vector scaled to the specified length.

Slid

slid(normal: Vec2) → Vec2slid(normal: Vec2) → Vec2

Return a new Vec2 slid along a surface defined by a normal vector.

Args

  • normal : The normal vector defining the surface.

Returns

Vec2 : A new vector slid along the surface.

Slide

slide(normal: Vec2) → Noneslide(normal: Vec2) → None

Slide this Vec2 along a surface defined by a normal vector.

Args

  • normal : The normal vector defining the surface.

Returns

Vec2 : A new vector slid along the surface.

To Polar

to_polar() → PolarCoordinateto_polar() → PolarCoordinate

Convert this Vec2 to polar coordinates.

Returns

PolarCoordinate : Polar representation with angle and length.

PreviousTween
NextVertex

On this page

ConstructorPropertiesMethodsAs IntsCeilCeiledCopyDistance Squared ToDistance ToFloorFlooredIs ZeroMove TowardMoved TowardNormalizeNormalizedProjectReflectRejectRotateRotatedRoundRoundedScale To LengthScaled To LengthSlidSlideTo Polar