Math

class Math

Bases: pybind11_object

Provides simple mathematics computation tools that are not available in the C mathematics library (math.h)

Methods

__init__

abs

Overloaded function.

clamp

Overloaded function.

comb

Computes the number of combination of p elements inside n elements.

computeRegularPointsOnSphere

Compute the vector of longitude / latitude (in degree) couples for maxPoints regularly spaced on a sphere, using the following paper:

deg

Overloaded function.

enu2ecef

Compute from a given longitude, latitude and a sphere radius the homogeneous transformation from the ENU frame to the ECEF frame:

enu2ned

param enu_M:

HomogeneousMatrix expressed in ENU frame.

equal

param x:

x value.

fact

Computes and returns x!

getAngleBetweenMinPiAndPi

Overloaded function.

getLocalTangentPlaneTransformations

Compute transformations from the local tangent plane (e.g. NED, ECU, ...) to the ECEF frame.

getMean

Compute the mean value for a vector of double.

getMedian

Compute the median value for a vector of double.

getStdev

Compute the standard deviation value for a vector of double.

greater

param x:

x value.

isFinite

Overloaded function.

isInf

Overloaded function.

isNaN

Overloaded function.

isNumber

param str:

String to check.

lineFitting

Compute the line equation using least-squares fitting that minimizes the cost function:

linspace

Overloaded function.

lookAt

Compute the transformation such that the camera located at from position looks toward to position.

maximum

Overloaded function.

mcosc

Compute \((1-cos(x))/x^2\)

minimum

Overloaded function.

modulo

Overloaded function.

msinc

Compute \((1-sinc(x))/x^2\) with \(sinc(x) = sin(x) / x\) .

ned2ecef

Compute from a given longitude, latitude and a sphere radius the homogeneous transformation from the NED frame to the ECEF frame:

nul

param x:

Value to test.

rad

Overloaded function.

round

Round x to the nearest integer.

sigmoid

param x:

Value of x.

sign

Return the sign of x.

sinc

Overloaded function.

sqr

return:

Square value \(x^2\) .

Inherited Methods

Operators

__doc__

__init__

__module__

Attributes

__annotations__

__init__(*args, **kwargs)
static abs(*args, **kwargs)

Overloaded function.

  1. abs(x: int) -> int

Parameters:
x

The number.

Returns:

The absolute value of x

  1. abs(x: float) -> float

Parameters:
x

The number.

Returns:

The absolute value of x

static clamp(*args, **kwargs)

Overloaded function.

  1. clamp(v: int, lower: int, upper: int) -> int

Clamp a value to boundaries.Throw a vpException if the value of lower is greater than upper .

Parameters:
v

The value to clamp.

lower

The boundaries to clamp v to.

upper

The boundaries to clamp v to.

  1. clamp(v: float, lower: float, upper: float) -> float

Clamp a value to boundaries.Throw a vpException if the value of lower is greater than upper .

Parameters:
v

The value to clamp.

lower

The boundaries to clamp v to.

upper

The boundaries to clamp v to.

static comb(n: int, p: int) float

Computes the number of combination of p elements inside n elements.

Parameters:
n: int

total number of elements.

p: int

requested number of elements.

Returns:

Combination number \(n! / ((n-p)! p!)\)

static computeRegularPointsOnSphere(maxPoints: int) list[tuple[float, float]]

Compute the vector of longitude / latitude (in degree) couples for maxPoints regularly spaced on a sphere, using the following paper:

Following image illustrates the camera poses regularly spaced on a sphere:

<unparsed image <doxmlparser.compound.docImageType object at 0x7f12320e7d60>>

Parameters:
maxPoints: int

The number of point coordinates to be sampled on a sphere.

Returns:

The vector of longitude / latitude (in degree) pairs for the maxPoints on a sphare.

static deg(*args, **kwargs)

Overloaded function.

  1. deg(rad: float) -> float

Convert an angle in radians into degrees.

Parameters:
rad

Angle in radians.

Returns:

Angle converted in degrees.

  1. deg(r: visp._visp.core.RotationVector) -> visp._visp.core.ColVector

Convert angles of a rotation vector into degrees.

Parameters:
r

Rotation vector with angles in radians.

Returns:

Corresponding column vector with angles converted in degrees.

  1. deg(r: visp._visp.core.ColVector) -> visp._visp.core.ColVector

Convert angles of a column vector from radians to degrees.

Parameters:
r

Column vector with angles in radians.

Returns:

Corresponding column vector with angles converted in degrees.

