pyoptools.misc.function_2d.poly_r package

Submodules

Module contents

class pyoptools.misc.function_2d.poly_r.PolyR

Bases: Function2D

A 2D polynomial class for radially symmetric functions.

Represents polynomials that depend only on the radial distance r = x**2 + y**2 from the origin. While the polynomial is defined in terms of r, it can be evaluated at any point (x,y) in Cartesian coordinates.

The polynomial is expressed in terms of r as: z = c_0 + c_1*r + c_2*r^2 + c_3*r^3 + … + c_n*r^n

where r = x**2 + y**2

Parameters:

coeff (array_like) – List or array of polynomial coefficients in ascending order of degree. The length of coeff determines the order of the polynomial.

order

The order (degree) of the polynomial.

Type:

int

_coeff

Internal Eigen vector storing the polynomial coefficients.

Type:

VectorXd

dx

Derivative with respect to x, computed lazily.

Type:

PolyRDeriv or None

dy

Derivative with respect to y, computed lazily.

Type:

PolyRDeriv or None

dx
dxdy()

Compute the partial derivatives with respect to x and y.

Returns:

A tuple (dx, dy) containing the derivative polynomials:
  • dx: derivative with respect to x

  • dy: derivative with respect to y

Return type:

tuple of PolyRDeriv

dy
eval(x, y)

Evaluate the polynomial at arrays of coordinates (x,y).

Parameters:
  • x (ndarray) – 2D array of x coordinates, shape (n_rows, n_cols).

  • y (ndarray) – 2D array of y coordinates, shape (n_rows, n_cols).

Returns:

2D array containing the polynomial values at each (x,y) point, shape matches input arrays.

Return type:

ndarray

order
class pyoptools.misc.function_2d.poly_r.PolyRDeriv

Bases: Function2D

Class that represents the derivative of a radial polynomial.

This class implements the calculation of the partial derivatives of a radial polynomial with respect to x or y coordinates. A radial polynomial is a polynomial expressed in terms of the radial coordinate r = sqrt(x^2 + y^2).

Parameters:
  • coeff (list) – List of coefficients of the radial polynomial. The i-th element corresponds to the coefficient of r^i.

  • axis (int) – Axis along which to take the derivative. Must be 0 (for x) or 1 (for y).

order

The order of the polynomial (number of coefficients - 1)

Type:

int

axis

Axis along which to take the derivative (0 for x, 1 for y)

Type:

int

_coeff

Eigen vector storing the polynomial coefficients

Type:

VectorXd

eval(x, y)

Evaluate the derivative of the radial polynomial over a grid of points.

Parameters:
  • x (ndarray of shape (n, m)) – Array of x coordinates where to evaluate the derivative. Must be a 2D array of doubles.

  • y (ndarray of shape (n, m)) – Array of y coordinates where to evaluate the derivative. Must be a 2D array of doubles.

Returns:

Array containing the values of the polynomial derivative evaluated at each point (x[i,j], y[i,j]).

Return type:

ndarray of shape (n, m)

Notes

This method calls the C-level eval_cy function for each point in the input arrays. Input arrays must have the same shape.