pylib.geometry2d module

2D geometry objects.

Date

2019-08-28

angle(point1, point2=None)[source]

Angle of point or between two points.

Parameters
  • point1 (tuple) – (first) point

  • point2 (tuple) – second point (default = None)

Returns

angle of point or between two points

Return type

float

cubic(point1, angle1, point2, angle2, samples=10)[source]

Cubic line defined by two end points and the rotation in radians at the points.

Parameters
  • point1 (tuple) – one end point

  • angle1 (int or float) – the slope at the one end point

  • point2 (tuple) – other end point

  • angle2 (int or float) – the slope at the other end point

  • samples (int) – number of sampling points (default = 10)

Returns

([sample_point1_x, sample_point2_x, …], [sample_points1_y, sample_point2_y, …])

Return type

tuple

cubic_deg(point1, angle1, point2, angle2)[source]

Cubic line defined by two end points and the roation in degree at the points.

Parameters
  • point1 (tuple) – one end point

  • angle1 (int or float) – the slope at the one end point

  • point2 (tuple) – other end point

  • angle2 (int or float) – the slope at the other end point

Returns

([sample_point1_x, sample_point2_x, …], [sample_points1_y, sample_point2_y, …])

Return type

tuple

See also

cubic()

cubics(pts, **kwargs)[source]

Cubic lines defined by a list of two end points. The deformation as displacement and rotation (radians) is defined element wise as keyword argument deformation or global node wise as global_deformation. The global coordinate system is xy. x in the right direction and y in the top direction.

Parameters
  • pts – list of points in absolute global coordinate system. If keyword inc is given than the inc decides what the left and the right end point of the line is, otherwise it is assumed that the points build a solid line, that is lines between the given points in given order.

  • **kwargs

    options:

    • deformation – list of deformation element wise. Additional deformation (translation and rotation in radians) at element left and right node.

    • rotation_plane – rotation plane of the element wise deformation defined by a string; either ‘xy’ or ‘xz’ (default = ‘xy’). x in the right direction and y in the top direction or z in the bottom direction.

    • global_deformation – list of deformation global node wise. Additional deformation (horizontal translation, vertical translation and rotation in radians) at node.

    • factor – factor of the derformation (default = 1).

    • inc – the incidence table, a list of 2 element lists. The inc decides what the left and the right end point of the line is.

    • index_offset – starting index of lists (default = 0).

Returns

list of endpoints for each line; [(((point1_x, point1_y) angle1), ((point2_x, point2_y), angle2), (p1, angle1, p2, angle2), …]

Return type

list

distance(point1, point2)[source]

Distance between two points (or length of a straight line).

Parameters
  • point1 (tuple) – first point (first end point of straight line)

  • point2 (tuple) – second point (second end point of straight line)

Returns

distance between the two points

Return type

float

interpolate_hermite(lvd, lr, rvd, rr, lhd=0, rhd=0, scale_x=1, scale_y=1, samples=10)[source]

Interpolate cubic line with hermite boundary conditions.

Parameters
  • lvd (int or float) – left vertcal deflection

  • lr (int or float) – left rotation

  • rvd (int or float) – right vertical deflection

  • rr (int or float) – right rotation

  • lhd (int or float) – left horizontal deformation (default = 0)

  • rhd (int or float) – right horizontal deformation (default = 0)

  • scale_x (int or float) – length of element (default = 1)

  • scale_y (int or float) – factor of the deformation (default = 1). This does not change the length.

  • samples (int) – number of sampling points (default = 10)

\[\begin{split}s = \frac{x - x_1}{L} \\ x = s\,L + x_1\end{split}\]
line(point1, point2, samples=2)[source]

Line defined by two end points.

\[y = \frac{y_2-y_1}{x_2-x_1}(x-x_1) + y_1\]
Parameters
  • point1 (tuple) – one end point

  • point2 (tuple) – other end point

  • samples (int) – number of sampling points (default = 2)

Returns

((point1_x, point2_x), (points1_y, point2_y)) or ([sample_point1_x, sample_point2_x, …], [sample_points1_y, sample_point2_y, …])

Return type

tuple

Example

>>> x, y = line((0, 0), (1, 0))
>>> print(x, y)
((0, 1), (0, 0))
lines(pts, **kwargs)[source]

Lines defined by a list of end points.

Parameters
  • pts (list) – list of points in absolute global coordinate system. If keyword inc is given than the inc decides what the left and the right end point of the line is, otherwise it is assumed that the points build a solid line, that is lines between the given points in given order.

  • **kwargs

    options:

    • deformation – list of points. Additional deformation (translation) at point.

    • factor – factor of the deformation (default = 1).

    • inc – the incidence table, a list of 2 element lists. The inc decides what the left and the right end point of the line is.

    • index_offset – starting index of lists (default = 0).

Returns

list of endpoints for each line; [((point1_x, point1_y), (point2_x, point2_y)), (p1, p2), …]

Return type

list

See also

plot_lines() of the geometry_plot module to plot the lines

rectangle(width, height)[source]
Parameters
  • width (int or float) – the width of the rectangle

  • height (int or float) – the height of the rectangle

Returns

(point1, point2, point3, point4)

Return type

tuple

rotate(origin, angle, *pts, **kwargs)[source]

Rotate a point or polygon counterclockwise by a given angle around a given origin. The angle should be given in radians.

Parameters
  • origin (tuple) – the center of rotation

  • angle (int or float) – the rotation angle

  • *pts – points to rotate

  • **kwargs – options

Returns

(point_x, point_y) or (point1, point2, …)

Return type

tuple

See also

rotate_xy()

rotate_deg(origin, angle, *pts, **kwargs)[source]

Rotate a point or polygon counterclockwise by a given angle around a given origin. The angle should be given in degrees.

Parameters
  • origin (tuple) – the center of rotation

  • angle (int or float) – the rotation angle

  • *pts – points to rotate

  • **kwargs – options

Returns

(point_x, point_y) or (point1, point2, …)

Return type

tuple

See also

rotate()

rotate_xy(origin, angle, x, y, **kwargs)[source]

Rotate x and y coordinates counterclockwise by a given angle around a given origin. The angle should be given in radians.

Parameters
  • origin (tuple) – the center of rotation

  • angle (int or float) – the rotation angle

  • x (int or float or list) – x coordinates

  • y (int or float or list) – y coordinates

  • **kwargs – options

See also

rotate()

square(width)[source]
Parameters

width (int or float) – the edge size of the square

Returns

(point1, point2, point3, point4)

Return type

tuple

See also

rectangle()

translate(vec, *pts)[source]

Translate a point or polygon by a given vector.

Parameters
  • vec (tuple) – translation vector

  • *pts – points to translate

Returns

(point_x, point_y) or (point1, point2, …)

Return type

tuple

See also

translate_xy()

translate_xy(vec, x, y)[source]

Translate a point or polygon by a given vector.

Parameters
  • vec (tuple) – translation vector

  • x (int or float or list) – points to translate

  • y (int or float or list) – points to translate

Returns

(x’, y’)

Return type

tuple

See also

translate()