static enu2ecef(lonDeg: float, latDeg: float, radius: float) visp._visp.core.HomogeneousMatrix

Compute from a given longitude, latitude and a sphere radius the homogeneous transformation from the ENU frame to the ECEF frame:

\[\begin{split}\begin{bmatrix} X_{\text{ecef}} \\Y_{\text{ecef}} \\Z_{\text{ecef}} \end{bmatrix} = \begin{bmatrix} -\sin \lambda & -\sin \varphi \cos \lambda & \cos \varphi \cos \lambda \\\cos \lambda & -\sin \varphi \sin \lambda & \cos \varphi \sin \lambda \\0 & \cos \varphi & \sin \varphi \end{bmatrix} + \begin{bmatrix} \text{r} \cos \varphi \cos \lambda \\\text{r} \cos \varphi \sin \lambda \\\text{r} \sin \varphi \end{bmatrix} \end{split}\]

<unparsed image <doxmlparser.compound.docImageType object at 0x7f12320c3400>>

Note

See ned2ecef() , getLocalTangentPlaneTransformations()

Parameters:
lonDeg: float

The longitude in degree or angle \(\lambda\) in previous equation.

latDeg: float

The latitude in degree or angle \(\varphi\) in previous equation.

radius: float

The sphere radius \(r\) in meter.

Returns:

The homogeneous transformation from ENU to ECEF frame.

static enu2ned(enu_M: visp._visp.core.HomogeneousMatrix) visp._visp.core.HomogeneousMatrix
Parameters:
enu_M: visp._visp.core.HomogeneousMatrix

HomogeneousMatrix expressed in ENU frame.

Returns:

Converted homogeneous matrix in NED frame.

static equal(x: float, y: float, threshold: float = 0.001) bool
Parameters:
x: float

x value.

y: float

y value.

threshold: float = 0.001

Tolerance threshold.

Returns:

true if \(| x - y | <\) threshold .

static fact(x: int) float

Computes and returns x!

Parameters:
x: int

parameter of factorial function.

static getAngleBetweenMinPiAndPi(*args, **kwargs)

Overloaded function.

  1. getAngleBetweenMinPiAndPi(theta: float) -> float

Convert angle between \(-\pi\) and \(\pi\) .

Parameters:
theta

The input angle we want to ensure it is in the interval \([-\pi ; \pi]\) .

Returns:

The corresponding angle in the interval \([-\pi ; \pi]\) .

  1. getAngleBetweenMinPiAndPi(theta: float) -> float

Convert angle between \(-\pi\) and \(\pi\) .

Parameters:
theta

The input angle we want to ensure it is in the interval \([-\pi ; \pi]\) .

Returns:

The corresponding angle in the interval \([-\pi ; \pi]\) .

static getLocalTangentPlaneTransformations(lonlatVec: list[tuple[float, float]], radius: float, func: vpHomogeneousMatrix(double, double, double)) list[visp._visp.core.HomogeneousMatrix]

Compute transformations from the local tangent plane (e.g. NED, ECU, …) to the ECEF frame.

Following image illustrates the camera poses sampled using longitude / latitude coordinates:

<unparsed image <doxmlparser.compound.docImageType object at 0x7f1231a113c0>>

Note

See enu2ecef() , ned2ecef()

Parameters:
lonlatVec: list[tuple[float, float]]

Vector of longitude/latitude coordinates in degree.

radius: float

Sphere radius in meter.

Returns:

The vector of ecef_M_local homogeneous transformations.

static getMean(v: list[float]) float

Compute the mean value for a vector of double.

Parameters:
v: list[float]

Vector of double values.

Returns:

The mean value.

static getMedian(v: list[float]) float

Compute the median value for a vector of double.

Parameters:
v: list[float]

Vector of double values.

Returns:

The median value.

static getStdev(v: list[float], useBesselCorrection: bool = false) float

Compute the standard deviation value for a vector of double.

Parameters:
v: list[float]

Vector of double values.

useBesselCorrection: bool = false

If true, the Bessel correction is used (normalize by N-1).

Returns:

The standard deviation value.

static greater(x: float, y: float, threshold: float = 0.001) bool
Parameters:
x: float

x value.

y: float

y value.

threshold: float = 0.001

Tolerance threshold.

Returns:

true if \(x > y -\) threshold .

static isFinite(*args, **kwargs)

Overloaded function.

  1. isFinite(value: float) -> bool

Parameters:
value

Double number to check.

Returns:

true if value is neither infinite nor NaN (as defined by IEEE754 standard) and false otherwise.

  1. isFinite(value: float) -> bool

