Skip to content

Line

Line

Bases: DrawingObject

A class to create lines in the tikz environment.

The Line class helps handle the creation of lines in tikz code. It is analagous to the TikZ code

\draw[<options>] <start> to [<to_options>] <end>;
Lines in TikZ have even more features, like adding control points, and these features are accessible through the Line class.

Parameters:

Name Type Description Default
start Union[Tuple[float, float], Point]

Pair of floats representing the start of the line

required
end Union[Tuple[float, float], Point]

Pair of floats representing the end of the line

required
options str

String containing Tikz drawing options, e.g. "Blue"

''
control_pts List[Tuple]

List of control points for the line

[]

end property writable

end: Point

Returns a Point object representing the end of the line.

start property writable

start: Point

Returns a Point object representing the start of the line.

midpoint

midpoint() -> Point

Returns a Point object representing the middle of the line.

pos_at_t

pos_at_t(t: float) -> Point

Returns the point on the line that lies at "time t", on a scale from 0 to 1.

rotate

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

Rotate start, end, and control_pts. By default, the rotation is done relative to the midpoint of the line.

scale

scale(scale: float) -> None

Scale start, end, and control_pts.

shift

shift(xshift: float, yshift: float) -> None

Shift start, end, and control_pts

Examples

Here's an example of us using the Line class.

import tikzpy

tikz = tikzpy.TikzPicture()
tikz.line((0, 0), (4, 0), options="->", control_pts=[(1, 1), (3, -1)]
which generates