Geometry Module

Geometry related functions.

find_closest_plane(points)

Find the closest plane to a set of points based on Euclidean distance.

fit_plane_svd(points)

get_a_polygon_from_plane_equation_and_point(...)

Get a polygon from plane equation and point.

get_angle_between_lines(l1, l2)

get_angle_between_vectors(v1, v2)

get_best_plane_from_points_from_two_segments(...)

Computes the best fitting plane to the four points of two segments.

get_centroid_of_points(points)

Get the centroid of a set of points.

get_distance_from_point_to_plane(point, plane)

Get the distance from a point to a plane.

get_distance_from_points_to_plane(points, plane)

Get the distance from a np array of points to a plane.

get_intersection_point_of_line_with_plane(...)

Get the intersection point of a line with a plane.

get_intersection_points_of_line_with_cube(...)

Get the intersection points of a line with a cube.

get_limits_of_3d_graph_from_limits_of_object(...)

Get limits of graph from limits of object.

get_limits_of_graph_from_limits_of_object(...)

Get limits of graph from limits of object.

get_parallelepiped_3d_vertices(center, ...)

Get vertices of parallelepiped, given center, normal vectors, and lengths.

get_parallelogram_2d_vertices(center, ...)

Get vertices of parallelogram, given center, normal vectors, and lengths.

get_parallelogram_3d_vertices(center, ...)

Get vertices of parallelogram, given center, normal vectors, and lengths.

get_plane_equation(normal1, normal2, point)

get_plane_from_list_of_three_points(points)

Get plane in form Ax + By + Cz + D = 0 from list of three points.

get_point_of_plane_closest_to_given_point(...)

Get the point of a plane closest to a given point.

get_two_perpendicular_unit_vectors_in_plane(plane)

Get two perpendicular unit vectors in a plane.

geometry.find_closest_plane(points: List[List[float]]) Tuple[float][source]

Find the closest plane to a set of points based on Euclidean distance.

Parameters:

points (List[List[float]]) – Points.

Returns:

Plane equation coefficients.

Return type:

Tuple[float]

geometry.get_a_polygon_from_plane_equation_and_point(plane: ndarray, point: ndarray, scale: float = 1.0) ndarray[source]

Get a polygon from plane equation and point.

Parameters:
  • plane (np.ndarray) – Plane equation coefficients.

  • point (np.ndarray) – Point.

  • scale (float) – Scale.

Returns:

Polygon.

Return type:

np.ndarray

Example:

>>> import rsaitehu.geometry as geom
>>> import numpy as np
>>> plane = np.array([0, 0, 1, -3])
>>> point = np.array([1, 1, 1])
>>> polygon = geom.get_a_polygon_from_plane_equation_and_point(plane, point)
>>> polygon
geometry.get_best_plane_from_points_from_two_segments(segment_1: ndarray, segment_2: ndarray) Tuple[ndarray, float][source]

Computes the best fitting plane to the four points of two segments.

Parameters:
  • segment_1 (np.ndarray) – The first segment.

  • segment_2 (np.ndarray) – The second segment.

Returns:

The best fitting plane and the sum of squared errors.

Return type:

Tuple[np.ndarray, float]

Example:

>>> import rsaitehu.geometry as geom
>>> import numpy as np
>>> segment_1 = np.array([[0, 0, 0], [1, 0, 0]])
>>> segment_2 = np.array([[0, 1, 0], [1, 1, 0]])
>>> geom.get_best_plane_from_points_from_two_segments(segment_1, segment_2)
(array([ 0.,  0.,  1., -0.]), 0.0)
>>> # another example
>>> segment_1 = np.array([[1, 2, 3], [4, 5, 6]])
>>> segment_2 = np.array([[7, 8, 9], [10, 11, 12]])
>>> geom.get_best_plane_from_points_from_two_segments(segment_1, segment_2)
(array([ 0.81649658, -0.40824829, -0.40824829,  1.22474487]),
1.0107280348144214e-29)
>>> # another example 
>>> segment_1 = np.array([[0, 0, 0], [1, 0, 0]])
>>> segment_2 = np.array([[0, 1, 0], [1, 1, 1]])
>>> geom.get_best_plane_from_points_from_two_segments(segment_1, segment_2)
(array([-0.45440135, -0.45440135,  0.76618459,  0.2628552 ]),
0.15692966918274637)
geometry.get_centroid_of_points(points: ndarray) ndarray[source]

Get the centroid of a set of points.

Parameters:

points (np.ndarray) – Points.

Returns:

Centroid.

Return type:

np.ndarray

Example:

>>> import rsaitehu.geometry as geom
>>> import numpy as np
>>> points = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0]])
>>> centroid = geom.get_centroid_of_points(points)
>>> centroid
array([0.33333333, 0.33333333, 0.        ])
geometry.get_distance_from_point_to_plane(point: Tuple[float, float, float], plane: Tuple[float, float, float, float]) float[source]

Get the distance from a point to a plane.

Parameters:
  • point (Tuple[float, float, float]) – Point.

  • plane (Tuple[float, float, float, float]) – Plane equation coefficients.

Returns:

Distance from point to plane.

Return type:

float

Example:

geometry.get_distance_from_points_to_plane(points: ndarray, plane: Tuple[float, float, float, float]) ndarray[source]

Get the distance from a np array of points to a plane.

Parameters:
  • points (np.ndarray) – Points.

  • plane (Tuple[float, float, float, float]) – Plane equation coefficients.

Returns:

Distance from points to plane.

Return type:

np.ndarray

Example:

geometry.get_intersection_point_of_line_with_plane(line: ndarray, plane: ndarray) ndarray | None[source]

Get the intersection point of a line with a plane. If it is parallel, return None.

Parameters:
  • line (np.ndarray) – Line described as two points.

  • plane (np.ndarray) – Plane described as Ax + By + Cz + D = 0.

Returns:

Intersection point.

Return type:

Optional[np.ndarray]

Example:

>>> import rsaitehu.geometry as geom
>>> import numpy as np 
>>> import rsaitehu.drawing as drawing
>>> line = np.array([[0, 0, 0], [1, 1, 1]])
>>> plane = np.array([0, 0, 1, -3])
>>> intersection_point = geom.get_intersection_point_of_line_with_plane(line, plane)
>>> intersection_point
array([3., 3., 3.])
>>> drawing.draw_line_extension_to_plane(line, plane)

drawing_draw_line_extension_to_plane_example

geometry.get_intersection_points_of_line_with_cube(line: ndarray, cube_min: ndarray, cube_max: ndarray) ndarray[source]

Get the intersection points of a line with a cube.

Parameters:
  • line (np.ndarray) – Line described as two points.

  • cube_min (np.ndarray) – Minimum point of the cube.

  • cube_max (np.ndarray) – Maximum point of the cube.

Returns:

Intersection points.

Return type:

np.ndarray

Example:

>>> import rsaitehu.geometry as geom
>>> import rsaitehu.drawing as drawing
>>> import numpy as np
>>> line = np.array([[0, 0, 0], [1, 1, 1]])
>>> cube_min = np.array([-2, -2, -1])
>>> cube_max = np.array([1, 2, 2])
>>> intersection_points = geom.get_intersection_points_of_line_with_cube(line, cube_min, cube_max)
>>> intersection_points
array([[ 1.,  1.,  1.],
      [-1., -1., -1.]])
geometry.get_limits_of_3d_graph_from_limits_of_object(min_x: float, max_x: float, min_y: float, max_y: float, min_z: float, max_z: float) Tuple[float, float, float, float, float, float][source]

Get limits of graph from limits of object. The (0,0,0) point should be in the center of the graph and the object should be whole visible. The visible zone should be square. This is useful for plotting.

Parameters:
  • min_x (float) – Minimum x.

  • max_x (float) – Maximum x.

  • min_y (float) – Minimum y.

  • max_y (float) – Maximum y.

  • min_z (float) – Minimum z.

