ostk.mathematics.geometry.d2.object.Segment

class Segment(
self: ostk.mathematics.geometry.d2.object.Segment,
start_point: ostk.mathematics.geometry.d2.object.Point,
end_point: ostk.mathematics.geometry.d2.object.Point,
)

Bases: Object

Create a 2D segment defined by two endpoints.

Parameters:
  • start_point (Point) -- The starting point of the segment.

  • end_point (Point) -- The ending point of the segment.

Example

>>> start = Point(0.0, 0.0)
>>> end = Point(1.0, 1.0)
>>> segment = Segment(start, end)

Methods

apply_transformation

Apply a transformation to the segment in place.

contains

Check if this 2D object contains another object.

distance_to

Overloaded function.

get_center

Get the center (midpoint) of the segment.

get_direction

Get the direction vector of the segment (from start to end, normalized).

get_first_point

Get the first (starting) point of the segment.

get_length

Get the length of the segment.

get_second_point

Get the second (ending) point of the segment.

intersects

Check if this 2D object intersects with another object.

is_defined

Check if the segment is defined.

is_degenerate

Check if the segment is degenerate (start and end points are the same).

to_line

Convert the segment to an infinite line.

to_string

Convert the segment to a string representation.

undefined

Create an undefined segment.

class Format(self: ostk.mathematics.geometry.d2.Object.Format, value: int)

Bases: pybind11_object

Members:

Undefined

Standard

WKT

property name
apply_transformation(
self: ostk.mathematics.geometry.d2.object.Segment,
transformation: ostk::mathematics::geometry::d2::Transformation,
) None

Apply a transformation to the segment in place.

Parameters:

transformation (Transformation) -- The 2D transformation to apply.

Example

>>> segment = Segment(Point(0.0, 0.0), Point(1.0, 1.0))
>>> transformation = Translation([1.0, 1.0])
>>> segment.apply_transformation(transformation)
contains(
self: ostk.mathematics.geometry.d2.Object,
object: ostk.mathematics.geometry.d2.Object,
) bool

Check if this 2D object contains another object.

Parameters:

object (Object) -- The object to check containment for.

Returns:

True if this object contains the other, False otherwise.

Return type:

bool

Example

>>> polygon = Polygon([Point(0.0, 0.0), Point(2.0, 0.0), Point(2.0, 2.0)])
>>> point = Point(1.0, 1.0)
>>> polygon.contains(point)  # True
distance_to(*args, **kwargs)

Overloaded function.

  1. distance_to(self: ostk.mathematics.geometry.d2.object.Segment, point: ostk.mathematics.geometry.d2.object.Point) -> ostk.core.type.Real

    Calculate the distance from the segment to a point.

    Args:

    point (Point): The point to calculate distance to.

    Returns:

    float: The minimum distance from the segment to the point.

    Example:
    >>> segment = Segment(Point(0.0, 0.0), Point(2.0, 0.0))
    >>> distance = segment.distance_to(Point(1.0, 1.0))  # 1.0
    
  2. distance_to(self: ostk.mathematics.geometry.d2.object.Segment, point_set: ostk.mathematics.geometry.d2.object.PointSet) -> ostk.core.type.Real

    Calculate the distance from the segment to a point set.

    Args:

    point_set (PointSet): The point set to calculate distance to.

    Returns:

    float: The minimum distance from the segment to any point in the set.

    Example:
    >>> segment = Segment(Point(0.0, 0.0), Point(2.0, 0.0))
    >>> points = PointSet([Point(1.0, 1.0), Point(3.0, 1.0)])
    >>> distance = segment.distance_to(points)  # 1.0
    
get_center(
self: ostk.mathematics.geometry.d2.object.Segment,
) ostk.mathematics.geometry.d2.object.Point

Get the center (midpoint) of the segment.

Returns:

The center point of the segment.

Return type:

Point

Example

>>> segment = Segment(Point(0.0, 0.0), Point(2.0, 2.0))
>>> center = segment.get_center()  # Point(1.0, 1.0)
get_direction(
self: ostk.mathematics.geometry.d2.object.Segment,
) numpy.ndarray[numpy.float64[2, 1]]

