sparrowpy.geometry#

Module for scene geometry handling and basic algebraic methods.

Classes:

Polygon(points, up_vector, normal)

Polygon constructed from greater than two points.

class sparrowpy.geometry.Polygon(points: ndarray, up_vector: ndarray, normal: ndarray)[source]#

Bases: object

Polygon constructed from greater than two points.

Only convex polygons are allowed! Order of points is of course important!

Attributes:

area

Return the area in m^2 of the polygon.

center

Return the center coordinates of the polygon.

n_points

Return the number of points of the polygon.

normal

Return the normal vector of the polygon.

pts

size

Return the size in (lxmxn) of the polygon.

up_vector

Methods:

from_dict(input_dict)

Create an object from a dictionary.

intersection(origin, direction)

Return a intersection point with a ray and the polygon.

on_surface(point)

Return if a point is on the surface of the polygon.

plot([ax, color])

Plot the polygon.

plot_point([ax, color])

Plot the polygon points.

plot_view_up([ax])

Plot the view and up vector of the polygon.

to_dict()

Convert this object to dictionary.

property area: ndarray#

Return the area in m^2 of the polygon. supports all convex polygons and some concave polygons.

property center: ndarray#

Return the center coordinates of the polygon.

classmethod from_dict(input_dict)[source]#

Create an object from a dictionary. Used for read write.

intersection(origin: ndarray, direction: ndarray) ndarray[source]#

Return a intersection point with a ray and the polygon.

Parameters:
  • origin (np.ndarray) – origin of the incoming wave

  • direction (np.ndarray) – direction of the incoming wave

Returns:

intersection point, if it hit, otherwise None

Return type:

np.ndarray

property n_points: int#

Return the number of points of the polygon.

property normal: ndarray#

Return the normal vector of the polygon.

on_surface(point: ndarray) bool[source]#

Return if a point is on the surface of the polygon.

Returns True if the point is on the polygon’s surface and false otherwise.

plot(ax: Axes = None, color=None)[source]#

Plot the polygon.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – _description_, by default None

  • color (_type_, optional) – _description_, by default None

plot_point(ax: Axes = None, color=None)[source]#

Plot the polygon points.

plot_view_up(ax: Axes = None)[source]#

Plot the view and up vector of the polygon.

pts: ndarray#
property size: ndarray#

Return the size in (lxmxn) of the polygon.

to_dict()[source]#

Convert this object to dictionary. Used for read write.

up_vector: ndarray#