Commit 6025fb41 authored by Dominik Widhalm's avatar Dominik Widhalm
Browse files

Improved example solution for task 6.01 (thanks to FG)

parent 5c7fb6b8
......@@ -63,9 +63,17 @@ double get_perimeter (struct triangle *trngl) {
double get_area (struct triangle *trngl) {
/* First calculate the height of the triangle */
double s = get_perimeter(trngl) / 2;
double h_c = (2.0 / trngl->c) * sqrt(s * (s-trngl->a) * (s-trngl->b) * (s-trngl->c));
/* Calculate the actual area using the height */
return ((trngl->c * h_c) / 2.0);
/* Calculate the actual area using the height (simplified) */
return sqrt(s * (s-trngl->a) * (s-trngl->b) * (s-trngl->c));
/* The calculation above is a simplified combination of the calculation of
* the height of the side c (h_c) and the area calculation based on h_c.
*
* double h_c = (2.0 / trngl->c) * sqrt(s * (s-trngl->a) * (s-trngl->b) * (s-trngl->c));
* double area = (trngl->c * h_c) / 2.0;
*
* If you use the equation for h_c in the equation for area, you can cross
* out (2.0 / trngl->c) with (trngl->c / 2.0)!
*/
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment