# Arduino TriangleSolver Library

The TriangleSolver library implements the necessary calculations to easily solve any type of triangle on a processor like Arduino.

It is designed to help in the resolution of robot kinematics and other types of articulated mechanisms in which, in many cases, it is necessary to repeatedly solve angles or lengths.

## User Manual

The TriangleSolver class contains the variables that define the triangle we want to solve. These variables are three side lengths (A, B, C) and the three angles opposite each side (Alpha, Beta, and Gamma) measured in radians, according to the following diagram.

To solve the triangle, it is necessary to assign any three variables of the triangle. Then, the rest are calculated using the Solve method. The calculated variables are those that have a value of 0.0.

In most cases, three variables allow determining the triangle. However, there are two special cases.

In the case of providing the three angles but no sides, the system allows infinite solutions and therefore cannot be solved.

Another special case is when providing an angle, the opposite side, and an adjacent side. In this case, the system allows two solutions, one forcing all angles to be acute, and another allowing an angle greater than 90º. To choose between both cases, the ‘Solve’ function accepts an optional ‘IsObtuse’ parameter.

To make the library as lightweight as possible, the calculation does not perform any error checking or verification. It will be the calling program’s responsibility to ensure that the parameters are correct and, if necessary, that the solution is valid.

Additionally, the library provides the UpdateN functions (where N represents the different triangle variables). These functions simply assign the value provided as a parameter to the corresponding function and set the opposite angle (or side) and the two adjacent angles to zero. The purpose of these functions is to allow for quick mechanism calculations.

### Constructor

The TriangleSolver class is instantiated through its constructor, which has no parameters.

TriangleSolver triang;

### Using SimpleStepper

//Calculate the missing variables in the triangle
bool Solve(bool preferObtuse = false);

//Triangle variables
float& A = sides[0];
float& B = sides[1];
float& C = sides[2];
float& Alpha = angles[0];
float& Beta = angles[1];
float& Gamma = angles[2];

//Update triangle variables
void UpdateA(float a) const
void UpdateB(float b) const
void UpdateC(float c) const
void UpdateAlpha(float alpha)
void UpdateBeta(float beta)
void UpdateGamma(float gamma)

## Examples

The TriangleSolver library includes the following examples to illustrate its use.

• TriangleSolver: Example that shows the basic usage of the library

TriangleSolver triang;

void debug()
{
Serial.println(triang.A, 4);
Serial.println(triang.B, 4);
Serial.println(triang.C, 4);
Serial.println(degrees(triang.Alpha), 4);
Serial.println(degrees(triang.Beta)), 4;
Serial.println(degrees(triang.Gamma), 4);
}

void setup() {
Serial.begin(115200);

triang.A = 50;
triang.C = 25.39;
triang.Solve(true);
debug();

}

void loop()
{
// do nothing
delay(1000);
}