java.lang.Object
org.bzdev.math.Functions.Bernstein
- Enclosing class:
- Functions
Class containing methods specific to Bernstein polynomials.
- Methods for summing Bernstein polynomials:
- sumB(beta, n, x) - computes beta[i]*B(i,n,x), summed over i with the sum ranging from 0 to n inclusive.
- dsumBdx(beta, n, x) - computes the first derivative with respect to x of beta[i]*Bernstein(i,n,x) summed over i with the sum ranging from 0 to n inclusive.
- d2sumBdx2(beta, n, x) - computes the second derivative with respect to x of beta[i]*Bernstein(i,n,x) summed over i with the sum ranging from 0 to n inclusive.
- Methods for computing multiple sums of Bernstein polynomials:
- sumB(result, beta, n, x) - for each element of result, result[m], computes beta[m+i*result.length]*B(i,n,x), summed over i with the sum ranging from 0 to n inclusive.
- dsumBdx(result, beta, n, x) - for each element of result, result[m], computes the first derivative with respect to x of beta[m +i*result.length]*Bernstein(i,n,x) summed over i with the sum ranging from 0 to n inclusive.
- d2sumBdx2(result, beta, n, x) - for each element of result, result[m], computes the second derivative with respect to x of beta[m+i*result.length]*Bernstein(i,n,x) summed over i with the sum ranging from 0 to n inclusive.
- Methods for summing Bernstein polynomials that use barycentric
coordinates (the first 5 are used by the implementation but
may be useful for generating documentation, configuring GUIs,
etc.). The sum can be written as
∑λ βλBnλ(τ)
where n is a non-negative integer, τ is a vector of length
dim(τ), and the values of λ in the sum satisfy
0 ≤ λi ≤ n and
∑i=0dim(λ)-1 λi = n.
For convenience, the λ vectors can be encoded as an index.
The methods are:
- indexForLambdas(n, lambdas...) - for Bernstein polynomials of degree n, encode the lambda values as an index. Indices are not contiguous but have a well-defined order.
- lambdasForIndex(n, len, index) - for Bernstein polynomials of degree n convert an index to a vector whose length is len and whose components are lambda values.
- lambdasForIndex(n, results, index) - for Bernstein polynomials of degree n convert an index to a vector, storing the values in the array results. The length of the array results corresponds the number of barycentric coordinates.
- generateIndices(n, len) - for Bernstein polynomials of degree n, generate an array containing indices in a canonical order. For each index in this array, the sum of its λ components will be n. The number of λ components is len.
- generateIndices(n, m, len) - for Bernstein polynomials of degree n, generate an array containing indices in a canonical order. For each index in this array, the sum of its λ components will be m. The number of λ components is len.
- sumB(beta, n, x...) - compute the sum beta[ind]*B(n, lambdasForIndex(n, len, list[ind]), x0, x1, ...) where list = generateIndices(n, len) and len is the number of arguments from and including x0 to the end of the argument list. This sum is equivalent to σλ βλBnλ(τ).
- dsumBdx(xInd, beta, n, x...) - compute the partial derivative of sumB(beta, n, x0, ... ) with respect to xxInd.
- d2sumBdxdy(xInd,yInd, beta, n, x...) - compute the partial derivative of sumB(beta, n, x0, ... ) with respect to xxInd, and then differentiate again with respect to xyInd.
- Methods for computing multiple sums of Bernstein polynomials
that use barycentric coordinates.
The methods are
- sumB(result, beta, n, x...) - for each component result[m] compute the sum beta[m + ind*result.length]*B(n, lambdasForIndex(n, len, list[ind]), x0, x1, ...) where list = generateIndices(n, len) and len is the number of arguments from and including x0 to the end of the argument list.
- dsumBdx(result, xInd, beta, n, x...) - for each component result[m] compute the partial derivative of sumB(beta, n, x0, ... ) with respect to xxInd.
- d2sumBdxdy(result, xInd,yInd, beta, n, x...) - for each component result[m] compute the partial derivative of sumB(beta, n, x0, ... ) with respect to xxInd, and then differentiate again with respect to xyInd.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
d2sumBdx2
(double[] results, double[] beta, int m, int n, double x) Compute the second derivative of a weighted sum of Bernstein polynomials of the same degree for each component of an array of arguments, specifying an offset into the array representing weights.static double
d2sumBdx2
(double[] beta, int n, double x) Compute the second derivative of a weighted sum of Bernstein polynomials of the same degree.static double
d2sumBdx2
(double[] beta, int m, int n, double x) Compute the second derivative of a weighted sum of Bernstein polynomials of the same degree using a coefficient array with an offset.static void
d2sumBdxdy
(int xInd, int yInd, double[] result, double[] beta, int n, double... x) Compute a second partial derivative of a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates for each of a sequence of values.static void
d2sumBdxdy
(int xInd, int yInd, double[] result, double[] beta, int offset, int n, double... x) Compute a second partial derivative of a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates for each of a sequence of values, specifying an offset into the array providing the weights.static double
d2sumBdxdy
(int xInd, int yInd, double[] beta, int n, double... x) Compute a second partial derivative of a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates.static void
dIsumBdxI
(double[] results, double[] beta, int m, int n, double x, int I) Compute the Ith derivative of a weighted sum of Bernstein polynomials of the same degree for each component of an array of arguments, specifying an offset into the array representing weights.static double
dIsumBdxI
(int I, double[] beta, int n, double x) Compute the Ith derivative of a weighted sum of Bernstein polynomials of the same degree.static void
dsumBdx
(double[] results, double[] beta, int n, double x) Compute the derivative of a weighted sum of Bernstein polynomials of the same degree for each component of an array of arguments.static void
dsumBdx
(double[] results, double[] beta, int m, int n, double x) Compute the derivative of a weighted sum of Bernstein polynomials of the same degree for each component of an array of arguments, specifying an offset into the array representing weights.static double
dsumBdx
(double[] beta, int n, double x) Compute the derivative of a weighted sum of Bernstein polynomials of the same degree.static double
dsumBdx
(double[] beta, int m, int n, double x) Compute the derivative of a weighted sum of Bernstein polynomials of the same degree using a coefficient array with an offset.static void
dsumBdx
(double[] results, int offset, int rlen, double[] beta, int m, int n, double x) Compute the derivative of a weighted sum of Bernstein polynomials of the same degree for each component of an array of arguments, specifying an offset into the array representing weights and an offset into the array storing the results.static void
dsumBdx
(int xInd, double[] result, double[] beta, int n, double... x) Compute a first partial derivative of a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates for each of a sequence of values.static void
dsumBdx
(int xInd, double[] result, double[] beta, int offset, int n, double... x) Compute a first partial derivative of a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates for each of a sequence of values, specifying an offset into the array providing the weights.static double
dsumBdx
(int xInd, double[] beta, int n, double... x) Compute a first partial derivative of a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates.static int[]
generateIndices
(int n, int len) Generate a list of all the valid indices.static int[]
generateIndices
(int n, int m, int len) Generate a list of all the valid indices.static int
indexForLambdas
(int n, int... lambdas) Get an index representing a sequence of m values λ0, λ1, ..., λm-1, for which λi ∈ [0, n] for i ∈ [0, m) and such that the sum of λi (i ∈ [0, m)) is n.static void
lambdasForIndex
(int n, int[] results, int index) Get the sequence of m values corresponding to an index, storing the results in an array of length m that is explicitly provided.static int[]
lambdasForIndex
(int n, int len, int index) Get the sequence of m values corresponding to an index.static int
raiseBy
(double[] result, double[] beta, int n, int r) Compute the coefficients for a weighted sum of Bernstein polynomials of degree n+r for a weighted sum of Bernstein polynomials of degree n.static void
scale
(double[] result, double[] beta, int n) Transform the coefficients for a polynomial using a Bernstein basis to ones for a scaled Bernstein basis.static void
sumB
(double[] result, double[] beta, int n, double x) Compute a weighted sum of Bernstein polynomials of the same degree for each component of an array of arguments.static void
sumB
(double[] result, double[] beta, int n, double... x) Compute a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates for each of a sequence of values.static void
sumB
(double[] result, double[] beta, int m, int n, double x) Compute a weighted sum of Bernstein polynomials of the same degree for each component of an array of arguments, specifying an offset into the array representing weights.static void
sumB
(double[] result, double[] beta, int offset, int n, double... x) Compute a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates for each of sequence of values from an array, also specifying an offset into that array.static double
sumB
(double[] beta, int n, double x) Compute a weighted sum of Bernstein polynomials of the same degree.static double
sumB
(double[] beta, int n, double... x) Compute a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates.static double
sumB
(double[] beta, int m, int n, double x) Compute a weighted sum of Bernstein polynomials of the same degree, specifying an offset.static void
sumB
(double[] result, int offset, int rlen, double[] beta, int m, int n, double x) Compute a weighted sum of Bernstein polynomials of the same degree for each component of an array of arguments, specifying an offset into the array representing weights and an offset into the array storing the results.static double
sumBerr
(double[] beta, int m, int n, double x) Compute the error for a weighted sum of Bernstein polynomials of the same degree, specifying an offset.static void
unscale
(double[] result, double[] beta, int n) Transform the coefficients for a polynomial using a scaled Bernstein basis to ones for a Bernstein basis.
-
Method Details
-
sumB
Compute a weighted sum of Bernstein polynomials of the same degree. The implementation uses De Casteljau's algorithm, which is fast and numerically stable. The length of the array beta must be at least n+1. Indices larger than n+1 are ignored.- Parameters:
beta
- the weights for each polynomialn
- the degree of the Bernstein polynomials (a non-negative integer)x
- the point at which to evaluate the polynomials- Returns:
- the sum of beta[i+m]*B(i,n,x) for i in [0,n]
- Throws:
IllegalArgumentException
- an argument was out of bounds
-
raiseBy
public static int raiseBy(double[] result, double[] beta, int n, int r) Compute the coefficients for a weighted sum of Bernstein polynomials of degree n+r for a weighted sum of Bernstein polynomials of degree n.- Parameters:
result
- an array holding the coefficients after the degree was raised by rbeta
- the original coefficientsn
- the degree of the polynomials before the degree was raisedr
- the degree increment- Returns:
- the new degree (n+r)
- Throws:
IllegalArgumentException
- an argument was out of range
-
scale
public static void scale(double[] result, double[] beta, int n) Transform the coefficients for a polynomial using a Bernstein basis to ones for a scaled Bernstein basis. If the argument array beta contains values such that beta[i] is the coefficient for Bni(t), then result[i] will be the coefficient for (1-t)itn-i for i∈[0,n]. The arrays result and beta may be the same array.- Parameters:
result
- the coefficients for a scaled Bernstein basisbeta
- the coefficients for a Bernstein basisn
- the degree of the Bernstein polynomials
-
unscale
public static void unscale(double[] result, double[] beta, int n) Transform the coefficients for a polynomial using a scaled Bernstein basis to ones for a Bernstein basis. If the argument array beta contains values such that beta[i] is the coefficient (1-t)itn-i, then result[i] will be the coefficient for Bni(t) for i∈[0,n]. The arrays result and beta may be the same array.- Parameters:
result
- the coefficients for a scaled Bernstein basisbeta
- the coefficients for a Bernstein basisn
- the degree of the Bernstein polynomials
-
sumB
Compute a weighted sum of Bernstein polynomials of the same degree, specifying an offset. The ith weight will be multiplied by the Bernstein polynomial Bi,n(x) when computing the sum. The implementation uses De Casteljau's algorithm, which is fast and numerically stable. The length of the array beta must be at least n+1. Indices larger than n+1 are ignored.- Parameters:
beta
- the weights for each polynomialm
- the offset into the array beta at which the weights for each polynomial startn
- the degree of the Bernstein polynomials (a non-negative integer)x
- the point at which to evaluate the polynomials- Returns:
- the sum of beta[i+m]*B(i,n,x) for i in [0,n]
- Throws:
IllegalArgumentException
- an argument was out of bounds
-
sumBerr
public static double sumBerr(double[] beta, int m, int n, double x) Compute the error for a weighted sum of Bernstein polynomials of the same degree, specifying an offset. The ith weight will be multiplied by the Bernstein polynomial Bi,n(x) when computing the sum. The length of the array beta must be at least n+1. Indices larger than n+1 are ignored. The error computed is based on the spacing between adjacent double-precision numbers.- Parameters:
beta
- the weights for each polynomialm
- the offset into the array beta at which the weights for each polynomial startn
- the degree of the Bernstein polynomials (a non-negative integer)x
- the point at which to evaluate the polynomials- Returns:
- the error for the sum of beta[i+m]*B(i,n,x) for i in [0,n]
- Throws:
IllegalArgumentException
- an argument was out of bounds
-
sumB
public static void sumB(double[] result, double[] beta, int n, double x) throws IllegalArgumentException Compute a weighted sum of Bernstein polynomials of the same degree for each component of an array of arguments. The implementation uses De Casteljau's algorithm, which is fast and numerically stable. The length of the array beta must be at least (n+1) multiplied by the length of the "result" argument vector. The array beta contains the weights for each element of the argument array result and for each Bernstein polynomial Bi,n, ordered so that the weights for each element of result and a given value of i appear before the weights for i+1. Similarly, for a given value of i, the indices of beta corresponding to elements of the vector result are in the same order as for the vector result.- Parameters:
result
- the sum of beta[i+m]*B(i,n,x) for i in [0,n];beta
- the weights for each polynomial listed in the order specified aboven
- The degree of the Bernstein polynomialsx
- the value at which to evaluate the polynomials- Throws:
IllegalArgumentException
- an argument was out of bounds
-
sumB
public static void sumB(double[] result, double[] beta, int m, int n, double x) throws IllegalArgumentException Compute a weighted sum of Bernstein polynomials of the same degree for each component of an array of arguments, specifying an offset into the array representing weights. The implementation uses De Casteljau's algorithm, which is fast and numerically stable. The length of the array beta must be at least (m + (n+1)) multiplied by the length of the "result" argument vector. Indices larger than n+1 are ignored. The array beta contains the weights for each element of the argument array result and for each Bernstein polynomial Bi,n, ordered so that the weights for each element of result and a given value of i appear before the weights for i+1. Similarly, for a given value of i, the indices of beta corresponding to elements of the vector result are in the same order as for the vector result.- Parameters:
result
- the sum of beta[i+m]*B(i,n,x) for i in [0,n];beta
- the weights for each polynomial listed in the order specified abovem
- the offset into the beta array measured in multiples of the length of the vectorresult
n
- The degree of the Bernstein polynomialsx
- the value at which to evaluate the polynomials- Throws:
IllegalArgumentException
- an argument was out of bounds
-
sumB
public static void sumB(double[] result, int offset, int rlen, double[] beta, int m, int n, double x) throws IllegalArgumentException Compute a weighted sum of Bernstein polynomials of the same degree for each component of an array of arguments, specifying an offset into the array representing weights and an offset into the array storing the results. The implementation uses De Casteljau's algorithm, which is fast and numerically stable. The length of the array beta must be at least (m + (n+1)) multiplied by the value of the 'rlen' argument. Indices larger than n+1 are ignored. The array beta contains the weights for each element of the argument array result in the range [offset, offset+rlen) and for each Bernstein polynomial Bi,n, ordered so that the weights for each element of result and a given value of i appear before the weights for i+1. Similarly, for a given value of i, the indices of beta corresponding to elements of the vector result are in the same order as for the vector result.Note: this method was added because it is useful in computing values at points on Bézier patches.
- Parameters:
result
- the sum of beta[i+m]*B(i,n,x) for i in [0,n];offset
- the offset into the result arrayrlen
- the length to use for the computationbeta
- the weights for each polynomial listed in the order specified abovem
- the offset into the beta array measured in multiples of the length of the vectorresult
n
- The degree of the Bernstein polynomialsx
- the value at which to evaluate the polynomials- Throws:
IllegalArgumentException
- an argument was out of bounds
-
dsumBdx
Compute the derivative of a weighted sum of Bernstein polynomials of the same degree. The implementation uses De Casteljau's algorithm, which is fast and numerically stable. The length of the array beta must be at least n+1. Indices larger than n+1 are ignored.- Parameters:
beta
- the weights for each polynomialn
- The degree of the Bernstein polynomialsx
- the value at which to evaluate the derivative- Returns:
- the derivative of the sum of beta[i+m]*B(i,n,x) for i in [0,n]
- Throws:
IllegalArgumentException
- an argument was out of bounds
-
dsumBdx
public static double dsumBdx(double[] beta, int m, int n, double x) Compute the derivative of a weighted sum of Bernstein polynomials of the same degree using a coefficient array with an offset. The implementation uses De Casteljau's algorithm, which is fast and numerically stable. The length of the array beta must be at least m+n+1. Indices larger than or equal to m+n+1 are ignored. The coefficient for Bi,n(x) is beta[m+i].- Parameters:
beta
- the weights for each polynomialm
- the offset into the array provided by the first argumentn
- The degree of the Bernstein polynomialsx
- the value at which to evaluate the derivative- Returns:
- the derivative of the sum of beta[i+m]*B(i,n,x) for i in [0,n]
- Throws:
IllegalArgumentException
- an argument was out of bounds
-
dsumBdx
public static void dsumBdx(double[] results, double[] beta, int n, double x) throws IllegalArgumentException Compute the derivative of a weighted sum of Bernstein polynomials of the same degree for each component of an array of arguments. The implementation uses De Casteljau's algorithm, which is fast and numerically stable. The length of the array beta must be at least (n+1) multiplied by the length of the "result" argument vector. Indices larger than n+1 are ignored. The array beta contains the weights for each element of the argument array result and for each Bernstein polynomial Bi,n, ordered so that the weights for each element of result and a given value of i appear before the weights for i+1. Similarly, for a given value of i, the indices of beta corresponding to elements of the vector result are in the same order as for the vector result.- Parameters:
results
- the sum of beta[i+m]*B(i,n,x) for i in [0,n];beta
- the weights for each polynomial listed in the order specified aboven
- The degree of the Bernstein polynomialsx
- the value at which to evaluate the polynomials- Throws:
IllegalArgumentException
- an argument was out of bounds
-
dsumBdx
public static void dsumBdx(double[] results, double[] beta, int m, int n, double x) throws IllegalArgumentException Compute the derivative of a weighted sum of Bernstein polynomials of the same degree for each component of an array of arguments, specifying an offset into the array representing weights. The implementation uses De Casteljau's algorithm, which is fast and numerically stable. The length of the array beta must be at least (m + (n+1)) multiplied by the length of the "result" argument vector. Indices larger than n+1 are ignored. The array beta contains the weights for each element of the argument array result and for each Bernstein polynomial Bi,n, ordered so that the weights for each element of result and a given value of i appear before the weights for i+1. Similarly, for a given value of i, the indices of beta corresponding to elements of the vector result are in the same order as for the vector result.- Parameters:
results
- the sum of beta[i+m]*B(i,n,x) for i in [0,n];beta
- the weights for each polynomial listed in the order specified abovem
- the offset into the beta array in multiples of the length of the vector resultn
- The degree of the Bernstein polynomialsx
- the value at which to evaluate the polynomials- Throws:
IllegalArgumentException
- an argument was out of bounds
-
dsumBdx
public static void dsumBdx(double[] results, int offset, int rlen, double[] beta, int m, int n, double x) throws IllegalArgumentException Compute the derivative of a weighted sum of Bernstein polynomials of the same degree for each component of an array of arguments, specifying an offset into the array representing weights and an offset into the array storing the results. The implementation uses De Casteljau's algorithm, which is fast and numerically stable. The length of the array beta must be at least (m + (n+1)) multiplied by value of the 'rlen' argument. Indices larger than n+1 are ignored. The array beta contains the weights for each element of the argument array result in the range [offset, offset+rlen) and for each Bernstein polynomial Bi,n, ordered so that the weights for each element of result and a given value of i appear before the weights for i+1. Similarly, for a given value of i, the indices of beta corresponding to elements of the vector result are in the same order as for the vector result.Note: this method was added because it is useful in computing tangents at points on Bézier patches.
- Parameters:
results
- the sum of beta[i+m]*B(i,n,x) for i in [0,n];offset
- the offset into the result arrayrlen
- the length to use for the computationbeta
- the weights for each polynomial listed in the order specified abovem
- the offset into the beta array in multiples of the length of the vector resultn
- The degree of the Bernstein polynomialsx
- the value at which to evaluate the polynomials- Throws:
IllegalArgumentException
- an argument was out of bounds
-
d2sumBdx2
Compute the second derivative of a weighted sum of Bernstein polynomials of the same degree. The implementation uses De Casteljau's algorithm, which is fast and numerically stable. The length of the array beta must be at least n+1. Indices larger than n+1 are ignored.- Parameters:
beta
- the weights for each polynomialn
- The degree of the Bernstein polynomialsx
- the argument- Returns:
- the second derivative of the sum of beta[i]*B(i,n,x) for i in [0,n]
- Throws:
IllegalArgumentException
- an argument was out of bounds
-
d2sumBdx2
public static double d2sumBdx2(double[] beta, int m, int n, double x) throws IllegalArgumentException Compute the second derivative of a weighted sum of Bernstein polynomials of the same degree using a coefficient array with an offset. The implementation uses De Casteljau's algorithm, which is fast and numerically stable. The length of the array beta must be at least m+n+1. Indices larger than or equal to m+n+1 are ignored. The coefficient for Bi,n(x) is beta[m+i].- Parameters:
beta
- the weights for each polynomialm
- the offset into the array provided by the first argumentn
- The degree of the Bernstein polynomialsx
- the argument- Returns:
- the second derivative of the sum of beta[i]*B(i,n,x) for i in [0,n]
- Throws:
IllegalArgumentException
- an argument was out of bounds
-
d2sumBdx2
public static void d2sumBdx2(double[] results, double[] beta, int m, int n, double x) throws IllegalArgumentException Compute the second derivative of a weighted sum of Bernstein polynomials of the same degree for each component of an array of arguments, specifying an offset into the array representing weights. The implementation uses De Casteljau's algorithm, which is fast and numerically stable. The length of the array beta must be at least (m + (n+1)) multiplied by the length of the "result" argument vector. Indices larger than n+1 are ignored. The array beta contains the weights for each element of the argument array result and for each Bernstein polynomial Bi,n, ordered so that the weights for each element of result and a given value of i appear before the weights for i+1. Similarly, for a given value of i, the indices of beta corresponding to elements of the vector result are in the same order as for the vector result.- Parameters:
results
- the sum of beta[i+m]*B(i,n,x) for i in [0,n];beta
- the weights for each polynomial listed in the order specified abovem
- the offset into the beta array in multiples of the length of the vector resultn
- The degree of the Bernstein polynomialsx
- the value at which to evaluate the polynomials- Throws:
IllegalArgumentException
- an argument was out of bounds
-
dIsumBdxI
public static double dIsumBdxI(int I, double[] beta, int n, double x) throws IllegalArgumentException Compute the Ith derivative of a weighted sum of Bernstein polynomials of the same degree. The implementation uses De Casteljau's algorithm, which is fast and numerically stable. The length of the array beta must be at least n+1. Indices larger than n+1 are ignored.- Parameters:
I
- the number of times to differentiatebeta
- the weights for each polynomialn
- The degree of the Bernstein polynomialsx
- the argument- Returns:
- the second derivative of the sum of beta[i]*B(i,n,x) for i in [0,n]
- Throws:
IllegalArgumentException
- an argument was out of bounds
-
dIsumBdxI
public static void dIsumBdxI(double[] results, double[] beta, int m, int n, double x, int I) throws IllegalArgumentException Compute the Ith derivative of a weighted sum of Bernstein polynomials of the same degree for each component of an array of arguments, specifying an offset into the array representing weights. The implementation uses De Casteljau's algorithm, which is fast and numerically stable. The length of the array beta must be at least (m + (n+1)) multiplied by the length of the "result" argument vector. Indices larger than n+1 are ignored. The array beta contains the weights for each element of the argument array result and for each Bernstein polynomial Bi,n, ordered so that the weights for each element of result and a given value of i appear before the weights for i+1. Similarly, for a given value of i, the indices of beta corresponding to elements of the vector result are in the same order as for the vector result.- Parameters:
results
- the sum of beta[i+m]*B(i,n,x) for i in [0,n];beta
- the weights for each polynomial listed in the order specified abovem
- the offset into the beta array in multiples of the length of the vector resultn
- The degree of the Bernstein polynomialsx
- the value at which to evaluate the polynomialsI
- the degree of the derivative- Throws:
IllegalArgumentException
- an argument was out of bounds
-
indexForLambdas
Get an index representing a sequence of m values λ0, λ1, ..., λm-1, for which λi ∈ [0, n] for i ∈ [0, m) and such that the sum of λi (i ∈ [0, m)) is n.The index returned for a set of lambdas is encoded in a way that makes it easy to generate the the corresponding lambda values for a given value of n and m. Valid values for an index are in general not contiguous integers.
- Parameters:
n
- the maximum allowed value for λi for i ∈ [0, m)lambdas
- the values λ0, λ1, ... in that order- Returns:
- the index for the given arguments
- Throws:
IllegalArgumentException
- an argument was out of bounds
-
lambdasForIndex
Get the sequence of m values corresponding to an index. This is the inverse ofindexForLambdas(int, int...)
as a function of the vector λ.- Parameters:
n
- the maximum allowed value for λi for i ∈ [0, n]len
- the number of components of the vector λindex
- the index- Returns:
- an array whose components are λ0, λ1, ... in that order
- Throws:
IllegalArgumentException
- an argument was out of bounds
-
lambdasForIndex
Get the sequence of m values corresponding to an index, storing the results in an array of length m that is explicitly provided. This is the inverse ofindexForLambdas(int, int...)
as a function of the vector λ.- Parameters:
n
- the maximum allowed value for λi for i ∈ [0, n]results
- an array whose components will contain λ0, λ1, ... in that orderindex
- the index- Throws:
IllegalArgumentException
- an argument was out of bounds
-
generateIndices
Generate a list of all the valid indices. An index if valid if the corresponding vector λ's components satisfy two constraints:- λi ∈ [0, n].
- ∑i=0m-1 λi = n
The indices generated, for a give value of n and m are not contiguous but are ordered. These indices can also be easily converted to a factor containing the λ's.
- Parameters:
n
- the maximum value of a component of λ (inclusive)len
- the number of λ components (m in the description above)- Returns:
- the valid indices
- Throws:
IllegalArgumentException
- an argument was out of bounds- See Also:
-
generateIndices
Generate a list of all the valid indices. An index if valid if the corresponding vector λ's components satisfy two constrains:- λi ∈ [0, n].
- ∑i=0m-1 λi = m
- Parameters:
n
- the maximum value of a component of λm
- the maximum value of the sum of λ componentslen
- the number of λ components.- Returns:
- the valid indices
- Throws:
IllegalArgumentException
- an argument was out of bounds- See Also:
-
sumB
Compute a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates. The sum is given by ∑λβλBnλ(τ) where τ is a vector (x0, x1, ... ,xm) and m is the number of arguments represented by the variable-length argument x. The methodgenerateIndices(n, m)
will create an array of indices that represent values of λ andgenerateIndices(n, m, index)
will return an array containing the components of λ corresponding to the index. The jth element of beta must contain the value βλ for the vector λ associated with the jth entry of the list of indices described above.- Parameters:
beta
- the weightsn
- the degree of the Bernstein polynomialsx
- the barycentric coordinates- Returns:
- the weighted sum of Bernstein polynomials for specified barycentric coordinates
- Throws:
IllegalArgumentException
- an argument was out of bounds
-
dsumBdx
public static double dsumBdx(int xInd, double[] beta, int n, double... x) throws IllegalArgumentException Compute a first partial derivative of a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates. The sum is given by ∑λβλBnλ(τ) where τ is a vector (x0, x1, ... ,xm) and m is the number of arguments represented by the variable-length argument x. The methodgenerateIndices(n, m)
will create an array of indices that represent values of λ andgenerateIndices(n, m, index)
will return an array containing the components of λ corresponding to the index. The jth element of beta must contain the value βλ for the vector λ associated with the jth entry of the list of indices described above.- Parameters:
xInd
- an index specifying that the partial derivative is computed with respect to xxIndbeta
- the weightsn
- the degree of the Bernstein polynomialsx
- the barycentric coordinates- Returns:
- the partial derivative of a weighted sum of Bernstein polynomials for specified barycentric coordinates
- Throws:
IllegalArgumentException
- an argument was out of bounds
-
d2sumBdxdy
public static double d2sumBdxdy(int xInd, int yInd, double[] beta, int n, double... x) throws IllegalArgumentException Compute a second partial derivative of a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates. The sum is given by ∑λβλBnλ(τ) where τ is a vector (x0, x1, ... ,xm) and m is the number of arguments represented by the variable-length argument x. The methodgenerateIndices(n, m)
will create an array of indices that represent values of λ andgenerateIndices(n, m, index)
will return an array containing the components of λ corresponding to the index. The jth element of beta must contain the value βλ for the vector λ associated with the jth entry of the list of indices described above.- Parameters:
xInd
- an index specifying that the 1st partial derivative in ∂2 / ∂xxInd∂xyInd is computed with respect to xxIndyInd
- an index specifying that the 2nd partial derivative in ∂2 / ∂xxInd∂xyInd is computed with respect to xyIndbeta
- the weightsn
- the degree of the Bernstein polynomialsx
- the barycentric coordinates- Returns:
- the partial derivative of a weighted sum of Bernstein polynomials for specified barycentric coordinates
- Throws:
IllegalArgumentException
- an argument was out of bounds
-
sumB
public static void sumB(double[] result, double[] beta, int n, double... x) throws IllegalArgumentException Compute a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates for each of a sequence of values. The sum is given by ∑λβλBnλ(τ) where τ is a vector (x0, x1, ... ,xm) and m is the number of arguments represented by the variable-length argument x. The methodgenerateIndices(n, m)
will create an array of indices that represent values of λ andlambdasForIndex(n, m, index)
will return an array containing the components of λ corresponding to the index. The jth element of beta for result element result[m] must contain the value βλ for the vector λ associated with the jth entry of the list of indices described above. These elements are stored in beta[k + j*result.length] for the computation of result[k].- Parameters:
result
- the weighted sum of Bernstein polynomials for specified barycentric coordinatesbeta
- the weightsn
- the degree of the Bernstein polynomialsx
- the barycentric coordinates- Throws:
IllegalArgumentException
- an argument was out of bounds
-
sumB
public static void sumB(double[] result, double[] beta, int offset, int n, double... x) throws IllegalArgumentException Compute a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates for each of sequence of values from an array, also specifying an offset into that array. The sum is given by ∑λβλBnλ(τ) where τ is a vector (x0, x1, ... ,xm) and m is the number of arguments represented by the variable-length argument x. The methodgenerateIndices(n, m)
will create an array of indices that represent values of λ andlambdasForIndex(n, m, index)
will return an array containing the components of λ corresponding to the index. The jth element of beta for result element result[m] must contain the value βλ for the vector λ associated with the jth entry of the list of indices described above. These elements are stored in beta[k + j*result.length] for the computation of result[k].Note: this method was created for use in the class
Surface3D
.- Parameters:
result
- an array that will hold the weighted sum of Bernstein polynomials for specified barycentric coordinatesbeta
- the weightsoffset
- the offset into the array beta from which the sequence of weights starts.n
- the degree of the Bernstein polynomialsx
- the barycentric coordinates- Throws:
IllegalArgumentException
- an argument was out of bounds
-
dsumBdx
public static void dsumBdx(int xInd, double[] result, double[] beta, int n, double... x) throws IllegalArgumentException Compute a first partial derivative of a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates for each of a sequence of values. The sum is given by ∑λβλBnλ(τ) where τ is a vector (x0, x1, ... ,xm) and m is the number of arguments represented by the variable-length argument x. The methodgenerateIndices(n, m)
will create an array of indices that represent values of λ andgenerateIndices(n, m, index)
will return an array containing the components of λ corresponding to the index. The jth element of beta for the result component result[m] must contain the value βλ for the vector λ associated with the jth entry of the list of indices described above. These elements are stored in beta[k + j*result.length] for the computation of result[k].- Parameters:
xInd
- an index specifying that the partial derivative is computed with respect to xxIndresult
- the partial derivative of a weighted sum of Bernstein polynomials for specified barycentric coordinatesbeta
- the weightsn
- the degree of the Bernstein polynomialsx
- the barycentric coordinates- Throws:
IllegalArgumentException
- an argument was out of bounds
-
dsumBdx
public static void dsumBdx(int xInd, double[] result, double[] beta, int offset, int n, double... x) throws IllegalArgumentException Compute a first partial derivative of a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates for each of a sequence of values, specifying an offset into the array providing the weights. The sum is given by ∑λβλBnλ(τ) where τ is a vector (x0, x1, ... ,xm) and m is the number of arguments represented by the variable-length argument x. The methodgenerateIndices(n, m)
will create an array of indices that represent values of λ andgenerateIndices(n, m, index)
will return an array containing the components of λ corresponding to the index. The jth element of beta for the result component result[m] must contain the value βλ for the vector λ associated with the jth entry of the list of indices described above. These elements are stored in beta[k + j*result.length] for the computation of result[k].- Parameters:
xInd
- an index specifying that the partial derivative is computed with respect to xxIndresult
- the partial derivative of a weighted sum of Bernstein polynomials for specified barycentric coordinatesbeta
- the weightsoffset
- the offset into the array beta at which the weights startn
- the degree of the Bernstein polynomialsx
- the barycentric coordinates- Throws:
IllegalArgumentException
- an argument was out of bounds
-
d2sumBdxdy
public static void d2sumBdxdy(int xInd, int yInd, double[] result, double[] beta, int n, double... x) throws IllegalArgumentException Compute a second partial derivative of a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates for each of a sequence of values. Bernstein polynomials of the same degree using barycentric coordinates. The sum is given by ∑λβλBnλ(τ) where τ is a vector (x0, x1, ... ,xm) and m is the number of arguments represented by the variable-length argument x. The methodgenerateIndices(n, m)
will create an array of indices that represent values of λ andgenerateIndices(n, m, index)
will return an array containing the components of λ corresponding to the index. The jth element of beta for the result component result[m] must contain the value βλ for the vector λ associated with the jth entry of the list of indices described above. These elements are stored in beta[k + j*result.length] for the computation of result[k].- Parameters:
xInd
- an index specifying that the 1st partial derivative in ∂2 / ∂xxInd∂xyInd is computed with respect to xxIndyInd
- an index specifying that the 2nd partial derivative in ∂2 / ∂xxInd∂xyInd is computed with respect to xyIndresult
- the partial derivative of a weighted sum of Bernstein polynomials for specified barycentric coordinatesbeta
- the weightsn
- the degree of the Bernstein polynomialsx
- the barycentric coordinates- Throws:
IllegalArgumentException
- an argument was out of bounds
-
d2sumBdxdy
public static void d2sumBdxdy(int xInd, int yInd, double[] result, double[] beta, int offset, int n, double... x) throws IllegalArgumentException Compute a second partial derivative of a weighted sum of Bernstein polynomials of the same degree using barycentric coordinates for each of a sequence of values, specifying an offset into the array providing the weights. Bernstein polynomials of the same degree using barycentric coordinates. The sum is given by ∑λβλBnλ(τ) where τ is a vector (x0, x1, ... ,xm) and m is the number of arguments represented by the variable-length argument x. The methodgenerateIndices(n, m)
will create an array of indices that represent values of λ andgenerateIndices(n, m, index)
will return an array containing the components of λ corresponding to the index. The jth element of beta for the result component result[m] must contain the value βλ for the vector λ associated with the jth entry of the list of indices described above. These elements are stored in beta[k + j*result.length] for the computation of result[k].- Parameters:
xInd
- an index specifying that the 1st partial derivative in ∂2 / ∂xxInd∂xyInd is computed with respect to xxIndyInd
- an index specifying that the 2nd partial derivative in ∂2 / ∂xxInd∂xyInd is computed with respect to xyIndresult
- the partial derivative of a weighted sum of Bernstein polynomials for specified barycentric coordinatesbeta
- the weightsoffset
- the offset into the array beta at which the weights startn
- the degree of the Bernstein polynomialsx
- the barycentric coordinates- Throws:
IllegalArgumentException
- an argument was out of bounds
-