Skip to content

Point

Point

A class to handle points for TikzPy.

The Point class is how TikzPy handles coordinates. All drawing objects, like Line and Circle, use the Point class under the hood.

The Point class is designed to perform arithmetic with instances of itself and with Python tuples. The constructor accepts can either accept two numeric arguments, a single tuple of floats argument, or a single Point object.

Parameters:

Name Type Description Default
first_arg Union[float, Number, tuple, Point]

A number, a tuple, or Point object.

required
second_arg Union[float, Number, None]

A number, in the case of a 2D point, or None.

None
third_arg Union[float, Number, None]

A number, in the case of a 3D point, or None.

None

__add__

__add__(other) -> Point

Allow Point + tuple and Point + Point arithmetic.

__eq__

__eq__(other)

Overrides the default implementation

__mul__

__mul__(scale: Number) -> Point

Allow Point * Number arithmetic.

__radd__

__radd__(other) -> Point

Allow tuple + Point arithmetic.

__rmul__

__rmul__(scale: float) -> Point

Allow Number * Point arithmetic.

__truediv__

__truediv__(scale) -> Point

Allow Point / Number arithmetic.

rotate

rotate(
    angle: float,
    about_pt: Union[Tuple[float, float], Point],
    radians: bool = False,
) -> None

Rotate the point about another point.

scale

scale(scale: float) -> None

Scale the point given the scale.

shift

shift(
    xshift: float,
    yshift: float,
    zshift: Optional[float] = None,
) -> None

Translate the point via x, y offsets.

to_tuple

to_tuple() -> Tuple

Return a tuple of the x, y data.

Examples

The Point class can be instantiated from a tuple or at least two Numbers. One can also represent a point in 3D with this class.

>>> from tikzpy import Point
>>> my_point = Point(-1, 2)
>>> my_point.x
-1
>>> my_point.y
2
You can also perform arithmetic with Point objects, either with other Point objects or with Python tuples. For example, the following are all valid.
>>> my_point + (1, 1)  # Add it to another tuple
Point(0, 3)
>>> my_point + Point(2, 2)  # Add it with another point object
Point(1, 4)
>>> 2 * my_point  # Can also do my_point * 2 
Point(-2, 4)
>>> my_point / 3 
Point(-0.33333333, 0.666666666)

This allows you to write things like

>>> circle = tikz.circle((0,0), radius=3)
>>> circle.center += (1, 1)  # This is valid
>>> circle.center /= 3  # Also valid
and this feature becomes quite useful in drawings that are highly complex.