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,
- start_point: ostk.mathematics.geometry.d2.object.Point,
Bases:
ObjectCreate a 2D segment defined by two endpoints.
- Parameters:
Example
>>> start = Point(0.0, 0.0) >>> end = Point(1.0, 1.0) >>> segment = Segment(start, end)
Methods
Apply a transformation to the segment in place.
Check if this 2D object contains another object.
Overloaded function.
Get the center (midpoint) of the segment.
Get the direction vector of the segment (from start to end, normalized).
Get the first (starting) point of the segment.
Get the length of the segment.
Get the second (ending) point of the segment.
Check if this 2D object intersects with another object.
Check if the segment is defined.
Check if the segment is degenerate (start and end points are the same).
Convert the segment to an infinite line.
Convert the segment to a string representation.
Create an undefined segment.
- class Format(self: ostk.mathematics.geometry.d2.Object.Format, value: int)¶
Bases:
pybind11_objectMembers:
Undefined
Standard
WKT
- property name¶
- apply_transformation(
- self: ostk.mathematics.geometry.d2.object.Segment,
- transformation: ostk::mathematics::geometry::d2::Transformation,
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( ) 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:
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.
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
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( ) ostk.mathematics.geometry.d2.object.Point¶
Get the center (midpoint) of the segment.
- Returns:
The center point of the segment.
- Return type:
Example
>>> segment = Segment(Point(0.0, 0.0), Point(2.0, 2.0)) >>> center = segment.get_center() # Point(1.0, 1.0)
- get_direction( ) 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( ) ostk.mathematics.geometry.d2.object.Point¶
Get the first (starting) point of the segment.
- Returns:
The starting point of the segment.
- Return type:
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( ) ostk.core.type.Real¶
Get the length of the segment.
- Returns:
The length of the segment.
- Return type:
Example
>>> segment = Segment(Point(0.0, 0.0), Point(3.0, 4.0)) >>> length = segment.get_length() # 5.0
- get_second_point( ) ostk.mathematics.geometry.d2.object.Point¶
Get the second (ending) point of the segment.
- Returns:
The ending point of the segment.
- Return type:
Example
>>> segment = Segment(Point(0.0, 0.0), Point(1.0, 1.0)) >>> end = segment.get_second_point() # Point(1.0, 1.0)
- intersects( ) 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:
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:
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:
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( ) 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:
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,
- format: ostk.mathematics.geometry.d2.Object.Format = <Format.Standard: 1>,
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:
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:
Example
>>> undefined_segment = Segment.undefined() >>> undefined_segment.is_defined() # False