Parameters:
value

Float number to check.

Returns:

true if value is neither infinite nor NaN (as defined by IEEE754 standard) and false otherwise.

static isInf(*args, **kwargs)

Overloaded function.

  1. isInf(value: float) -> bool

Parameters:
value

Double number to check.

Returns:

true if value is a plus or minus infinity (as defined by IEEE754 standard) and false otherwise.

  1. isInf(value: float) -> bool

Parameters:
value

Float number to check.

Returns:

true if value is a plus or minus infinity (as defined by IEEE754 standard) and false otherwise.

static isNaN(*args, **kwargs)

Overloaded function.

  1. isNaN(value: float) -> bool

Parameters:
value

Double number to check.

Returns:

true if value is Not A Number (as defined by IEEE754 standard) and false otherwise.

  1. isNaN(value: float) -> bool

Parameters:
value

Float number to check.

Returns:

true if value is Not A Number (as defined by IEEE754 standard) and false otherwise.

static isNumber(str: str) bool
Parameters:
str: str

String to check.

Returns:

true if string is number and false otherwise.

static lineFitting(imPts: list[visp._visp.core.ImagePoint]) tuple[float, float, float, float]

Compute the line equation using least-squares fitting that minimizes the cost function:

\[\mathbf{E} = \sum_{i=1}^{n}\left ( ax_i + by_i - c \right )^2 \]
Parameters:
imPts: list[visp._visp.core.ImagePoint]

Image points (size >= 3).

Returns:

A tuple containing:

  • The mean distance error (point-to-line distance) between the points and the fitted line.

  • a: a coefficient.

  • b: b coefficient.

  • c: c coefficient.

static linspace(*args, **kwargs)

Overloaded function.

  1. linspace(start_in: int, end_in: int, num_in: int) -> list[float]

Similar to the NumPy linspace function: “Return evenly spaced numbers over a specified interval.” Code from: https://stackoverflow.com/a/27030598

Parameters:
start_in

The starting value of the sequence.

end_in

The end value of the sequence.

num_in

Number of samples to generate.

Returns:

Returns num_in evenly spaced samples, calculated over the interval [ start_in , end_in ].

  1. linspace(start_in: float, end_in: float, num_in: int) -> list[float]

Similar to the NumPy linspace function: “Return evenly spaced numbers over a specified interval.” Code from: https://stackoverflow.com/a/27030598

Parameters:
start_in

The starting value of the sequence.

end_in

The end value of the sequence.

num_in

Number of samples to generate.

Returns:

Returns num_in evenly spaced samples, calculated over the interval [ start_in , end_in ].

static lookAt(from: visp._visp.core.ColVector, to: visp._visp.core.ColVector, tmp: visp._visp.core.ColVector) visp._visp.core.HomogeneousMatrix

Compute the transformation such that the camera located at from position looks toward to position.

<unparsed image <doxmlparser.compound.docImageType object at 0x7f1231a13040>>

