# Arduino Library for the Stewart Flight Simulator Platform — Part 2

--

Part 2 demonstrates the techniques used for finding the centre of gravity of our top and bottom hexagonal platforms and how to calculate the co-ordinates of the connection points on each edge. This step is glossed over by everyone! It is not until you try to actually code the formulaes that you realise that you need the co-ordinates of the twelve connection points on both platforms.

## Finding the Centroid / Centre of Gravity (COG)

In order to apply the inverse kinematic transformations described in Part 3, we need the co-ordinates of the connection points on the top and bottom platforms. We will start with the top platform because that is straight forward. Finding the vertices of our irregular hexagonal platform, allows us to calculate the **centroid** (the centre of mass of a geometric object of uniform density). The centroid is where the x, y, and z axes have their origin, when performing the inverse kinematic.

Figure 9 illustrates the problem, all measurements are in millimetres, and the angles are in degrees. We need to find the length of the sides of triangles **A** and **B**. Trigonometry to the rescue! For **A**:

`cos 60 = x/40`

or `x = 40 cos 60 = 20`

`sin 60 = y/40`

or `y = 40 sin 60 = 34.64`

For Triangle **B**:

`cos 60 = x/85`

or `x = 85 cos 60 = 42.5`

`sin 60 = y/85`

or `y = 85 sin 60 = 73.61`

Similarly, for the bottom platform triangle **C**:

`x = 62 cos 60 = 31`

`y = 62 sin 60 = 53.69`

For Triangle **D**:

`x = 90 cos 60 = 45`

`y = 90 sin 60 = 77.94`

The top platform vertices in counter-clockwise (ccw) order are **{(20, 0), (105, 0), (125, 34.64), (82.5, 108.25), (42.5, 108.25), (0, 34.64)}**. The bottom platform vertices are **{(31, 0), (121, 0), (152, 53.69), (107, 131.63), (45, 131.63), (0, 53.69)}**.

To calculate the COG co-ordinates for this hexagon, we will use the code from…