Skip to content

point

twod.point

a two-dimensional point for humans™.

Classes

Point(x: float = 0.0, y: float = 0.0) dataclass

Attributes
y: float = 0.0 class-attribute instance-attribute

A two dimensional geometric point.

The Point class represents a geometric point with 'x' and 'y' attributes and has many helpful properties and methods.

p = Point() p.is_origin True

is_origin: bool property

True if and only if x == 0 and y == 0.

quadrant: Quadrant property

The quadrant in the cartesian plane this point is located in.

Possible values are: - Quadrant.FIRST - Quadrant.SECOND - Quadrant.THIRD - Quadrant.FOURTH - Quadrant.ORIGIN - Quadrant.X_AXIS - Quadrant.Y_AXIS

radius: float property writable

The distance from this point to the origin.

radians: float property writable

The angle in radians measured counter-clockwise from 3 o'clock.

degrees: float property writable

The angle in degrees measured counter-clockwise from 3 o'clock.

polar: tuple[float, float] property writable

Polar coordinates tuple: (R, ϴ).

R is the distance from the origin to this point. ϴ is the angle (radians) measured counter-clockwise from 3 o'clock.

polar_deg: tuple[float, float] property writable

Polar coordinates tuple: (R, ϴ).

R is the distance from the origin to this point. ϴ is the angle (degrees) measured counter-clockwise from 3 o'clock.

xy: tuple[float, float] property writable

A tuple of this point's x and y coordinates.

Functions
from_polar(radius: float, theta: float, is_radians: bool = True, translate: Optional[Point] = None) -> Point classmethod

Returns a Point with polar coordinates (R, ϴ).

The point is genrated relative to the origin.

:param float radius: :param float theta: :param bool is_radians: :return: Point

distance(other: Optional[Point] = None) -> float

Return the floating point distance between self and other.

If other is not given, the distance from self to the origin is returned.

:param other: Point :return: float

distance_squared(other: Optional[Point] = None) -> float

Return the floating point squared distance between self and other.

If other is not given, the squared distance from self to the origin is returned.

:param other: Point :return: float

dot(other: Point) -> float

Return a scalar dot product of self with other.

:param other: Point :return: float

cross(other: Point) -> float

Return a scalar cross product of self with other.

:param other: Point :return: float

ccw(b: Point, c: Point) -> float

Return a floating point value indicating the winding direction of the points [self, b, c].

If ccw < 0, clock-wise winding If ccw > 0, counter clock-wise winding If ccw == 0, the three points are colinear

Note: ccw is also 2*area of the triangle [self, b, c].

:param b: Point :param c: Point :return: float

is_ccw(b: Point, c: Point) -> bool

Return True if the angle [self, b, c] has counter clock-wise winding, else False.

Raises the exception ColinearPoints if the points compose a line.

:param b: Point :param c: Point :return: bool

is_colinear(b: Point, c: Point) -> bool

True if the angle [self, b, c ] is a line, else False.

:param b: Point :param c: Point :return: bool

midpoint(other: Optional[Point] = None) -> Point

Return a new Point midway between self and other..

If other is not given, the midpoint between self and the origin is returned.

:param other: Point :return: Point

between(p: Point, q: Point) -> bool

True if self is bounded by the points [p, q], else False

The bounds are checked by less than or equal to (<=) so self is considered between if it resides on any of the lines constructed using [p,q].

:param p: Point :param q: Point :return: bool

inside(p: Point, q: Point) -> bool

True if point is bounded by the points (p, q), else False

The bounds are checked by less than (<) so point is considered inside if it does not reside on any of the lines constructed using (p,q).

:param p: Point :param q: Point :return: bool