66 lines
3.1 KiB
Markdown
66 lines
3.1 KiB
Markdown
## How does it work?
|
|
|
|
The underlying mathematical principal used is trigonometry. It assumes, that a reference height is known. This could be a stick of a known length leaned against the tree as optical marker, or an actual marker on the tree at a known height. Given that known height, the height of the entire tree can be calculated without actually knowing the distance to the tree.
|
|
|
|
The implementation was inspired by the formulas and explanations given at the [AWF-Wiki of University of Göttingen](http://wiki.awf.forst.uni-goettingen.de/wiki/index.php/The_trigonometric_principle). They present the following formulas in more detail and with nice pictures, so go there to learn more!
|
|
|
|
### Definitions for the calculation
|
|
|
|
- $l$: the reference height in meters,
|
|
- $e$: the distance to the tree in meters
|
|
- $\alpha1$: the angle between horizontal line and top of tree,
|
|
- $\alpha2$: the angle between horizontal line and bottom of tree,
|
|
- $\alpha3$: the angle between horizontal line and top of reference height
|
|
|
|
### Formulas and Calculations
|
|
The reference height $l$ can be calulated like this:
|
|
|
|
$l = e * (tan (\alpha 1) - tan(\alpha 2))$
|
|
|
|
By transforming the formula (with given $l$), the distance to the tree can be caculated like so:
|
|
|
|
$e = \frac{l}{tan (\alpha 1) - tan(\alpha 2)}$
|
|
|
|
The actual tree height $h$ is constructed of
|
|
|
|
- $h1$: the distance between horizontal and top of tree, and
|
|
- $h2$: the distance between horizontal and the bottom of the tree
|
|
|
|
and can be calculated as such:
|
|
|
|
$h = h1 - h2$
|
|
|
|
$h1 = e * tan(\alpha1)$
|
|
|
|
$h2 = e * tan(\alpha2)$
|
|
|
|
Thus, with the formula for $e$, we get the following final formula.
|
|
|
|
$h = h1 - h2 = (e * tan(\alpha1)) - (e * tan(\alpha2))$
|
|
|
|
$= \frac{l}{tan (\alpha 1) - tan(\alpha 2)} * tan(\alpha1) - \frac{l}{tan (\alpha 1) - tan(\alpha 2)} * tan(\alpha2)$
|
|
|
|
### Considerations in implementation
|
|
To get correct results, the following things have additonally been implemented.
|
|
|
|
#### Corrections for display in degrees
|
|
When using the integrated motion sensors, the iPhone measures angles in radians. When converting those to degrees, they will repeat when looking down or up (as they are the "difference" to the horizontal line). So we must determine if we are actually looking "up" or "down" (using the gravity "z" angle of the motion sensor) and apply a transformation.
|
|
|
|
This was done like this:
|
|
|
|
a) First, convert to degrees:
|
|
|
|
$\alpha1(deg)=alpha1(rad) * \frac{180}{\pi}$
|
|
|
|
b) next, if we are looking "up", tranform it to be the correct angle:
|
|
|
|
$\alpha1(deg) = 180 - alpha1(deg)$
|
|
|
|
#### Angle corrections to allow all possibilities of tree location
|
|
Depending on whether the different angles are located - above or below the horizontal line - (when the iPhone is hold in portrait orientation, these are - in degrees - 90°) the angles have to be multiplied by `-1` as needed
|
|
- if looking "up", multiply by `-1`, if looking down, keep the original radian value.
|
|
|
|
#### Corrections for negative values
|
|
Depending on whether certain angles are above or below the horizontal line one would get negative values in some cases. This is why at many places I used `abs` to only get the numbers in a positive range.
|
|
|