Skip to content

Lines & Segments

Line primitives for connecting points and creating geometric constructions.


segment

def segment(
    p1: Point,
    p2: Point,
    *,
    label: str = "",
    label_dir: str = "NE",
    label_pos: float = 0.5,
    color: str = "black",
    style: str = "solid",
    width: float = 1.0,
    marks: int = 0,
) -> Segment

Create a line segment between two points.

Parameters:

Name Type Default Description
p1 Point required First endpoint
p2 Point required Second endpoint
label str "" Display label
label_dir str "NE" Direction for label placement (N, NE, E, SE, S, SW, W, NW)
label_pos float 0.5 Position along segment for label (0.0 to 1.0)
color str "black" Color for the segment
style str "solid" Line style (solid, dashed, dotted)
width float 1.0 Line width
marks int 0 Number of congruence marks

Returns: A Segment with TwoPoints construction.

Example

"""Basic segment example."""

from geolet import autofigure, point, segment


@autofigure
def segment_():
    A = point(0, 0, "A", label_dir="SW")
    B = point(4, 0, "B", label_dir="SE")

    seg = segment(A, B)

Segment


line

def line(
    p1: Point,
    p2: Point,
    *,
    label: str = "",
    label_dir: str = "NE",
    label_pos: float = 0.5,
    color: str = "black",
    style: str = "solid",
    width: float = 1.0,
) -> Line

Create an infinite line through two points.

Parameters:

Name Type Default Description
p1 Point required First point
p2 Point required Second point
label str "" Display label
label_dir str "NE" Direction for label placement (N, NE, E, SE, S, SW, W, NW)
label_pos float 0.5 Position along line for label (0.0 to 1.0)
color str "black" Color for the line
style str "solid" Line style (solid, dashed, dotted)
width float 1.0 Line width

Returns: A Line with ThroughPoints construction.

Example

"""Line example."""

from geolet import autofigure, line, point


@autofigure
def line_():
    A = point(0, 0, "A", label_dir="SW")
    B = point(2, 1, "B", label_dir="NE")

    l = line(A, B, color="blue")

Line


perpendicular

def perpendicular(
    to: Line | Segment,
    through: Point,
    *,
    label: str = "",
    label_dir: str = "NE",
    label_pos: float = 0.5,
    color: str = "black",
    style: str = "solid",
    width: float = 1.0,
) -> Line

Create a line perpendicular to another line/segment through a point.

Parameters:

Name Type Default Description
to Line \| Segment required Line or segment to be perpendicular to
through Point required Point the perpendicular passes through
label str "" Display label
label_dir str "NE" Direction for label placement (N, NE, E, SE, S, SW, W, NW)
label_pos float 0.5 Position along line for label (0.0 to 1.0)
color str "black" Color for the line
style str "solid" Line style (solid, dashed, dotted)
width float 1.0 Line width

Returns: A Line with PerpendicularTo construction.

Example

"""Perpendicular line example."""

from geolet import autofigure, perpendicular, point, segment


@autofigure
def perpendicular_():
    A = point(0, 0, "A", label_dir="SW")
    B = point(4, 0, "B", label_dir="SE")
    P = point(2, 2, "P", label_dir="N")
    seg = segment(A, B)

    perp = perpendicular(seg, P, color="red", style="dashed")

Perpendicular


parallel

def parallel(
    to: Line | Segment,
    through: Point,
    *,
    label: str = "",
    label_dir: str = "NE",
    label_pos: float = 0.5,
    color: str = "black",
    style: str = "solid",
    width: float = 1.0,
) -> Line

Create a line parallel to another line/segment through a point.

Parameters:

Name Type Default Description
to Line \| Segment required Line or segment to be parallel to
through Point required Point the parallel passes through
label str "" Display label
label_dir str "NE" Direction for label placement (N, NE, E, SE, S, SW, W, NW)
label_pos float 0.5 Position along line for label (0.0 to 1.0)
color str "black" Color for the line
style str "solid" Line style (solid, dashed, dotted)
width float 1.0 Line width

Returns: A Line with ParallelTo construction.

Example

"""Parallel line example."""

from geolet import autofigure, parallel, point, segment


@autofigure
def parallel_():
    A = point(0, 0, "A", label_dir="SW")
    B = point(4, 0, "B", label_dir="SE")
    C = point(1, 2, "C", label_dir="NW")

    seg = segment(A, B)
    par = parallel(seg, C, color="blue", style="dashed")

Parallel


Styling

Segment Styles

"""Segment styling options."""

from geolet import autofigure, point, segment


@autofigure
def segment_styles():
    # Points for segments
    A1 = point(0, 0, "A_1", label_dir="W")
    B1 = point(4, 0, "B_1", label_dir="E")

    A2 = point(0, 1.5, "A_2", label_dir="W")
    B2 = point(4, 1.5, "B_2", label_dir="E")

    A3 = point(0, 3, "A_3", label_dir="W")
    B3 = point(4, 3, "B_3", label_dir="E")

    A4 = point(0, 4.5, "A_4", label_dir="W")
    B4 = point(4, 4.5, "B_4", label_dir="E")

    A5 = point(0, 6, "A_5", label_dir="W")
    B5 = point(4, 6, "B_5", label_dir="E")

    s1 = segment(A1, B1, label="solid")
    s2 = segment(A2, B2, label="dashed", style="dashed")
    s3 = segment(A3, B3, label="dotted", style="dotted")

    # color
    s4 = segment(A4, B4, label="red", color="red")

    # marks (congruence marks)
    s5 = segment(A5, B5, label="marks=2", marks=2)

Segment styles

Line Styles

"""Line styling options."""

from geolet import autofigure, line, point


@autofigure
def line_styles():
    # Line styles (different angles to avoid overlap)
    A1 = point(0, 0, "A_1", label_dir="SW")
    B1 = point(2, 1, "B_1", label_dir="NE")

    A2 = point(0, 2, "A_2", label_dir="SW")
    B2 = point(2, 3.5, "B_2", label_dir="NE")

    A3 = point(0, 5, "A_3", label_dir="SW")
    B3 = point(2, 7, "B_3", label_dir="NE")

    l1 = line(A1, B1)
    l2 = line(A2, B2, style="dashed")
    l3 = line(A3, B3, style="dotted")

    # Colors (different angles)
    A4 = point(5, 0, "A_4", label_dir="SW")
    B4 = point(7, 1, "B_4", label_dir="NE")

    A5 = point(5, 2, "A_5", label_dir="SW")
    B5 = point(7, 3.5, "B_5", label_dir="NE")

    A6 = point(5, 5, "A_6", label_dir="SW")
    B6 = point(7, 7, "B_6", label_dir="NE")

    l4 = line(A4, B4, color="red")
    l5 = line(A5, B5, color="blue")
    l6 = line(A6, B6, color="green")

    # Labels (different angles)
    A7 = point(10, 0, "A_7", label_dir="SW")
    B7 = point(12, 1, "B_7", label_dir="NE")

    A8 = point(10, 2, "A_8", label_dir="SW")
    B8 = point(12, 3.5, "B_8", label_dir="NE")

    A9 = point(10, 5, "A_9", label_dir="SW")
    B9 = point(12, 7, "B_9", label_dir="NE")

    # label with default position
    l7 = line(A7, B7, label="l")

    # label with label_pos
    l8 = line(A8, B8, label="m", label_pos=0.3)

    # label with label_dir
    l9 = line(A9, B9, label="n", label_dir="S")

Line styles