ladybug_geometry.geometry2d.line module¶
2D Line Segment
- class ladybug_geometry.geometry2d.line.LineSegment2D(p, v)[source]¶
Bases:
Base1DIn2D
2D line segment object.
- Parameters:
p – A Point2D representing the first point of the line segment.
v – A Vector2D representing the vector to the second point.
- Properties:
p
v
p1
p2
min
max
center
midpoint
endpoints
length
vertices
- ToString()¶
Overwrite .NET ToString.
- closest_point(point)¶
Get the closest Point2D on this object to another Point2D.
- Parameters:
point – A Point2D object to which the closest point on this object will be computed.
- Returns:
Point2D for the closest point on this line to the input point.
- closest_points_between_line(line)[source]¶
Get the two closest Point2D between this object to another LineSegment2D.
Note that the line segments should not intersect for the result to be valid.
- Parameters:
line – A LineSegment2D object to which the closest points will be computed.
- Returns:
Two Point2D objects representing
The closest point on this object to the input line.
The closest point on the input line to this object.
- distance_to_line(line)[source]¶
Get the minimum distance between this object and the input LineSegment2D.
Note that the line segments should not intersect for the result to be valid.
- Parameters:
line – A LineSegment2D object to which the minimum distance will be computed.
- Returns:
The minimum distance to the input line.
- distance_to_point(point)¶
Get the minimum distance between this object and the input point.
- Parameters:
point – A Point2D object to which the minimum distance will be computed.
- Returns:
The distance to the input point.
- duplicate()¶
Get a copy of this object.
- classmethod from_array(line_array)[source]¶
Create a LineSegment2D from a nested array of two endpoint coordinates.
- Parameters:
line_array – Nested tuples ((pt1.x, pt1.y), (pt2.x, pt2.y)), where pt1 and pt2 represent the endpoints of the line segment.
- classmethod from_dict(data)¶
Create a LineSegment2D/Ray2D from a dictionary.
- Parameters:
data – A python dictionary in the following format
{ "p": (10, 0), "v": (10, 10) }
- classmethod from_end_points(p1, p2)[source]¶
Initialize a line segment from a start point and and end point.
- Parameters:
p1 – A Point2D representing the first point of the line segment.
p2 – A Point2D representing the second point of the line segment.
- classmethod from_sdl(s, d, length)[source]¶
Initialize a line segment from a start point, direction, and length.
- Parameters:
s – A Point2D representing the start point of the line segment.
d – A Vector2D representing the direction of the line segment.
length – A number representing the length of the line segment.
- intersect_line_ray(line_ray)[source]¶
Get the intersection between this object and another Ray2 or LineSegment2D.
- Parameters:
line_ray – Another LineSegment2D or Ray2D or to intersect.
- Returns:
Point2D of intersection if it exists. None if no intersection exists.
- is_colinear(line_ray, tolerance, angle_tolerance=None)¶
Test whether this object is colinear to another LineSegment2D or Ray2D.
- Parameters:
line_ray – Another LineSegment2D or Ray2D for which co-linearity with this object will be tested.
tolerance – The maximum distance between the line_ray and the infinite extension of this object for them to be considered colinear.
angle_tolerance – The max angle in radians that the direction between this object and another can vary for them to be considered parallel. If None, the angle tolerance will not be used to evaluate co-linearity and the lines will only be considered colinear if the endpoints of one line are within the tolerance distance of the other line. (Default: None).
- is_equivalent(other, tolerance)[source]¶
Boolean noting equivalence (within tolerance) between this line and another.
The order of the line points do not matter for equivalence to be true.
- Parameters:
other – LineSegment2D for comparison.
tolerance – float representing point equivalence.
- Returns:
True if equivalent else False
- is_parallel(line_ray, angle_tolerance)¶
Test whether this object is parallel to another LineSegment2D or Ray2D.
- Parameters:
line_ray – Another LineSegment2D or Ray2D for which parallelization with this objects will be tested.
angle_tolerance – The max angle in radians that the direction between this object and another can vary for them to be considered parallel.
- move(moving_vec)[source]¶
Get a line segment that has been moved along a vector.
- Parameters:
moving_vec – A Vector2D with the direction and distance to move the ray.
- offset(distance)[source]¶
Offset the line segment by a given distance.
- Parameters:
distance – The distance that the line segment will be offset. Both positive and negative values are accepted with positive values being offset to the left of the line and negative values being offset to the right of the line (starting from LineSegment.p and looking in the direction of LineSegment.v).
- point_at(parameter)[source]¶
Get a point at a given fraction along the line segment.
- Parameters:
parameter – The fraction between the start and end point where the desired point lies. For example, 0.5 will yield the midpoint.
- point_at_length(length)[source]¶
Get a point at a given distance along the line segment.
- Parameters:
length – The distance along the line from the start point where the desired point lies.
- reflect(normal, origin)[source]¶
Get a line segment reflected across a plane with the input normal and origin.
- Parameters:
normal – A Vector2D representing the normal vector for the plane across which the line segment will be reflected. THIS VECTOR MUST BE NORMALIZED.
origin – A Point2D representing the origin from which to reflect.
- rotate(angle, origin)[source]¶
Get a line segment that is rotated counterclockwise by a certain angle.
- Parameters:
angle – An angle for rotation in radians.
origin – A Point2D for the origin around which the line segment will be rotated.
- scale(factor, origin=None)[source]¶
Scale a line segment by a factor from an origin point.
- Parameters:
factor – A number representing how much the line segment should be scaled.
origin – A Point2D representing the origin from which to scale. If None, it will be scaled from the World origin (0, 0).
- subdivide(distances)[source]¶
Get Point2D values along the line that subdivide it based on input distances.
- Parameters:
distances – A list of distances along the line at which to subdivide it. This can also be a single number that will be repeated until the end of the line.
- subdivide_evenly(number)[source]¶
Get Point2D values along the line that divide it into evenly-spaced segments.
- Parameters:
number – The number of segments into which the line will be divided.
- property center¶
A Point2D for the center of the bounding rectangle around this geometry.
- property endpoints¶
Tuple of endpoints
- property length¶
The length of the line segment.
- property max¶
A Point2D for the maximum bounding rectangle vertex around this geometry.
- property midpoint¶
Midpoint.
- property min¶
A Point2D for the minimum bounding rectangle vertex around this geometry.
- property p¶
Base point.
- property p1¶
First point (same as p).
- property p2¶
Second point.
- property v¶
Direction vector.
- property vertices¶
Tuple of both vertices in this object.