Returns:

Limits of graph.

Return type:

Tuple[float, float, float, float, float, float]

geometry.get_limits_of_graph_from_limits_of_object(min_x: float, max_x: float, min_y: float, max_y: float) Tuple[float, float, float, float][source]

Get limits of graph from limits of object. The (0,0) point should be in the center of the graph and the object should be whole visible. The visible zone should be square. This is useful for plotting.

Parameters:
  • min_x (float) – Minimum x.

  • max_x (float) – Maximum x.

  • min_y (float) – Minimum y.

  • max_y (float) – Maximum y.

Returns:

Limits of graph.

Return type:

Tuple[float, float, float, float]

geometry.get_parallelepiped_3d_vertices(center: List[float], normal1: List[float], normal2: List[float], normal3: List[float], length1: float, length2: float, length3: float) List[List[float]][source]

Get vertices of parallelepiped, given center, normal vectors, and lengths.

Parameters:
  • center (List[float]) – Center.

  • normal1 (List[float]) – Normal vector 1.

  • normal2 (List[float]) – Normal vector 2.

  • normal3 (List[float]) – Normal vector 3.

  • length1 (float) – Length 1.

  • length2 (float) – Length 2.

  • length3 (float) – Length 3.

Returns:

Vertices.

Return type:

List[List[float]]

Example:

geometry.get_parallelogram_2d_vertices(center: List[float], normal1: List[float], normal2: List[float], length1: float, length2: float)[source]

Get vertices of parallelogram, given center, normal vectors, and lengths.

Parameters:
  • center (List[float]) – Center.

  • normal1 (List[float]) – Normal vector 1.

  • normal2 (List[float]) – Normal vector 2.

  • length1 (float) – Length 1.

  • length2 (float) – Length 2.

Returns:

Vertices.

Return type:

List[List[float]]

Example:

geometry.get_parallelogram_3d_vertices(center: List[float], normal1: List[float], normal2: List[float], length1: float, length2: float) List[List[float]][source]

Get vertices of parallelogram, given center, normal vectors, and lengths.

Parameters:
  • center (List[float]) – Center.

  • normal1 (List[float]) – Normal vector 1.

  • normal2 (List[float]) – Normal vector 2.

  • length1 (float) – Length 1.

  • length2 (float) – Length 2.

Returns:

Vertices.

Return type:

List[List[float]]

Example:

geometry.get_plane_from_list_of_three_points(points: List[List[float]]) ndarray | None[source]

Get plane in form Ax + By + Cz + D = 0 from list of three points.

Parameters:

points (List[List[float]]) – Points.

Returns:

Plane.

Return type:

Union[np.ndarray, None]

Example:

>>> import coreransac
>>> points = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
>>> plane = customransac.get_plane_from_points(points)
>>> plane
array([0, 0, 1, 0])
geometry.get_point_of_plane_closest_to_given_point(plane: ndarray, point: ndarray) ndarray[source]

Get the point of a plane closest to a given point.

Parameters:
  • plane (np.ndarray) – Plane described as Ax + By + Cz + D = 0.

  • point (np.ndarray) – Point.

Returns:

Point of plane closest to given point.

Return type:

np.ndarray

Example:

geometry.get_two_perpendicular_unit_vectors_in_plane(plane: ndarray) Tuple[ndarray, ndarray][source]

Get two perpendicular unit vectors in a plane.

Parameters:

plane (np.ndarray) – Plane described as Ax + By + Cz + D = 0.

Returns:

Two perpendicular unit vectors in the plane.

Return type:

Tuple[np.ndarray, np.ndarray]

Example:

>>> import rsaitehu.geometry as geom
>>> import numpy as np
>>> plane = np.array([0, 0, 1, -3])
>>> perpendicular1, perpendicular2 = geom.get_two_perpendicular_unit_vectors_in_plane(plane)
>>> perpendicular1
array([0., 1., 0.])
>>> perpendicular2
array([-1., 0., 0.])