INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Evaluates the curve binormal vectors at the given list of parameter values.
:param obj: input curve
:type obj: abstract.Curve
:param param_list: parameter list
:type param_list: list or tuple
:param normalize: if True, the returned vector is converted to a unit vector
:type normalize: bool
... | def binormal_curve_single_list(obj, param_list, normalize):
""" Evaluates the curve binormal vectors at the given list of parameter values.
:param obj: input curve
:type obj: abstract.Curve
:param param_list: parameter list
:type param_list: list or tuple
:param normalize: if True, the returned... |
Evaluates the surface tangent vector at the given (u,v) parameter pair.
The output returns a list containing the starting point (i.e., origin) of the vector and the vectors themselves.
:param obj: input surface
:type obj: abstract.Surface
:param uv: (u,v) parameter pair
:type uv: list or tuple
... | def tangent_surface_single(obj, uv, normalize):
""" Evaluates the surface tangent vector at the given (u,v) parameter pair.
The output returns a list containing the starting point (i.e., origin) of the vector and the vectors themselves.
:param obj: input surface
:type obj: abstract.Surface
:param ... |
Evaluates the surface tangent vectors at the given list of parameter values.
:param obj: input surface
:type obj: abstract.Surface
:param param_list: parameter list
:type param_list: list or tuple
:param normalize: if True, the returned vector is converted to a unit vector
:type normalize: bool... | def tangent_surface_single_list(obj, param_list, normalize):
""" Evaluates the surface tangent vectors at the given list of parameter values.
:param obj: input surface
:type obj: abstract.Surface
:param param_list: parameter list
:type param_list: list or tuple
:param normalize: if True, the re... |
Evaluates the surface normal vector at the given (u, v) parameter pair.
The output returns a list containing the starting point (i.e. origin) of the vector and the vector itself.
:param obj: input surface
:type obj: abstract.Surface
:param uv: (u,v) parameter pair
:type uv: list or tuple
:para... | def normal_surface_single(obj, uv, normalize):
""" Evaluates the surface normal vector at the given (u, v) parameter pair.
The output returns a list containing the starting point (i.e. origin) of the vector and the vector itself.
:param obj: input surface
:type obj: abstract.Surface
:param uv: (u,... |
Evaluates the surface normal vectors at the given list of parameter values.
:param obj: input surface
:type obj: abstract.Surface
:param param_list: parameter list
:type param_list: list or tuple
:param normalize: if True, the returned vector is converted to a unit vector
:type normalize: bool
... | def normal_surface_single_list(obj, param_list, normalize):
""" Evaluates the surface normal vectors at the given list of parameter values.
:param obj: input surface
:type obj: abstract.Surface
:param param_list: parameter list
:type param_list: list or tuple
:param normalize: if True, the retu... |
Finds the control points involved in the evaluation of the curve point defined by the input parameter.
This function uses a modified version of the algorithm *A3.1 CurvePoint* from The NURBS Book by Piegl & Tiller.
:param t: parameter
:type t: float
:param curve: input curve object
:type curve: ab... | def find_ctrlpts_curve(t, curve, **kwargs):
""" Finds the control points involved in the evaluation of the curve point defined by the input parameter.
This function uses a modified version of the algorithm *A3.1 CurvePoint* from The NURBS Book by Piegl & Tiller.
:param t: parameter
:type t: float
... |
Finds the control points involved in the evaluation of the surface point defined by the input parameter pair.
This function uses a modified version of the algorithm *A3.5 SurfacePoint* from The NURBS Book by Piegl & Tiller.
:param t_u: parameter on the u-direction
:type t_u: float
:param t_v: paramete... | def find_ctrlpts_surface(t_u, t_v, surf, **kwargs):
""" Finds the control points involved in the evaluation of the surface point defined by the input parameter pair.
This function uses a modified version of the algorithm *A3.5 SurfacePoint* from The NURBS Book by Piegl & Tiller.
:param t_u: parameter on t... |
Links the input curves together.
The end control point of the curve k has to be the same with the start control point of the curve k + 1.
Keyword Arguments:
* ``tol``: tolerance value for checking equality. *Default: 10e-8*
* ``validate``: flag to enable input validation. *Default: False*
... | def link_curves(*args, **kwargs):
""" Links the input curves together.
The end control point of the curve k has to be the same with the start control point of the curve k + 1.
Keyword Arguments:
* ``tol``: tolerance value for checking equality. *Default: 10e-8*
* ``validate``: flag to enab... |
Inserts knots n-times to a spline geometry.
The following code snippet illustrates the usage of this function:
.. code-block:: python
# Insert knot u=0.5 to a curve 2 times
operations.insert_knot(curve, [0.5], [2])
# Insert knot v=0.25 to a surface 1 time
operations.insert_kn... | def insert_knot(obj, param, num, **kwargs):
""" Inserts knots n-times to a spline geometry.
The following code snippet illustrates the usage of this function:
.. code-block:: python
# Insert knot u=0.5 to a curve 2 times
operations.insert_knot(curve, [0.5], [2])
# Insert knot v=0... |
Refines the knot vector(s) of a spline geometry.
The following code snippet illustrates the usage of this function:
.. code-block:: python
# Refines the knot vector of a curve
operations.refine_knotvector(curve, [1])
# Refines the knot vector on the v-direction of a surface
o... | def refine_knotvector(obj, param, **kwargs):
""" Refines the knot vector(s) of a spline geometry.
The following code snippet illustrates the usage of this function:
.. code-block:: python
# Refines the knot vector of a curve
operations.refine_knotvector(curve, [1])
# Refines the ... |
Applies degree elevation and degree reduction algorithms to spline geometries.
:param obj: spline geometry
:type obj: abstract.SplineGeometry
:param param: operation definition
:type param: list, tuple
:return: updated spline geometry | def degree_operations(obj, param, **kwargs):
""" Applies degree elevation and degree reduction algorithms to spline geometries.
:param obj: spline geometry
:type obj: abstract.SplineGeometry
:param param: operation definition
:type param: list, tuple
:return: updated spline geometry
"""
... |
Elevates the spatial dimension of the spline geometry.
If you pass ``inplace=True`` keyword argument, the input will be updated. Otherwise, this function does not
change the input but returns a new instance with the updated data.
:param obj: spline geometry
:type obj: abstract.SplineGeometry
:retu... | def add_dimension(obj, **kwargs):
""" Elevates the spatial dimension of the spline geometry.
If you pass ``inplace=True`` keyword argument, the input will be updated. Otherwise, this function does not
change the input but returns a new instance with the updated data.
:param obj: spline geometry
:t... |
Splits the curve at the input parametric coordinate.
This method splits the curve into two pieces at the given parametric coordinate, generates two different
curve objects and returns them. It does not modify the input curve.
Keyword Arguments:
* ``find_span_func``: FindSpan implementation. *Defau... | def split_curve(obj, param, **kwargs):
""" Splits the curve at the input parametric coordinate.
This method splits the curve into two pieces at the given parametric coordinate, generates two different
curve objects and returns them. It does not modify the input curve.
Keyword Arguments:
* ``fi... |
Decomposes the curve into Bezier curve segments of the same degree.
This operation does not modify the input curve, instead it returns the split curve segments.
Keyword Arguments:
* ``find_span_func``: FindSpan implementation. *Default:* :func:`.helpers.find_span_linear`
* ``insert_knot_func``... | def decompose_curve(obj, **kwargs):
""" Decomposes the curve into Bezier curve segments of the same degree.
This operation does not modify the input curve, instead it returns the split curve segments.
Keyword Arguments:
* ``find_span_func``: FindSpan implementation. *Default:* :func:`.helpers.find... |
Computes the hodograph (first derivative) curve of the input curve.
This function constructs the hodograph (first derivative) curve from the input curve by computing the degrees,
knot vectors and the control points of the derivative curve.
:param obj: input curve
:type obj: abstract.Curve
:return:... | def derivative_curve(obj):
""" Computes the hodograph (first derivative) curve of the input curve.
This function constructs the hodograph (first derivative) curve from the input curve by computing the degrees,
knot vectors and the control points of the derivative curve.
:param obj: input curve
:ty... |
Computes the approximate length of the parametric curve.
Uses the following equation to compute the approximate length:
.. math::
\\sum_{i=0}^{n-1} \\sqrt{P_{i + 1}^2-P_{i}^2}
where :math:`n` is number of evaluated curve points and :math:`P` is the n-dimensional point.
:param obj: input cur... | def length_curve(obj):
""" Computes the approximate length of the parametric curve.
Uses the following equation to compute the approximate length:
.. math::
\\sum_{i=0}^{n-1} \\sqrt{P_{i + 1}^2-P_{i}^2}
where :math:`n` is number of evaluated curve points and :math:`P` is the n-dimensional po... |
Splits the surface at the input parametric coordinate on the u-direction.
This method splits the surface into two pieces at the given parametric coordinate on the u-direction,
generates two different surface objects and returns them. It does not modify the input surface.
Keyword Arguments:
* ``fin... | def split_surface_u(obj, param, **kwargs):
""" Splits the surface at the input parametric coordinate on the u-direction.
This method splits the surface into two pieces at the given parametric coordinate on the u-direction,
generates two different surface objects and returns them. It does not modify the inp... |
Decomposes the surface into Bezier surface patches of the same degree.
This operation does not modify the input surface, instead it returns the surface patches.
Keyword Arguments:
* ``find_span_func``: FindSpan implementation. *Default:* :func:`.helpers.find_span_linear`
* ``insert_knot_func``... | def decompose_surface(obj, **kwargs):
""" Decomposes the surface into Bezier surface patches of the same degree.
This operation does not modify the input surface, instead it returns the surface patches.
Keyword Arguments:
* ``find_span_func``: FindSpan implementation. *Default:* :func:`.helpers.fi... |
Computes the hodograph (first derivative) surface of the input surface.
This function constructs the hodograph (first derivative) surface from the input surface by computing the degrees,
knot vectors and the control points of the derivative surface.
The return value of this function is a tuple containing ... | def derivative_surface(obj):
""" Computes the hodograph (first derivative) surface of the input surface.
This function constructs the hodograph (first derivative) surface from the input surface by computing the degrees,
knot vectors and the control points of the derivative surface.
The return value of... |
Finds the control points involved in the evaluation of the curve/surface point defined by the input parameter(s).
:param obj: curve or surface
:type obj: abstract.Curve or abstract.Surface
:param u: parameter (for curve), parameter on the u-direction (for surface)
:type u: float
:param v: parameter... | def find_ctrlpts(obj, u, v=None, **kwargs):
""" Finds the control points involved in the evaluation of the curve/surface point defined by the input parameter(s).
:param obj: curve or surface
:type obj: abstract.Curve or abstract.Surface
:param u: parameter (for curve), parameter on the u-direction (for... |
Evaluates the tangent vector of the curves or surfaces at the input parameter values.
This function is designed to evaluate tangent vectors of the B-Spline and NURBS shapes at single or
multiple parameter positions.
:param obj: input shape
:type obj: abstract.Curve or abstract.Surface
:param param... | def tangent(obj, params, **kwargs):
""" Evaluates the tangent vector of the curves or surfaces at the input parameter values.
This function is designed to evaluate tangent vectors of the B-Spline and NURBS shapes at single or
multiple parameter positions.
:param obj: input shape
:type obj: abstrac... |
Evaluates the normal vector of the curves or surfaces at the input parameter values.
This function is designed to evaluate normal vectors of the B-Spline and NURBS shapes at single or
multiple parameter positions.
:param obj: input geometry
:type obj: abstract.Curve or abstract.Surface
:param para... | def normal(obj, params, **kwargs):
""" Evaluates the normal vector of the curves or surfaces at the input parameter values.
This function is designed to evaluate normal vectors of the B-Spline and NURBS shapes at single or
multiple parameter positions.
:param obj: input geometry
:type obj: abstrac... |
Evaluates the binormal vector of the curves or surfaces at the input parameter values.
This function is designed to evaluate binormal vectors of the B-Spline and NURBS shapes at single or
multiple parameter positions.
:param obj: input shape
:type obj: abstract.Curve or abstract.Surface
:param par... | def binormal(obj, params, **kwargs):
""" Evaluates the binormal vector of the curves or surfaces at the input parameter values.
This function is designed to evaluate binormal vectors of the B-Spline and NURBS shapes at single or
multiple parameter positions.
:param obj: input shape
:type obj: abst... |
Translates curves, surface or volumes by the input vector.
Keyword Arguments:
* ``inplace``: if False, operation applied to a copy of the object. *Default: False*
:param obj: input geometry
:type obj: abstract.SplineGeometry or multi.AbstractContainer
:param vec: translation vector
:type v... | def translate(obj, vec, **kwargs):
""" Translates curves, surface or volumes by the input vector.
Keyword Arguments:
* ``inplace``: if False, operation applied to a copy of the object. *Default: False*
:param obj: input geometry
:type obj: abstract.SplineGeometry or multi.AbstractContainer
... |
Rotates curves, surfaces or volumes about the chosen axis.
Keyword Arguments:
* ``axis``: rotation axis; x, y, z correspond to 0, 1, 2 respectively. *Default: 2*
* ``inplace``: if False, operation applied to a copy of the object. *Default: False*
:param obj: input geometry
:type obj: abstr... | def rotate(obj, angle, **kwargs):
""" Rotates curves, surfaces or volumes about the chosen axis.
Keyword Arguments:
* ``axis``: rotation axis; x, y, z correspond to 0, 1, 2 respectively. *Default: 2*
* ``inplace``: if False, operation applied to a copy of the object. *Default: False*
:para... |
Scales curves, surfaces or volumes by the input multiplier.
Keyword Arguments:
* ``inplace``: if False, operation applied to a copy of the object. *Default: False*
:param obj: input geometry
:type obj: abstract.SplineGeometry, multi.AbstractGeometry
:param multiplier: scaling multiplier
:t... | def scale(obj, multiplier, **kwargs):
""" Scales curves, surfaces or volumes by the input multiplier.
Keyword Arguments:
* ``inplace``: if False, operation applied to a copy of the object. *Default: False*
:param obj: input geometry
:type obj: abstract.SplineGeometry, multi.AbstractGeometry
... |
Transposes the input surface(s) by swapping u and v parametric directions.
Keyword Arguments:
* ``inplace``: if False, operation applied to a copy of the object. *Default: False*
:param surf: input surface(s)
:type surf: abstract.Surface, multi.SurfaceContainer
:return: transposed surface(s) | def transpose(surf, **kwargs):
""" Transposes the input surface(s) by swapping u and v parametric directions.
Keyword Arguments:
* ``inplace``: if False, operation applied to a copy of the object. *Default: False*
:param surf: input surface(s)
:type surf: abstract.Surface, multi.SurfaceContain... |
Generates binary voxel representation of the surfaces and volumes.
Keyword Arguments:
* ``grid_size``: size of the voxel grid. *Default: (8, 8, 8)*
* ``padding``: voxel padding for in-outs finding. *Default: 10e-8*
* ``use_cubes``: use cube voxels instead of cuboid ones. *Default: False*
... | def voxelize(obj, **kwargs):
""" Generates binary voxel representation of the surfaces and volumes.
Keyword Arguments:
* ``grid_size``: size of the voxel grid. *Default: (8, 8, 8)*
* ``padding``: voxel padding for in-outs finding. *Default: 10e-8*
* ``use_cubes``: use cube voxels instea... |
Saves binary voxel grid as a binary file.
The binary file is structured in little-endian unsigned int format.
:param voxel_grid: binary voxel grid
:type voxel_grid: list, tuple
:param file_name: file name to save
:type file_name: str | def save_voxel_grid(voxel_grid, file_name):
""" Saves binary voxel grid as a binary file.
The binary file is structured in little-endian unsigned int format.
:param voxel_grid: binary voxel grid
:type voxel_grid: list, tuple
:param file_name: file name to save
:type file_name: str
"""
... |
Computes the cross-product of the input vectors.
:param vector1: input vector 1
:type vector1: list, tuple
:param vector2: input vector 2
:type vector2: list, tuple
:return: result of the cross product
:rtype: tuple | def vector_cross(vector1, vector2):
""" Computes the cross-product of the input vectors.
:param vector1: input vector 1
:type vector1: list, tuple
:param vector2: input vector 2
:type vector2: list, tuple
:return: result of the cross product
:rtype: tuple
"""
try:
if vector1... |
Computes the dot-product of the input vectors.
:param vector1: input vector 1
:type vector1: list, tuple
:param vector2: input vector 2
:type vector2: list, tuple
:return: result of the dot product
:rtype: float | def vector_dot(vector1, vector2):
""" Computes the dot-product of the input vectors.
:param vector1: input vector 1
:type vector1: list, tuple
:param vector2: input vector 2
:type vector2: list, tuple
:return: result of the dot product
:rtype: float
"""
try:
if vector1 is No... |
Sums the vectors.
This function computes the result of the vector operation :math:`\\overline{v}_{1} + c * \\overline{v}_{2}`, where
:math:`\\overline{v}_{1}` is ``vector1``, :math:`\\overline{v}_{2}` is ``vector2`` and :math:`c` is ``coeff``.
:param vector1: vector 1
:type vector1: list, tuple
:... | def vector_sum(vector1, vector2, coeff=1.0):
""" Sums the vectors.
This function computes the result of the vector operation :math:`\\overline{v}_{1} + c * \\overline{v}_{2}`, where
:math:`\\overline{v}_{1}` is ``vector1``, :math:`\\overline{v}_{2}` is ``vector2`` and :math:`c` is ``coeff``.
:param v... |
Generates a unit vector from the input.
:param vector_in: vector to be normalized
:type vector_in: list, tuple
:param decimals: number of significands
:type decimals: int
:return: the normalized vector (i.e. the unit vector)
:rtype: list | def vector_normalize(vector_in, decimals=18):
""" Generates a unit vector from the input.
:param vector_in: vector to be normalized
:type vector_in: list, tuple
:param decimals: number of significands
:type decimals: int
:return: the normalized vector (i.e. the unit vector)
:rtype: list
... |
Generates a vector from 2 input points.
:param start_pt: start point of the vector
:type start_pt: list, tuple
:param end_pt: end point of the vector
:type end_pt: list, tuple
:param normalize: if True, the generated vector is normalized
:type normalize: bool
:return: a vector from start_pt... | def vector_generate(start_pt, end_pt, normalize=False):
""" Generates a vector from 2 input points.
:param start_pt: start point of the vector
:type start_pt: list, tuple
:param end_pt: end point of the vector
:type end_pt: list, tuple
:param normalize: if True, the generated vector is normaliz... |
Computes the mean (average) of a list of vectors.
The function computes the arithmetic mean of a list of vectors, which are also organized as a list of
integers or floating point numbers.
.. code-block:: python
:linenos:
# Import geomdl.utilities module
from geomdl import utilitie... | def vector_mean(*args):
""" Computes the mean (average) of a list of vectors.
The function computes the arithmetic mean of a list of vectors, which are also organized as a list of
integers or floating point numbers.
.. code-block:: python
:linenos:
# Import geomdl.utilities module
... |
Computes the magnitude of the input vector.
:param vector_in: input vector
:type vector_in: list, tuple
:return: magnitude of the vector
:rtype: float | def vector_magnitude(vector_in):
""" Computes the magnitude of the input vector.
:param vector_in: input vector
:type vector_in: list, tuple
:return: magnitude of the vector
:rtype: float
"""
sq_sum = 0.0
for vin in vector_in:
sq_sum += vin**2
return math.sqrt(sq_sum) |
Computes the angle between the two input vectors.
If the keyword argument ``degrees`` is set to *True*, then the angle will be in degrees. Otherwise, it will be
in radians. By default, ``degrees`` is set to *True*.
:param vector1: vector
:type vector1: list, tuple
:param vector2: vector
:type ... | def vector_angle_between(vector1, vector2, **kwargs):
""" Computes the angle between the two input vectors.
If the keyword argument ``degrees`` is set to *True*, then the angle will be in degrees. Otherwise, it will be
in radians. By default, ``degrees`` is set to *True*.
:param vector1: vector
:t... |
Checks if the input vector is a zero vector.
:param vector_in: input vector
:type vector_in: list, tuple
:param tol: tolerance value
:type tol: float
:return: True if the input vector is zero, False otherwise
:rtype: bool | def vector_is_zero(vector_in, tol=10e-8):
""" Checks if the input vector is a zero vector.
:param vector_in: input vector
:type vector_in: list, tuple
:param tol: tolerance value
:type tol: float
:return: True if the input vector is zero, False otherwise
:rtype: bool
"""
if not isin... |
Translates the input points using the input vector.
:param point_in: input point
:type point_in: list, tuple
:param vector_in: input vector
:type vector_in: list, tuple
:return: translated point
:rtype: list | def point_translate(point_in, vector_in):
""" Translates the input points using the input vector.
:param point_in: input point
:type point_in: list, tuple
:param vector_in: input vector
:type vector_in: list, tuple
:return: translated point
:rtype: list
"""
try:
if point_in ... |
Computes distance between two points.
:param pt1: point 1
:type pt1: list, tuple
:param pt2: point 2
:type pt2: list, tuple
:return: distance between input points
:rtype: float | def point_distance(pt1, pt2):
""" Computes distance between two points.
:param pt1: point 1
:type pt1: list, tuple
:param pt2: point 2
:type pt2: list, tuple
:return: distance between input points
:rtype: float
"""
if len(pt1) != len(pt2):
raise ValueError("The input points ... |
Computes the midpoint of the input points.
:param pt1: point 1
:type pt1: list, tuple
:param pt2: point 2
:type pt2: list, tuple
:return: midpoint
:rtype: list | def point_mid(pt1, pt2):
""" Computes the midpoint of the input points.
:param pt1: point 1
:type pt1: list, tuple
:param pt2: point 2
:type pt2: list, tuple
:return: midpoint
:rtype: list
"""
if len(pt1) != len(pt2):
raise ValueError("The input points should have the same d... |
Matrix multiplication (iterative algorithm).
The running time of the iterative matrix multiplication algorithm is :math:`O(n^{3})`.
:param m1: 1st matrix with dimensions :math:`(n \\times p)`
:type m1: list, tuple
:param m2: 2nd matrix with dimensions :math:`(p \\times m)`
:type m2: list, tuple
... | def matrix_multiply(m1, m2):
""" Matrix multiplication (iterative algorithm).
The running time of the iterative matrix multiplication algorithm is :math:`O(n^{3})`.
:param m1: 1st matrix with dimensions :math:`(n \\times p)`
:type m1: list, tuple
:param m2: 2nd matrix with dimensions :math:`(p \\t... |
Transposes the input matrix.
The input matrix :math:`m` is a 2-dimensional array.
:param m: input matrix with dimensions :math:`(n \\times m)`
:type m: list, tuple
:return: transpose matrix with dimensions :math:`(m \\times n)`
:rtype: list | def matrix_transpose(m):
""" Transposes the input matrix.
The input matrix :math:`m` is a 2-dimensional array.
:param m: input matrix with dimensions :math:`(n \\times m)`
:type m: list, tuple
:return: transpose matrix with dimensions :math:`(m \\times n)`
:rtype: list
"""
num_cols = l... |
Computes the (approximate) normal vector of the input triangle.
:param tri: triangle object
:type tri: elements.Triangle
:return: normal vector of the triangle
:rtype: tuple | def triangle_normal(tri):
""" Computes the (approximate) normal vector of the input triangle.
:param tri: triangle object
:type tri: elements.Triangle
:return: normal vector of the triangle
:rtype: tuple
"""
vec1 = vector_generate(tri.vertices[0].data, tri.vertices[1].data)
vec2 = vecto... |
Computes the center of mass of the input triangle.
:param tri: triangle object
:type tri: elements.Triangle
:param uv: if True, then finds parametric position of the center of mass
:type uv: bool
:return: center of mass of the triangle
:rtype: tuple | def triangle_center(tri, uv=False):
""" Computes the center of mass of the input triangle.
:param tri: triangle object
:type tri: elements.Triangle
:param uv: if True, then finds parametric position of the center of mass
:type uv: bool
:return: center of mass of the triangle
:rtype: tuple
... |
Computes the binomial coefficient (denoted by *k choose i*).
Please see the following website for details: http://mathworld.wolfram.com/BinomialCoefficient.html
:param k: size of the set of distinct elements
:type k: int
:param i: size of the subsets
:type i: int
:return: combination of *k* an... | def binomial_coefficient(k, i):
""" Computes the binomial coefficient (denoted by *k choose i*).
Please see the following website for details: http://mathworld.wolfram.com/BinomialCoefficient.html
:param k: size of the set of distinct elements
:type k: int
:param i: size of the subsets
:type i... |
LU-Factorization method using Doolittle's Method for solution of linear systems.
Decomposes the matrix :math:`A` such that :math:`A = LU`.
The input matrix is represented by a list or a tuple. The input matrix is **2-dimensional**, i.e. list of lists of
integers and/or floats.
:param matrix_a: Input ... | def lu_decomposition(matrix_a):
""" LU-Factorization method using Doolittle's Method for solution of linear systems.
Decomposes the matrix :math:`A` such that :math:`A = LU`.
The input matrix is represented by a list or a tuple. The input matrix is **2-dimensional**, i.e. list of lists of
integers and... |
Forward substitution method for the solution of linear systems.
Solves the equation :math:`Ly = b` using forward substitution method
where :math:`L` is a lower triangular matrix and :math:`b` is a column matrix.
:param matrix_l: L, lower triangular matrix
:type matrix_l: list, tuple
:param matrix_... | def forward_substitution(matrix_l, matrix_b):
""" Forward substitution method for the solution of linear systems.
Solves the equation :math:`Ly = b` using forward substitution method
where :math:`L` is a lower triangular matrix and :math:`b` is a column matrix.
:param matrix_l: L, lower triangular mat... |
Backward substitution method for the solution of linear systems.
Solves the equation :math:`Ux = y` using backward substitution method
where :math:`U` is a upper triangular matrix and :math:`y` is a column matrix.
:param matrix_u: U, upper triangular matrix
:type matrix_u: list, tuple
:param matri... | def backward_substitution(matrix_u, matrix_y):
""" Backward substitution method for the solution of linear systems.
Solves the equation :math:`Ux = y` using backward substitution method
where :math:`U` is a upper triangular matrix and :math:`y` is a column matrix.
:param matrix_u: U, upper triangular ... |
Returns a list of evenly spaced numbers over a specified interval.
Inspired from Numpy's linspace function: https://github.com/numpy/numpy/blob/master/numpy/core/function_base.py
:param start: starting value
:type start: float
:param stop: end value
:type stop: float
:param num: number of samp... | def linspace(start, stop, num, decimals=18):
""" Returns a list of evenly spaced numbers over a specified interval.
Inspired from Numpy's linspace function: https://github.com/numpy/numpy/blob/master/numpy/core/function_base.py
:param start: starting value
:type start: float
:param stop: end value... |
Implementation of Python's ``range()`` function which works with floats.
Reference to this implementation: https://stackoverflow.com/a/36091634
:param start: start value
:type start: float
:param stop: end value
:type stop: float
:param step: increment
:type step: float
:return: float
... | def frange(start, stop, step=1.0):
""" Implementation of Python's ``range()`` function which works with floats.
Reference to this implementation: https://stackoverflow.com/a/36091634
:param start: start value
:type start: float
:param stop: end value
:type stop: float
:param step: incremen... |
Returns points on convex hull in counterclockwise order according to Graham's scan algorithm.
Reference: https://gist.github.com/arthur-e/5cf52962341310f438e96c1f3c3398b8
.. note:: This implementation only works in 2-dimensional space.
:param points: list of 2-dimensional points
:type points: list, t... | def convex_hull(points):
""" Returns points on convex hull in counterclockwise order according to Graham's scan algorithm.
Reference: https://gist.github.com/arthur-e/5cf52962341310f438e96c1f3c3398b8
.. note:: This implementation only works in 2-dimensional space.
:param points: list of 2-dimensional... |
Tests if a point is Left|On|Right of an infinite line.
Ported from the C++ version: on http://geomalgorithms.com/a03-_inclusion.html
.. note:: This implementation only works in 2-dimensional space.
:param point0: Point P0
:param point1: Point P1
:param point2: Point P2
:return:
>0 for... | def is_left(point0, point1, point2):
""" Tests if a point is Left|On|Right of an infinite line.
Ported from the C++ version: on http://geomalgorithms.com/a03-_inclusion.html
.. note:: This implementation only works in 2-dimensional space.
:param point0: Point P0
:param point1: Point P1
:param... |
Winding number test for a point in a polygon.
Ported from the C++ version: http://geomalgorithms.com/a03-_inclusion.html
.. note:: This implementation only works in 2-dimensional space.
:param point: point to be tested
:type point: list, tuple
:param vertices: vertex points of a polygon vertices[... | def wn_poly(point, vertices):
""" Winding number test for a point in a polygon.
Ported from the C++ version: http://geomalgorithms.com/a03-_inclusion.html
.. note:: This implementation only works in 2-dimensional space.
:param point: point to be tested
:type point: list, tuple
:param vertices... |
Generates surfaces from curves.
Arguments:
* ``args``: a list of curve instances
Keyword Arguments (optional):
* ``degree``: degree of the 2nd parametric direction
* ``knotvector``: knot vector of the 2nd parametric direction
* ``rational``: flag to generate rational surfaces
... | def construct_surface(direction, *args, **kwargs):
""" Generates surfaces from curves.
Arguments:
* ``args``: a list of curve instances
Keyword Arguments (optional):
* ``degree``: degree of the 2nd parametric direction
* ``knotvector``: knot vector of the 2nd parametric direction
... |
Generates volumes from surfaces.
Arguments:
* ``args``: a list of surface instances
Keyword Arguments (optional):
* ``degree``: degree of the 3rd parametric direction
* ``knotvector``: knot vector of the 3rd parametric direction
* ``rational``: flag to generate rational volumes... | def construct_volume(direction, *args, **kwargs):
""" Generates volumes from surfaces.
Arguments:
* ``args``: a list of surface instances
Keyword Arguments (optional):
* ``degree``: degree of the 3rd parametric direction
* ``knotvector``: knot vector of the 3rd parametric direction... |
Extracts curves from a surface.
The return value is a ``dict`` object containing the following keys:
* ``u``: the curves which generate u-direction (or which lie on the v-direction)
* ``v``: the curves which generate v-direction (or which lie on the u-direction)
As an example; if a curve lies on the ... | def extract_curves(psurf, **kwargs):
""" Extracts curves from a surface.
The return value is a ``dict`` object containing the following keys:
* ``u``: the curves which generate u-direction (or which lie on the v-direction)
* ``v``: the curves which generate v-direction (or which lie on the u-direction... |
Extracts surfaces from a volume.
:param pvol: input volume
:type pvol: abstract.Volume
:return: extracted surface
:rtype: dict | def extract_surfaces(pvol):
""" Extracts surfaces from a volume.
:param pvol: input volume
:type pvol: abstract.Volume
:return: extracted surface
:rtype: dict
"""
if pvol.pdimension != 3:
raise GeomdlException("The input should be a spline volume")
if len(pvol) != 1:
rai... |
Extracts the largest isosurface from a volume.
The following example illustrates one of the usage scenarios:
.. code-block:: python
:linenos:
from geomdl import construct, multi
from geomdl.visualization import VisMPL
# Assuming that "myvol" variable stores your spline volume... | def extract_isosurface(pvol):
""" Extracts the largest isosurface from a volume.
The following example illustrates one of the usage scenarios:
.. code-block:: python
:linenos:
from geomdl import construct, multi
from geomdl.visualization import VisMPL
# Assuming that "myv... |
Fixes direction, connectivity and similar issues of the trim curves.
This function works for surface trims in curve containers, i.e. trims consisting of multiple curves.
Keyword Arguments:
* ``tol``: tolerance value for comparing floats. *Default: 10e-8*
* ``delta``: evaluation delta of the tr... | def fix_multi_trim_curves(obj, **kwargs):
""" Fixes direction, connectivity and similar issues of the trim curves.
This function works for surface trims in curve containers, i.e. trims consisting of multiple curves.
Keyword Arguments:
* ``tol``: tolerance value for comparing floats. *Default: 10e-... |
Fixes direction, connectivity and similar issues of the trim curves.
This function works for surface trim curves consisting of a single curve.
:param obj: input surface
:type obj: abstract.Surface | def fix_trim_curves(obj):
""" Fixes direction, connectivity and similar issues of the trim curves.
This function works for surface trim curves consisting of a single curve.
:param obj: input surface
:type obj: abstract.Surface
"""
# Validate input
if obj.pdimension != 2:
raise Geom... |
Checks if the trim curve was closed and sense was set.
:param curve: trim curve
:param parbox: parameter space bounding box of the underlying surface
:return: a tuple containing the status of the operation and list of extra trim curves generated
:rtype: tuple | def check_trim_curve(curve, parbox, **kwargs):
""" Checks if the trim curve was closed and sense was set.
:param curve: trim curve
:param parbox: parameter space bounding box of the underlying surface
:return: a tuple containing the status of the operation and list of extra trim curves generated
:r... |
Returns the bounding box of the surface parametric domain in ccw direction.
:param domain: parametric domain
:type domain: list, tuple
:param last: if True, adds the first vertex to the end of the return list
:type last: bool
:return: edges of the parametric domain
:rtype: tuple | def get_par_box(domain, last=False):
""" Returns the bounding box of the surface parametric domain in ccw direction.
:param domain: parametric domain
:type domain: list, tuple
:param last: if True, adds the first vertex to the end of the return list
:type last: bool
:return: edges of the parame... |
Detects the sense, i.e. clockwise or counter-clockwise, of the curve.
:param curve: 2-dimensional trim curve
:type curve: abstract.Curve
:param tol: tolerance value
:type tol: float
:return: True if detection is successful, False otherwise
:rtype: bool | def detect_sense(curve, tol):
""" Detects the sense, i.e. clockwise or counter-clockwise, of the curve.
:param curve: 2-dimensional trim curve
:type curve: abstract.Curve
:param tol: tolerance value
:type tol: float
:return: True if detection is successful, False otherwise
:rtype: bool
... |
Finds intersection of 2 rays.
This functions finds the parameter values for the 1st and 2nd input rays and returns a tuple of
``(parameter for ray1, parameter for ray2, intersection status)``.
``status`` value is a enum type which reports the case which the intersection operation encounters.
The inter... | def intersect(ray1, ray2, **kwargs):
""" Finds intersection of 2 rays.
This functions finds the parameter values for the 1st and 2nd input rays and returns a tuple of
``(parameter for ray1, parameter for ray2, intersection status)``.
``status`` value is a enum type which reports the case which the inte... |
Sets points that form the geometry.
Keyword Arguments:
* ``points``: sets the points | def evaluate(self, **kwargs):
""" Sets points that form the geometry.
Keyword Arguments:
* ``points``: sets the points
"""
self._eval_points = kwargs.get('points', self._init_array())
self._dimension = len(self._eval_points[0]) |
Saves control points or evaluated points in VTK Polydata format (string).
Please see the following document for details: http://www.vtk.org/VTK/img/file-formats.pdf
Keyword Arguments:
* ``point_type``: **ctrlpts** for control points or **evalpts** for evaluated points
* ``tessellate``: tessell... | def export_polydata_str(obj, **kwargs):
""" Saves control points or evaluated points in VTK Polydata format (string).
Please see the following document for details: http://www.vtk.org/VTK/img/file-formats.pdf
Keyword Arguments:
* ``point_type``: **ctrlpts** for control points or **evalpts** for ev... |
Exports control points or evaluated points in VTK Polydata format.
Please see the following document for details: http://www.vtk.org/VTK/img/file-formats.pdf
Keyword Arguments:
* ``point_type``: **ctrlpts** for control points or **evalpts** for evaluated points
* ``tessellate``: tessellates th... | def export_polydata(obj, file_name, **kwargs):
""" Exports control points or evaluated points in VTK Polydata format.
Please see the following document for details: http://www.vtk.org/VTK/img/file-formats.pdf
Keyword Arguments:
* ``point_type``: **ctrlpts** for control points or **evalpts** for ev... |
Generates random colors for control and evaluated curve/surface points plots.
The ``seed`` argument is used to set the random seed by directly passing the value to ``random.seed()`` function.
Please see the Python documentation for more details on the ``random`` module .
Inspired from https://stackoverflo... | def color_generator(seed=None):
""" Generates random colors for control and evaluated curve/surface points plots.
The ``seed`` argument is used to set the random seed by directly passing the value to ``random.seed()`` function.
Please see the Python documentation for more details on the ``random`` module .... |
Converts linear sequence of points into a zig-zag shape.
This function is designed to create input for the visualization software. It orders the points to draw a zig-zag
shape which enables generating properly connected lines without any scanlines. Please see the below sketch on the
functionality of the ``... | def make_zigzag(points, num_cols):
""" Converts linear sequence of points into a zig-zag shape.
This function is designed to create input for the visualization software. It orders the points to draw a zig-zag
shape which enables generating properly connected lines without any scanlines. Please see the belo... |
Converts linear sequence of input points into a quad structure.
:param points: list of points to be ordered
:type points: list, tuple
:param size_v: number of elements in a row
:type size_v: int
:param size_u: number of elements in a column
:type size_u: int
:return: re-ordered points
:... | def make_quad(points, size_u, size_v):
""" Converts linear sequence of input points into a quad structure.
:param points: list of points to be ordered
:type points: list, tuple
:param size_v: number of elements in a row
:type size_v: int
:param size_u: number of elements in a column
:type s... |
Generates a quadtree-like structure from surface control points.
This function generates a 2-dimensional list of control point coordinates. Considering the object-oriented
representation of a quadtree data structure, first dimension of the generated list corresponds to a list of
*QuadTree* classes. Second ... | def make_quadtree(points, size_u, size_v, **kwargs):
""" Generates a quadtree-like structure from surface control points.
This function generates a 2-dimensional list of control point coordinates. Considering the object-oriented
representation of a quadtree data structure, first dimension of the generated ... |
Computes the minimum bounding box of the point set.
The (minimum) bounding box is the smallest enclosure in which all the input points lie.
:param ctrlpts: points
:type ctrlpts: list, tuple
:return: bounding box in the format [min, max]
:rtype: tuple | def evaluate_bounding_box(ctrlpts):
""" Computes the minimum bounding box of the point set.
The (minimum) bounding box is the smallest enclosure in which all the input points lie.
:param ctrlpts: points
:type ctrlpts: list, tuple
:return: bounding box in the format [min, max]
:rtype: tuple
... |
Generates a triangular mesh from an array of points.
This function generates a triangular mesh for a NURBS or B-Spline surface on its parametric space.
The input is the surface points and the number of points on the parametric dimensions u and v,
indicated as row and column sizes in the function signature.... | def make_triangle_mesh(points, size_u, size_v, **kwargs):
""" Generates a triangular mesh from an array of points.
This function generates a triangular mesh for a NURBS or B-Spline surface on its parametric space.
The input is the surface points and the number of points on the parametric dimensions u and v... |
Triangulates a monotone polygon defined by a list of vertices.
The input vertices must form a convex polygon and must be arranged in counter-clockwise order.
:param tri_idx: triangle numbering start value
:type tri_idx: int
:param args: list of Vertex objects
:type args: Vertex
:return: list o... | def polygon_triangulate(tri_idx, *args):
""" Triangulates a monotone polygon defined by a list of vertices.
The input vertices must form a convex polygon and must be arranged in counter-clockwise order.
:param tri_idx: triangle numbering start value
:type tri_idx: int
:param args: list of Vertex o... |
Generates a mesh of quadrilateral elements.
:param points: list of points
:type points: list, tuple
:param size_u: number of points on the u-direction (column)
:type size_u: int
:param size_v: number of points on the v-direction (row)
:type size_v: int
:return: a tuple containing lists of v... | def make_quad_mesh(points, size_u, size_v):
""" Generates a mesh of quadrilateral elements.
:param points: list of points
:type points: list, tuple
:param size_u: number of points on the u-direction (column)
:type size_u: int
:param size_v: number of points on the v-direction (row)
:type si... |
Triangular tessellation algorithm for surfaces with no trims.
This function can be directly used as an input to :func:`.make_triangle_mesh` using ``tessellate_func`` keyword
argument.
:param v1: vertex 1
:type v1: Vertex
:param v2: vertex 2
:type v2: Vertex
:param v3: vertex 3
:type v3... | def surface_tessellate(v1, v2, v3, v4, vidx, tidx, trim_curves, tessellate_args):
""" Triangular tessellation algorithm for surfaces with no trims.
This function can be directly used as an input to :func:`.make_triangle_mesh` using ``tessellate_func`` keyword
argument.
:param v1: vertex 1
:type v1... |
Triangular tessellation algorithm for trimmed surfaces.
This function can be directly used as an input to :func:`.make_triangle_mesh` using ``tessellate_func`` keyword
argument.
:param v1: vertex 1
:type v1: Vertex
:param v2: vertex 2
:type v2: Vertex
:param v3: vertex 3
:type v3: Vert... | def surface_trim_tessellate(v1, v2, v3, v4, vidx, tidx, trims, tessellate_args):
""" Triangular tessellation algorithm for trimmed surfaces.
This function can be directly used as an input to :func:`.make_triangle_mesh` using ``tessellate_func`` keyword
argument.
:param v1: vertex 1
:type v1: Verte... |
Distibuted payload (message) to one connection
:param conn: connection
:param payload: payload(json dumpable)
:return: | def target_message(conn, payload):
"""
Distibuted payload (message) to one connection
:param conn: connection
:param payload: payload(json dumpable)
:return:
"""
try:
yield from conn.send(json.dumps(payload))
except Exception as e:
logger.debug('could not send',... |
Distributes payload (message) to all connected ws clients | def fanout_message(connections, payload):
"""
Distributes payload (message) to all connected ws clients
"""
for conn in connections:
try:
yield from conn.send(json.dumps(payload))
except Exception as e:
logger.debug('could not send', e) |
Distributes the users online status to everyone he has dialog with | def gone_online(stream):
"""
Distributes the users online status to everyone he has dialog with
"""
while True:
packet = yield from stream.get()
session_id = packet.get('session_key')
if session_id:
user_owner = get_user_from_session(session_id)
i... |
Used to check user's online opponents and show their online/offline status on page on init | def check_online(stream):
"""
Used to check user's online opponents and show their online/offline status on page on init
"""
while True:
packet = yield from stream.get()
session_id = packet.get('session_key')
opponent_username = packet.get('username')
if session_i... |
Saves a new chat message to db and distributes msg to connected users | def new_messages_handler(stream):
"""
Saves a new chat message to db and distributes msg to connected users
"""
# TODO: handle no user found exception
while True:
packet = yield from stream.get()
session_id = packet.get('session_key')
msg = packet.get('message')
... |
Sends connected client list of currently active users in the chatroom | def users_changed_handler(stream):
"""
Sends connected client list of currently active users in the chatroom
"""
while True:
yield from stream.get()
# Get list list of current active users
users = [
{'username': username, 'uuid': uuid_str}
for u... |
Show message to opponent if user is typing message | def is_typing_handler(stream):
"""
Show message to opponent if user is typing message
"""
while True:
packet = yield from stream.get()
session_id = packet.get('session_key')
user_opponent = packet.get('username')
typing = packet.get('typing')
if session_i... |
Send message to user if the opponent has read the message | def read_message_handler(stream):
"""
Send message to user if the opponent has read the message
"""
while True:
packet = yield from stream.get()
session_id = packet.get('session_key')
user_opponent = packet.get('username')
message_id = packet.get('message_id')
... |
An Asyncio Task is created for every new websocket client connection
that is established. This coroutine listens to messages from the connected
client and routes the message to the proper queue.
This coroutine can be thought of as a producer. | def main_handler(websocket, path):
"""
An Asyncio Task is created for every new websocket client connection
that is established. This coroutine listens to messages from the connected
client and routes the message to the proper queue.
This coroutine can be thought of as a producer.
"""
... |
Gets the user from current User model using the passed session_key
:param session_key: django.contrib.sessions.models.Session - session_key
:return: User instance or None if not found | def get_user_from_session(session_key):
"""
Gets the user from current User model using the passed session_key
:param session_key: django.contrib.sessions.models.Session - session_key
:return: User instance or None if not found
"""
session = Session.objects.get(session_key=session_key)
sessi... |
gets the dialog between user_1 and user_2
:param user_1: the first user in dialog (owner or opponent)
:param user_2: the second user in dialog (owner or opponent)
:return: queryset which include dialog between user_1 and user_2 (queryset can be empty) | def get_dialogs_with_user(user_1, user_2):
"""
gets the dialog between user_1 and user_2
:param user_1: the first user in dialog (owner or opponent)
:param user_2: the second user in dialog (owner or opponent)
:return: queryset which include dialog between user_1 and user_2 (queryset can be empty)
... |
return True if ANY target_word matches a query_word | def anyword_substring_search_inner(query_word, target_words):
""" return True if ANY target_word matches a query_word
"""
for target_word in target_words:
if(target_word.startswith(query_word)):
return query_word
return False |
return True if all query_words match | def anyword_substring_search(target_words, query_words):
""" return True if all query_words match
"""
matches_required = len(query_words)
matches_found = 0
for query_word in query_words:
reply = anyword_substring_search_inner(query_word, target_words)
if reply is not False:
... |
main function to call for searching | def substring_search(query, list_of_strings, limit_results=DEFAULT_LIMIT):
""" main function to call for searching
"""
matching = []
query_words = query.split(' ')
# sort by longest word (higest probability of not finding a match)
query_words.sort(key=len, reverse=True)
counter = 0
... |
queries lucene index to find a nearest match, output is profile username | def search_people_by_bio(query, limit_results=DEFAULT_LIMIT,
index=['onename_people_index']):
""" queries lucene index to find a nearest match, output is profile username
"""
from pyes import QueryStringQuery, ES
conn = ES()
q = QueryStringQuery(query,
... |
order of results should be a) query in first name, b) query in last name | def order_search_results(query, search_results):
""" order of results should be a) query in first name, b) query in last name
"""
results = search_results
results_names = []
old_query = query
query = query.split(' ')
first_word = ''
second_word = ''
third_word = ''
if(len(que... |
dedup results | def dedup_search_results(search_results):
""" dedup results
"""
known = set()
deduped_results = []
for i in search_results:
username = i['username']
if username in known:
continue
deduped_results.append(i)
known.add(username)
return deduped_resu... |
Generate a hash over data for immutable storage.
Return the hex string. | def get_data_hash(data_txt):
"""
Generate a hash over data for immutable storage.
Return the hex string.
"""
h = hashlib.sha256()
h.update(data_txt)
return h.hexdigest() |
Verify that a zonefile hashes to the given value hash
@zonefile_str must be the zonefile as a serialized string | def verify_zonefile( zonefile_str, value_hash ):
"""
Verify that a zonefile hashes to the given value hash
@zonefile_str must be the zonefile as a serialized string
"""
zonefile_hash = get_zonefile_data_hash( zonefile_str )
if zonefile_hash != value_hash:
log.debug("Zonefile hash mismatc... |
Lock the global health info table.
Return the table. | def atlas_peer_table_lock():
"""
Lock the global health info table.
Return the table.
"""
global PEER_TABLE_LOCK, PEER_TABLE, PEER_TABLE_LOCK_HOLDER, PEER_TABLE_LOCK_TRACEBACK
if PEER_TABLE_LOCK_HOLDER is not None:
assert PEER_TABLE_LOCK_HOLDER != threading.current_thread(), "DEADLOCK"
... |
Unlock the global health info table. | def atlas_peer_table_unlock():
"""
Unlock the global health info table.
"""
global PEER_TABLE_LOCK, PEER_TABLE_LOCK_HOLDER, PEER_TABLE_LOCK_TRACEBACK
try:
assert PEER_TABLE_LOCK_HOLDER == threading.current_thread()
except:
log.error("Locked by %s, unlocked by %s" % (PEER_TAB... |
Given a list of bit indexes (bit_indexes), set or clear the
appropriate bits in the inventory vector (inv_vec).
If the bit index is beyond the length of inv_vec,
then expand inv_vec to accomodate it.
If operation is True, then set the bits.
If operation is False, then clear the bits
Return th... | def atlas_inventory_flip_zonefile_bits( inv_vec, bit_indexes, operation ):
"""
Given a list of bit indexes (bit_indexes), set or clear the
appropriate bits in the inventory vector (inv_vec).
If the bit index is beyond the length of inv_vec,
then expand inv_vec to accomodate it.
If operation is... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.