colour.algebra.geometry Module¶
Geometry¶
Defines objects related to geometrical computations:
-
colour.algebra.geometry.
normalise_vector
(a)[source]¶ Normalises given vector \(a\).
Parameters: a (array_like) – Vector \(a\) to normalise. Returns: Normalised vector \(a\). Return type: ndarray Examples
>>> a = np.array([0.07049534, 0.10080000, 0.09558313]) >>> normalise_vector(a) array([ 0.4525410..., 0.6470802..., 0.6135908...])
-
colour.algebra.geometry.
euclidean_distance
(a, b)[source]¶ Returns the euclidean distance between point arrays \(a\) and \(b\).
Parameters: - a (array_like) – Point array \(a\).
- b (array_like) – Point array \(b\).
Returns: Euclidean distance.
Return type: numeric or ndarray
Examples
>>> a = np.array([100.00000000, 21.57210357, 272.22819350]) >>> b = np.array([100.00000000, 426.67945353, 72.39590835]) >>> euclidean_distance(a, b) 451.7133019...
-
colour.algebra.geometry.
extend_line_segment
(a, b, distance=1)[source]¶ Extends the line segment defined by point arrays \(a\) and \(b\) by given distance and return the new end point.
Parameters: - a (array_like) – Point array \(a\).
- b (array_like) – Point array \(b\).
- distance (numeric, optional) – Distance to extend the line segment.
Returns: New end point.
Return type: ndarray
References
[1] Saeedn. (n.d.). Extend a line segment a specific distance. Retrieved January 16, 2016, from http://stackoverflow.com/questions/7740507/extend-a-line-segment-a-specific-distance Notes
- Input line segment points coordinates are 2d coordinates.
Examples
>>> a = np.array([0.95694934, 0.13720932]) >>> b = np.array([0.28382835, 0.60608318]) >>> extend_line_segment(a, b) array([-0.5367248..., 1.1776534...])
-
class
colour.algebra.geometry.
LineSegmentsIntersections_Specification
[source]¶ Bases:
colour.algebra.geometry.LineSegmentsIntersections_Specification
Defines the specification for intersection of line segments \(l_1\) and \(l_2\) returned by
intersect_line_segments()
definition.Parameters: - xy (array_like) – Array of \(l_1\) and \(l_2\) line segments intersections coordinates. Non existing segments intersections coordinates are set with np.nan.
- intersect (array_like) – Array of bool indicating if line segments \(l_1\) and \(l_2\) intersect.
- parallel (array_like) – Array of bool indicating if line segments \(l_1\) and \(l_2\) are parallel.
- coincident (array_like) – Array of bool indicating if line segments \(l_1\) and \(l_2\) are coincident.
-
colour.algebra.geometry.
intersect_line_segments
(l_1, l_2)[source]¶ Computes \(l_1\) line segments intersections with \(l_2\) line segments.
Parameters: - l_1 (array_like) – \(l_1\) line segments array, each row is a line segment such as (\(x_1\), \(y_1\), \(x_2\), \(y_2\)) where (\(x_1\), \(y_1\)) and (\(x_2\), \(y_2\)) are respectively the start and end points of \(l_1\) line segments.
- l_2 (array_like) – \(l_2\) line segments array, each row is a line segment such as (\(x_3\), \(y_3\), \(x_4\), \(y_4\)) where (\(x_3\), \(y_3\)) and (\(x_4\), \(y_4\)) are respectively the start and end points of \(l_2\) line segments.
Returns: Line segments intersections specification.
Return type: References
[2] Bourke, P. (n.d.). Intersection point of two line segments in 2 dimensions. Retrieved January 15, 2016, from http://paulbourke.net/geometry/pointlineplane/ [3] Erdem, U. M. (n.d.). Fast Line Segment Intersection. Retrieved January 15, 2016, from http://www.mathworks.com/matlabcentral/fileexchange/27205-fast-line-segment-intersection Notes
- Input line segments points coordinates are 2d coordinates.
Examples
>>> l_1 = np.array([[[0.15416284, 0.7400497], ... [0.26331502, 0.53373939]], ... [[0.01457496, 0.91874701], ... [0.90071485, 0.03342143]]]) >>> l_2 = np.array([[[0.95694934, 0.13720932], ... [0.28382835, 0.60608318]], ... [[0.94422514, 0.85273554], ... [0.00225923, 0.52122603]], ... [[0.55203763, 0.48537741], ... [0.76813415, 0.16071675]]]) >>> s = intersect_line_segments(l_1, l_2) >>> s.xy array([[[ nan, nan], [ 0.2279184..., 0.6006430...], [ nan, nan]], [[ 0.4281451..., 0.5055568...], [ 0.3056055..., 0.6279838...], [ 0.7578749..., 0.1761301...]]]) >>> s.intersect array([[False, True, False], [ True, True, True]], dtype=bool) >>> s.parallel array([[False, False, False], [False, False, False]], dtype=bool) >>> s.coincident array([[False, False, False], [False, False, False]], dtype=bool)