Get the direction vector of the segment (from start to end, normalized).

Returns:

The normalized direction vector of the segment.

Return type:

Vector2d

Example

>>> segment = Segment(Point(0.0, 0.0), Point(3.0, 4.0))
>>> direction = segment.get_direction()  # [0.6, 0.8]
get_first_point(
self: ostk.mathematics.geometry.d2.object.Segment,
) ostk.mathematics.geometry.d2.object.Point

Get the first (starting) point of the segment.

Returns:

The starting point of the segment.

Return type:

Point

Example

>>> segment = Segment(Point(0.0, 0.0), Point(1.0, 1.0))
>>> start = segment.get_first_point()  # Point(0.0, 0.0)
get_length(
self: ostk.mathematics.geometry.d2.object.Segment,
) ostk.core.type.Real

Get the length of the segment.

Returns:

The length of the segment.

Return type:

float

Example

>>> segment = Segment(Point(0.0, 0.0), Point(3.0, 4.0))
>>> length = segment.get_length()  # 5.0
get_second_point(
self: ostk.mathematics.geometry.d2.object.Segment,
) ostk.mathematics.geometry.d2.object.Point

Get the second (ending) point of the segment.

Returns:

The ending point of the segment.

Return type:

Point

Example

>>> segment = Segment(Point(0.0, 0.0), Point(1.0, 1.0))
>>> end = segment.get_second_point()  # Point(1.0, 1.0)
intersects(
self: ostk.mathematics.geometry.d2.Object,
object: ostk.mathematics.geometry.d2.Object,
) bool

Check if this 2D object intersects with another object.

Parameters:

object (Object) -- The object to check intersection with.

Returns:

True if objects intersect, False otherwise.

Return type:

bool

Example

>>> line1 = Line(Point(0.0, 0.0), numpy.array([1.0, 0.0]))
>>> line2 = Line(Point(0.0, -1.0), numpy.array([0.0, 1.0]))
>>> line1.intersects(line2)  # True
is_defined(self: ostk.mathematics.geometry.d2.object.Segment) bool

Check if the segment is defined.

Returns:

True if the segment is defined, False otherwise.

Return type:

bool

Example

>>> segment = Segment(Point(0.0, 0.0), Point(1.0, 1.0))
>>> segment.is_defined()  # True
is_degenerate(self: ostk.mathematics.geometry.d2.object.Segment) bool

Check if the segment is degenerate (start and end points are the same).

Returns:

True if the segment is degenerate, False otherwise.

Return type:

bool

Example

>>> segment = Segment(Point(1.0, 1.0), Point(1.0, 1.0))
>>> segment.is_degenerate()  # True
>>> segment2 = Segment(Point(0.0, 0.0), Point(1.0, 1.0))
>>> segment2.is_degenerate()  # False
to_line(
self: ostk.mathematics.geometry.d2.object.Segment,
) ostk.mathematics.geometry.d2.object.Line

Convert the segment to an infinite line.

Returns:

A line that passes through both endpoints of the segment.

Return type:

Line

Example

>>> segment = Segment(Point(0.0, 0.0), Point(1.0, 1.0))
>>> line = segment.to_line()
to_string(
self: ostk.mathematics.geometry.d2.object.Segment,
format: ostk.mathematics.geometry.d2.Object.Format = <Format.Standard: 1>,
precision: ostk.core.type.Integer = Undefined,
) ostk.core.type.String

Convert the segment to a string representation.

Parameters:
  • format (Object.Format, optional) -- The output format. Defaults to Standard.

  • precision (int, optional) -- The precision for floating point numbers. Defaults to undefined.

Returns:

String representation of the segment.

Return type:

str

Example

>>> segment = Segment(Point(0.0, 0.0), Point(1.0, 1.0))
>>> segment.to_string()
static undefined() ostk.mathematics.geometry.d2.object.Segment

Create an undefined segment.

Returns:

An undefined segment object.

Return type:

Segment

Example

>>> undefined_segment = Segment.undefined()
>>> undefined_segment.is_defined()  # False