ostk.mathematics.geometry.d3.object.Segment

class Segment(
self,
first_point: ostk.mathematics.geometry.d3.object.Point,
second_point: ostk.mathematics.geometry.d3.object.Point,
)

Bases: Object

Create a 3D segment between two points.

Parameters:
  • first_point (Point) -- The first endpoint of the segment.

  • second_point (Point) -- The second endpoint of the segment.

Example

>>> point1 = Point(0.0, 0.0, 0.0)
>>> point2 = Point(1.0, 1.0, 1.0)
>>> segment = Segment(point1, point2)

Attributes

apply_transformation

Apply a transformation to the segment in place.

as_cone

Convert the object to a cone.

as_ellipsoid

Convert the object to an ellipsoid.

as_line

Convert the object to a line.

as_line_string

Convert the object to a line string.

as_plane

Convert the object to a plane.

as_point

Convert the object to a point.

as_point_set

Convert the object to a point set.

as_polygon

Convert the object to a polygon.

as_pyramid

Convert the object to a pyramid.

as_ray

Convert the object to a ray.

as_segment

Convert the object to a segment.

as_sphere

Convert the object to a sphere.

contains

Check if the segment contains a point.

distance_to

Overloaded function.

get_center

Get the center point of the segment.

get_direction

Get the direction vector of the segment.

get_first_point

Get the first endpoint of the segment.

get_length

Get the length of the segment.

get_second_point

Get the second endpoint of the segment.

intersection_with

Calculate the intersection of the segment with a plane.

intersects

Overloaded function.

is_cone

Check if the object is a cone.

is_degenerate

Check if the segment is degenerate (both endpoints are the same).

is_ellipsoid

Check if the object is an ellipsoid.

is_line

Check if the object is a line.

is_line_string

Check if the object is a line string.

is_plane

Check if the object is a plane.

is_point

Check if the object is a point.

is_point_set

Check if the object is a point set.

is_polygon

Check if the object is a polygon.

is_pyramid

Check if the object is a pyramid.

is_ray

Check if the object is a ray.

is_segment

Check if the object is a segment.

is_sphere

Check if the object is a sphere.

to_line

Convert the segment to a line.

apply_transformation

Apply a transformation to the segment in place.

Parameters:

transformation (Transformation) -- The transformation to apply.

Example

>>> segment = Segment(Point(0.0, 0.0, 0.0), Point(1.0, 1.0, 1.0))
>>> transformation = Translation([1.0, 1.0, 1.0])
>>> segment.apply_transformation(transformation)
as_cone

Convert the object to a cone.

Returns:

The cone.

Return type:

Cone

as_ellipsoid

Convert the object to an ellipsoid.

Returns:

The ellipsoid.

Return type:

Ellipsoid

as_line

Convert the object to a line.

Returns:

The line.

Return type:

Line

as_line_string

Convert the object to a line string.

Returns:

The line string.

Return type:

LineString

as_plane

Convert the object to a plane.

Returns:

The plane.

Return type:

Plane

as_point

Convert the object to a point.

Returns:

The point.

Return type:

Point

as_point_set

Convert the object to a point set.

Returns:

The point set.

Return type:

PointSet

as_polygon

Convert the object to a polygon.

Returns:

The polygon.

Return type:

Polygon

as_pyramid

Convert the object to a pyramid.

Returns:

The pyramid.

Return type:

Pyramid

as_ray

Convert the object to a ray.

Returns:

The ray.

Return type:

Ray

as_segment

Convert the object to a segment.

Returns:

The segment.

Return type:

Segment

as_sphere

Convert the object to a sphere.

Returns:

The sphere.

Return type:

Sphere

contains

Check if the segment contains a point.

Parameters:

point (Point) -- The point to check.

Returns:

True if the segment contains the point, False otherwise.

Return type:

bool

Example

>>> segment = Segment(Point(0.0, 0.0, 0.0), Point(2.0, 0.0, 0.0))
>>> segment.contains(Point(1.0, 0.0, 0.0))  # True (midpoint)
distance_to

Overloaded function.

  1. distance_to(self, point: ostk.mathematics.geometry.d3.object.Point) -> float

    Calculate the distance from the segment to a point.

    Args:

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

    Returns:

    float: The distance from the segment to the point.

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

    Calculate the distance from the segment to a point set.

    Args:

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

    Returns:

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

    Example:
    >>> segment = Segment(Point(0.0, 0.0, 0.0), Point(2.0, 0.0, 0.0))
    >>> points = PointSet([Point(1.0, 0.0, 0.0), Point(3.0, 0.0, 0.0)])
    >>> distance = segment.distance_to(points)  # 1.0
    
get_center

Get the center point of the segment.

Returns:

The midpoint of the segment.

Return type:

Point

Example

>>> segment = Segment(Point(0.0, 0.0, 0.0), Point(2.0, 2.0, 2.0))
>>> center = segment.get_center()  # Point(1.0, 1.0, 1.0)
get_direction

Get the direction vector of the segment.

Returns:

The normalized direction vector from first to second point.

Return type:

Vector3d

Example

