4.2. tools#
- lmd.tools.ellipse(major_axis, minor_axis, offset=(0, 0), rotation=0, polygon_resolution=1)#
Get a lmd.lib.Shape for ellipse of choosen dimensions.
- Parameters:
major_axis (float) – Major axis of the ellipse. The major axis is defined from the center to the perimeter and therefore half the diameter. The major axis is placed along the x-axis before rotation.
minor_axis (float) – Minor axis of the ellipse. The minor axis is defined from the center to the perimeter and therefore half the diameter. The minor axis is placed along the y-axis before rotation.
offset (np.ndarray) – Location of the ellipse based on the center given in the form of (x, y). Default value: np.array((0, 0))
rotation (float) – Clockwise rotation in radian.
polygon_resolution (float) – The polygon resolution defines how far the vertices should be spaced on average. A polygon_resolution of 10 will place a vertex on average every ten units.
- Returns:
Shape which contains the ellipse.
- Return type:
Example
import numpy as np from lmd.lib import Collection, Shape from lmd import tools calibration = np.array([[0, 0], [0, 100], [50, 50]]) my_first_collection = Collection(calibration_points = calibration) my_ellipse = tools.ellipse(20, 10, offset = (30, 50), polygon_resolution = 5, rotation = 1.8*np.pi) my_first_collection.add_shape(my_ellipse) my_first_collection.plot(calibration = True)
- lmd.tools.glyph(glyph, offset=array([0, 0]), rotation=0, divisor=10, multiplier=1, **kwargs)#
Get an uncalibrated lmd.lib.Collection for a glyph of interest.
- Parameters:
glyph (str) – Single glyph as string.
divisor (int) – Parameter which determines the resolution when creating a polygon from a SVG. A larger divisor will lead to fewer datapoints for the glyph. Default value: 10
offset (np.ndarray) – Location of the glyph based on the top left corner. Default value: np.array((0, 0))
multiplier (float) – Scaling parameter for defining the size of the glyph. The default height of a glyph is 10 units. Default value: 1
- Returns:
Uncalibrated Collection which contains the Shapes for the glyph.
- Return type:
- lmd.tools.glyph_path(glyph)#
Returns the path for a glyph of interest. Raises a NotImplementedError if an unknown glyph is requested.
- Parameters:
glyph (str) – Single glyph as string.
- Returns:
Path for the glyph.
- Return type:
str
- lmd.tools.makeCross(center, arms, width, dist)#
Generate lmd.lib.Shapes to represent a crosshair and add them to an exisiting lmd.lib.Collection.
- Parameters:
center (numpy.array) – center of the new crosshair
arms (numpy.array) – length of the individual arms [top, right, bottom, left]
width (float) – width of each individual element of the crosshair
dist (float) – distance between the center of the cross hair and each arm
- Returns:
Uncalibrated Collection which contains the Shapes for the calibration cross.
- Return type:
Example
import numpy as np from lmd.lib import Collection, Shape from lmd import tools calibration = np.array([[0, 0], [0, 100], [50, 50]]) my_first_collection = Collection(calibration_points = calibration) cross_1 = tools.makeCross([20, 20], [50,50,50,50], 1, 10) my_first_collection.join(cross_1) my_first_collection.plot(calibration = True)
- lmd.tools.rectangle(width, height, offset=(0, 0), rotation=0, rotation_offset=(0, 0))#
Get a lmd.lib.Shape for rectangle of choosen dimensions.
- Parameters:
width (float) – Width of the rectangle.
offset (np.ndarray) – Location of the rectangle based on the center. Default value: np.array((0, 0))
rotation (float) – Rotation in radian.
rotation_offset (np.ndarray) – Location of the center of rotation relative to the center of the rectangle. Default value: np.array((0, 0))
- Returns:
Shape which contains the rectangle.
- Return type:
Example:
- lmd.tools.text(text, offset=array([0, 0]), divisor=1, multiplier=1, rotation=0, **kwargs)#
Get an uncalibrated lmd.lib.Collection for a text.
- Parameters:
text (str) – Text as string.
divisor (int) – Parameter which determines the resolution when creating a polygon from a SVG. A larger divisor will lead to fewer datapoints for the glyph. Default value: 10
offset (np.ndarray) – Location of the text based on the top left corner. Default value: np.array((0, 0))
multiplier (float) – Scaling parameter for defining the size of the text. The default height of a glyph is 10 units. Default value: 1
- Returns:
Uncalibrated Collection which contains the Shapes for the text.
- Return type:
Example
import numpy as np from lmd.lib import Collection, Shape from lmd import tools calibration = np.array([[0, 0], [0, 100], [100, 50]]) my_first_collection = Collection(calibration_points = calibration) identifier_1 = tools.text('0456_B2', offset=np.array([30, 40]), rotation = -np.pi/4) my_first_collection.join(identifier_1) my_first_collection.plot(calibration = True)