CLASS v1.8.0

Line

pykraken.Line

A 2D line segment defined by two points. You can access or modify points using .a, .b, or directly via .ax, .ay, .bx, .by.

Reference

PYTHON API

Constructor

method5 overloads
Line()
Line(ax: float, ay: float, bx: float, by: float)
Line(ax: float, ay: float, b: Vec2)
Line(a: Vec2, bx: float, by: float)
Line(a: Vec2, b: Vec2)

Overloaded function.

  1. Line()

Create a default line with all values set to 0.

  1. Line(ax: float, ay: float, bx: float, by: float)

Create a line from two coordinate points.

Args

  • ax (float) — X-coordinate of point A.
  • ay (float) — Y-coordinate of point A.
  • bx (float) — X-coordinate of point B.
  • by (float) — Y-coordinate of point B.
  1. Line(ax: float, ay: float, b: Vec2)

Create a line from A coordinates and a Vec2 B point.

Args

  • ax (float) — X-coordinate of point A.
  • ay (float) — Y-coordinate of point A.
  • b (Vec2) — Point B.
  1. Line(a: Vec2, bx: float, by: float)

Create a line from a Vec2 A point and B coordinates.

Args

  • a (Vec2) — Point A.
  • bx (float) — X-coordinate of point B.
  • by (float) — Y-coordinate of point B.
  1. Line(a: Vec2, b: Vec2)

Create a line from two Vec2 points.

Args

  • a (Vec2) — Point A.
  • b (Vec2) — Point B.

a

property
a: Vec2

Get or set point A as a tuple or Vec2.

ax

property
ax: float

X-coordinate of point A.

ay

property
ay: float

Y-coordinate of point A.

b

property
b: Vec2

Get or set point B as a tuple or Vec2.

bx

property
bx: float

X-coordinate of point B.

by

property
by: float

Y-coordinate of point B.

length

property
length: float

The Euclidean length of the line segment.

copy

method
copy(self) -> Line

Return a copy of this line.

get_angle

method
get_angle(self) -> float

Get the angle of the line in radians.

Returns

  • float — The angle in radians.
get_closest_point(self, point: Vec2) -> Vec2

Get the closest point on the line to a given point.

Args

  • point (Vec2) — The point to find the closest point to.

Returns

  • Vec2 — The closest point on the line as a Vec2.
get_midpoint(self) -> Vec2

Get the midpoint of the line segment.

Returns

  • Vec2 — The midpoint as a Vec2.
get_perpendicular(self) -> Line

Get a perpendicular bisector line from this line.

Returns

  • Line — A new perpendicular line.

move

method
move(self, offset: Vec2) -> None

Move this line by a Vec2 offset.

Args

  • offset (Vec2) — The amount to move.

moved

method
moved(self, offset: Vec2) -> Line

Return a new line moved by a Vec2 offset.

Args

  • offset (Vec2) — The amount to move.

Find your next step

Start typing to search the manual.