Info3 homework — Geometry projects

Date: March 19, 2020

Author: Gábor P. Nagy

Introduction

In this exercise, we want to compute different measurements of a triangle, which is given either by three sides or by the coordinates of the three vertices. Our basic program inputs the three sides a, b, c and checks if they satisfy the triangle inequality.

Save this file on your computer, compile it and run with different input.

Numerics library

In order to use common mathematical operations and transformations, you must include the <cmath> numerics library.

Notice that the value of π is stored in the constant double precision variable PI. It is calculated using the fact that the tangent of π / 4 is equal to 1.

Exercises

  1. In the program geom_triangle_inequality.cxx we did not check if the sides are negative. Why?

  2. Modify the program numerics_cos.cxx such that π is computed using cos(π) = -1.

  3. Modify the program geom_triangle_inequality.cxx such that for proper triangles, it also prints the area of the triangle. Use Heron's_formula to compute the area:

    where

  4. Modify the program geom_triangle_inequality.cxx such that it inputs the coordinates of the three vertices and it outputs the perimeter of the triangle. Use Pythagoras' theorem to compute the sides.

  5. Modify the program geom_triangle_inequality.cxx such that it inputs the coordinates of the three vertices and it outputs the area of the triangle. You can either compute the sides first and then use Heron's formula. Or, you use the fact that in the plane, the (signed) area of a parallelogram is equal to the 2x2 determinant, with rows as spanning vectors. Hence,

  6. Modify the program geom_triangle_inequality.cxx such that it inputs the coordinates of the three vertices and it outputs the radius of the inscribed circle of the triangle. Compute the area A and use the equation

    to find the radius.

Homeworks


  1. Modify the program geom_triangle_inequality.cxx such that it inputs the coordinates of the three vertices and it outputs the radius and center of the inscribed circle of the triangle.
  2. Modify the program geom_triangle_inequality.cxx such that it inputs the coordinates of the three vertices and it outputs the radius and center of the escribed circle of the triangle.
  3. Modify the program geom_triangle_inequality.cxx such that it inputs the coordinates of the three vertices and it outputs the coordinates of the orthocenter of the triangle. Pay attention to check the input.
  4. Modify the program geom_triangle_inequality.cxx such that it inputs the coordinates of the three vertices and it outputs if the orientation of the vertices is positive or negative.
  5. Modify the program geom_triangle_inequality.cxx such that it inputs the coordinates of the three vertices and it outputs whether the origin is contained in the triangle.