Right-handed coordinate system for OpenGL (figure from https://learnopengl.com/Getting-started/Coordinate-Systems ):

<unparsed image <doxmlparser.compound.docImageType object at 0x7f1231a134c0>>

See also:

Parameters:
from

Current camera position as a 3-dim vector with 3D coordinates (X,Y,Z) in meter..

to

Where the camera must point toward as a 3-dim vector with 3D coordinates (X,Y,Z) in meter.

tmp

Arbitrary up-vector as a 3-dim vector with coordinates along (X,Y,Z) in meter.

Returns:

The homogeneous transformation from the camera frame to the OpenGL frame.

static maximum(*args, **kwargs)

Overloaded function.

  1. maximum(a: int, b: int) -> int

Parameters:
a

First number.

b

Second number.

Returns:

The maximum of the two numbers.

  1. maximum(a: float, b: float) -> float

Parameters:
a

First number.

b

Second number.

Returns:

The maximum of the two numbers.

static mcosc(cosx: float, x: float) float

Compute \((1-cos(x))/x^2\)

Parameters:
cosx: float

Value of cos(x).

x: float

Value of x.

Returns:

\((1-cos(x))/x^2\)

static minimum(*args, **kwargs)

Overloaded function.

  1. minimum(a: int, b: int) -> int

Parameters:
a

First number.

b

Second number.

Returns:

The minimum of the two numbers.

  1. minimum(a: float, b: float) -> float

Parameters:
a

First number.

b

Second number.

Returns:

The minimum of the two numbers.

static modulo(*args, **kwargs)

Overloaded function.

  1. modulo(value: float, modulo: float) -> float

Gives the rest of value divided by modulo when the quotient can only be an integer.

Parameters:
value

The value we want to know the rest in the “modulo” operation.

modulo

The divider.

Returns:

float The rest as in a modulo operation.

  1. modulo(value: float, modulo: float) -> float

Gives the rest of value divided by modulo when the quotient can only be an integer.

Parameters:
value

The value we want to know the rest in the “modulo” operation.

modulo

The divider.

Returns:

double The rest as in a modulo operation.

  1. modulo(a: int, n: int) -> int

Compute the modified modulo:

  • modulo(11, 10) == 1 == 11 % 10

  • modulo(-1, 10) == 9

Parameters:
a

The dividend.

n

The divisor.

Returns:

The modified modulo of a mod n.

  1. modulo(a: int, n: int) -> int

Compute the modified modulo:

  • modulo(11, 10) == 1 == 11 % 10

Parameters:
a

The dividend.

n

The divisor.

Returns:

The modified modulo of a mod n.

static msinc(sinx: float, x: float) float

Compute \((1-sinc(x))/x^2\) with \(sinc(x) = sin(x) / x\) .

Parameters:
sinx: float

value of sin(x).

x: float

Value of x.

Returns:

\((1-sinc(x))/x^2\)

static ned2ecef(lonDeg: float, latDeg: float, radius: float) visp._visp.core.HomogeneousMatrix

Compute from a given longitude, latitude and a sphere radius the homogeneous transformation from the NED frame to the ECEF frame:

\[\begin{split}\begin{bmatrix} X_{\text{ecef}} \\Y_{\text{ecef}} \\Z_{\text{ecef}} \end{bmatrix} = \begin{bmatrix} -\sin \varphi \cos \lambda & -\sin \lambda & -\cos \varphi \cos \lambda \\-\sin \varphi \sin \lambda & \cos \lambda & -\cos \varphi \sin \lambda \\\cos \varphi & 0 & -\sin \varphi \end{bmatrix} + \begin{bmatrix} \text{r} \cos \varphi \cos \lambda \\\text{r} \cos \varphi \sin \lambda \\\text{r} \sin \varphi \end{bmatrix} \end{split}\]

<unparsed image <doxmlparser.compound.docImageType object at 0x7f12320c10f0>>

See also:

Note

See enu2ecef() , getLocalTangentPlaneTransformations()

Parameters:
lonDeg: float

The longitude in degree or angle \(\lambda\) in previous equation.

latDeg: float

The latitude in degree or angle \(\varphi\) in previous equation.

radius: float

The sphere radius \(r\) in meter.

Returns:

The homogeneous transformation from NED to ECEF frame.

static nul(x: float, threshold: float = 0.001) bool
Parameters:
x: float

Value to test.

threshold: float = 0.001

Tolerance threshold

Returns:

true if \(| x | <\) threshold .

static rad(*args, **kwargs)

Overloaded function.

  1. rad(deg: float) -> float

Parameters:
deg

Angle in degrees.

Returns:

Angle converted in radians.

  1. rad(r: visp._visp.core.ColVector) -> visp._visp.core.ColVector

Convert angles of a column vector from degrees to radians.

Parameters:
r

Column vector with angles in degrees.

Returns:

Corresponding column vector with angles converted in radians.

static round(x: float) int

Round x to the nearest integer.

Parameters:
x: float

Value to round.

Returns:

Nearest integer of x.

static sigmoid(x: float, x0: float = 0., x1: float = 1., n: float = 12.) float
Parameters:
x: float

Value of x.

x0: float = 0.

Lower bound (default 0).

x1: float = 1.

Upper bound (default 1).

n: float = 12.

Degree of the exponential (default 12).

Returns:

Sigmoid value \(1/(1+exp(-n*((x-x0)/(x1-x0)-0.5)))\)

static sign(x: float) int

Return the sign of x.

Parameters:
x: float

Value to test.

Returns:

-1 if x is negative, +1 if positive and 0 if zero.

static sinc(*args, **kwargs)

Overloaded function.

  1. sinc(x: float) -> float

Compute sinus cardinal \(\frac{sin(x)}{x}\) .

Parameters:
x

Value of x.

Returns:

Sinus cardinal.

  1. sinc(sinx: float, x: float) -> float

Compute sinus cardinal \(\frac{sin(x)}{x}\) .

Parameters:
sinx

Value of sin(x).

x

Value of x.

Returns:

Sinus cardinal.

static sqr(x: float) float
Returns:

Square value \(x^2\) .