ladybug_geometry.geometry3d.line module

3D Line Segment

class ladybug_geometry.geometry3d.line.LineSegment3D(p, v)[source]

Bases: Base1DIn3D

3D line segment object.

Parameters
  • p – A Point3D representing the first point of the line segment.

  • v – A Vector3D representing the vector to the second point.

Properties:
  • p

  • v

  • p1

  • p2

  • min

  • max

  • midpoint

  • endpoints

  • length

  • vertices

ToString()

Overwrite .NET ToString.

closest_point(point)

Get the closest Point3D on this object to another Point3D.

Parameters

point – A Point3D object to which the closest point on this object will be computed.

Returns

Point3D for the closest point on this line/ray to the input point.

distance_to_point(point)

Get the minimum distance between this object and the input point.

Parameters

point – A Point3D object to which the minimum distance will be computed.

Returns

The distance to the input point.

duplicate()

Get a copy of this object.

flip()[source]

Get a copy of this line segment that is flipped.

classmethod from_array(line_array)[source]

Create a LineSegment3D from a nested array of two endpoint coordinates.

Parameters

line_array – Nested tuples ((pt1.x, pt1.y, pt.z), (pt2.x, pt2.y, pt.z)), where pt1 and pt2 represent the endpoints of the line segment.

classmethod from_dict(data)

Create a LineSegment3D/Ray3D from a dictionary.

Parameters

data – A python dictionary in the following format

{
"p": (10, 0, 0),
"v": (10, 10, 0)
}
classmethod from_end_points(p1, p2)[source]

Initialize a line segment from a start point and and end point.

Parameters
  • p1 – A Point3D representing the first point of the line segment.

  • p2 – A Point3D representing the second point of the line segment.

classmethod from_line_segment2d(line2d, z=0)[source]

Initialize a new LineSegment3D from an LineSegment2D and a z value.

Parameters
  • line2d – A LineSegment2D to be used to generate the LineSegment3D.

  • z – A number for the Z coordinate value of the line.

classmethod from_sdl(s, d, length)[source]

Initialize a line segment from a start point, direction, and length.

Parameters
  • s – A Point3D representing the start point of the line segment.

  • d – A Vector3D representing the direction of the line segment.

  • length – A number representing the length of the line segment.

intersect_plane(plane)

Get the intersection between this object and a Plane.

Parameters

plane – A Plane that will be intersected with this object.

Returns

A Point3D object if the intersection was successful. None if no intersection exists.

is_colinear(line_ray, tolerance, angle_tolerance=None)

Test whether this object is colinear to another LineSegment3D or Ray3D.

Parameters
  • line_ray – Another LineSegment3D or Ray3D 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_horizontal(tolerance)[source]

Test whether this line segment is horizontal within a certain tolerance.

Parameters

tolerance – The maximum difference between the z values of the start and end coordinates at which the line segment is considered horizontal.

is_parallel(line_ray, angle_tolerance)

Test whether this object is parallel to another LineSegment3D or Ray3D.

Parameters
  • line_ray – Another LineSegment3D or Ray3D 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.

is_vertical(tolerance)[source]

Test whether this line segment is vertical within a certain tolerance.

Parameters

tolerance – The maximum difference between the x and y values of the start and end coordinates at which the line segment is considered horizontal.

move(moving_vec)[source]

Get a line segment that has been moved along a vector.

Parameters

moving_vec – A Vector3D with the direction and distance to move the ray.

point_at(parameter)[source]

Get a Point3D 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 Point3D 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 vector and origin.

Parameters
  • normal – A Vector3D representing the normal vector for the plane across which the line segment will be reflected. THIS VECTOR MUST BE NORMALIZED.

  • origin – A Point3D representing the origin from which to reflect.

rotate(axis, angle, origin)[source]

Rotate a line segment by a certain angle around an axis and origin.

Right hand rule applies: If axis has a positive orientation, rotation will be clockwise. If axis has a negative orientation, rotation will be counterclockwise.

Parameters
  • axis – A Vector3D axis representing the axis of rotation.

  • angle – An angle for rotation in radians.

  • origin – A Point3D for the origin around which the object will be rotated.

rotate_xy(angle, origin)[source]

Get a line segment rotated counterclockwise in the XY plane by a certain angle.

Parameters
  • angle – An angle in radians.

  • origin – A Point3D for the origin around which the object 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 Point3D representing the origin from which to scale. If None, it will be scaled from the World origin (0, 0, 0).

split_with_plane(plane)[source]

Split this LineSegment3D in 2 smaller LineSegment3Ds using a Plane.

Parameters

plane – A Plane that will be used to split this line segment.

Returns

A list of two LineSegment3D objects if the split was successful. Will be a list with 1 LineSegment3D if no intersection exists.

subdivide(distances)[source]

Get Point3D 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 Point3D values along the line that divide it into evenly-spaced segments.

Parameters

number – Integer for the number of segments into which the line will be divided.

to_array()[source]

A nested list representing the two line endpoint coordinates.

to_dict()[source]

Get LineSegment3D as a dictionary.

property endpoints

Tuple of endpoints

property length

The length of the line segment.

property max

A Point3D for the maximum bounding box vertex around this geometry.

property midpoint

Midpoint.

property min

A Point3D for the minimum bounding box 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.