Chapter 17. The Math Sub-API

Table of Contents

Using Polynomials
Solving Linear Equations
Using Class Transform2D
Properties Of Affine Transformations

The math sub-API features a class to handle affine transformations and a number of utility methods. The affine transformations implemented in the Tensegrity API are capable of 2-dimensional coordinate transformations. They offer an enhanced set of methods compared to the standard class java.awt.geom.AffineTransform , especially for bulk transformations of arrays of coordinates.

Using Polynomials

The Polynomial class provides the functionality for multiplying and dividing polynomials with polynomials and monomials. Polynomials and their derivatives can be evaluated at arbitrary points and, most of all, they can be solved. Note that for quadratic polynomials, there is a specialized and extra stable method in class MathUtil, which is more appropriate for solving quadratic polynomials than using the method from the Polynomial class, which works for arbitrary degree polynomials.

Below follows an example of how to use the class Polynomial

Example 17.1. Using and solving polynomials

// construct f(x) = 2x^3 + x^2 + x - 2
Polynomial p= new Polynomial(new double[]{ - 2.0, 1.0, 1.0, 2.0});
// multiply with monomial factor (x - 3)
p.multiplyMonomial(3);

// now find the roots of the polynomial between -1E10 and 1E10
// with an accuracy of 0.000000000001
ArrayListDouble roots= p.solve(- 1E10, 1E10, 0.000000000001);
for(int i= 0; i< roots.size(); ++ i)
{
    // round results
    roots.set(i, Math.round(roots.get(i)));
}