>>> segment = Segment(Point(0.0, 0.0, 0.0), Point(1.0, 0.0, 0.0))
>>> direction = segment.get_direction()  # [1.0, 0.0, 0.0]
get_first_point

Get the first endpoint of the segment.

Returns:

The first endpoint of the segment.

Return type:

Point

Example

>>> segment = Segment(Point(1.0, 2.0, 3.0), Point(4.0, 5.0, 6.0))
>>> first_point = segment.get_first_point()  # Point(1.0, 2.0, 3.0)
get_length

Get the length of the segment.

Returns:

The distance between the two endpoints.

Return type:

float

Example

>>> segment = Segment(Point(0.0, 0.0, 0.0), Point(3.0, 4.0, 0.0))
>>> length = segment.get_length()  # 5.0
get_second_point

Get the second endpoint of the segment.

Returns:

The second endpoint of the segment.

Return type:

Point

Example

>>> segment = Segment(Point(1.0, 2.0, 3.0), Point(4.0, 5.0, 6.0))
>>> second_point = segment.get_second_point()  # Point(4.0, 5.0, 6.0)
intersection_with

Calculate the intersection of the segment with a plane.

Parameters:

plane (Plane) -- The plane to calculate intersection with.

Returns:

The intersection of the segment with the plane.

Return type:

Intersection

Example

>>> segment = Segment(Point(0.0, 0.0, 0.0), Point(2.0, 0.0, 0.0))
>>> plane = Plane(Point(1.0, 0.0, 0.0), Vector3d(0.0, 0.0, 1.0))
>>> intersection = segment.intersection_with(plane)
>>> intersection.get_point()  # Point(1.0, 0.0, 0.0)
intersects

Overloaded function.

  1. intersects(self, plane: ostk.mathematics.geometry.d3.object.Plane) -> bool

    Check if the segment intersects a plane.

    Args:

    plane (Plane): The plane to check intersection with.

    Returns:

    bool: True if the segment intersects the plane.

    Example:
    >>> segment = Segment(Point(0.0, 0.0, 0.0), Point(2.0, 0.0, 0.0))
    >>> segment.intersects(Plane(Point(1.0, 0.0, 0.0), Vector3d(0.0, 0.0, 1.0)))  # True
    
  2. intersects(self, sphere: ostk.mathematics.geometry.d3.object.Sphere) -> bool

    Check if the segment intersects a sphere.

    Args:

    sphere (Sphere): The sphere to check intersection with.

    Returns:

    bool: True if the segment intersects the sphere.

    Example:
    >>> segment = Segment(Point(0.0, 0.0, 0.0), Point(2.0, 0.0, 0.0))
    >>> segment.intersects(Sphere(Point(1.0, 0.0, 0.0), 1.0))  # True
    
  3. intersects(self, ellipsoid: ostk.mathematics.geometry.d3.object.Ellipsoid) -> bool

    Check if the segment intersects an ellipsoid.

    Args:

    ellipsoid (Ellipsoid): The ellipsoid to check intersection with.

    Returns:

    bool: True if the segment intersects the ellipsoid.

    Example:
    >>> segment = Segment(Point(0.0, 0.0, 0.0), Point(2.0, 0.0, 0.0))
    >>> segment.intersects(Ellipsoid(Point(1.0, 0.0, 0.0), 1.0, 1.0, 1.0))  # True
    
is_cone

Check if the object is a cone.

Returns:

True if the object is a cone.

Return type:

bool

is_degenerate

Check if the segment is degenerate (both endpoints are the same).

Returns:

True if the segment is degenerate, False otherwise.

Return type:

bool

Example

>>> point = Point(0.0, 0.0, 0.0)
>>> degenerate_segment = Segment(point, point)
>>> degenerate_segment.is_degenerate()  # True
is_ellipsoid

Check if the object is an ellipsoid.

Returns:

True if the object is an ellipsoid.

Return type:

bool

is_line

Check if the object is a line.

Returns:

True if the object is a line.

Return type:

bool

is_line_string

Check if the object is a line string.

Returns:

True if the object is a line string.

Return type:

bool

is_plane

Check if the object is a plane.

Returns:

True if the object is a plane.

Return type:

bool

is_point

Check if the object is a point.

Returns:

True if the object is a point.

Return type:

bool

is_point_set

Check if the object is a point set.

Returns:

True if the object is a point set.

Return type:

bool

is_polygon

Check if the object is a polygon.

Returns:

True if the object is a polygon.

Return type:

bool

is_pyramid

Check if the object is a pyramid.

Returns:

True if the object is a pyramid.

Return type:

bool

is_ray

Check if the object is a ray.

Returns:

True if the object is a ray.

Return type:

bool

is_segment

Check if the object is a segment.

Returns:

True if the object is a segment.

Return type:

bool

is_sphere

Check if the object is a sphere.

Returns:

True if the object is a sphere.

Return type:

bool

to_line

Convert the segment to a line.

Returns:

A line passing through the segment's endpoints.

Return type:

Line

Example

>>> segment = Segment(Point(0.0, 0.0, 0.0), Point(1.0, 1.0, 1.0))
>>> line = segment.to_line()