[ create a new paste ] login | about

Link: http://codepad.org/ks2gJ0sA    [ raw code | output | fork ]

anmartex - C++, pasted on Apr 17:
#include <iostream>
#include <cmath>

float Radius(float a, float b, float c)
{
   float p = a + b + c;

   return std::sqrt((p - a) * (p - b) * (p - c) / p);
}

int main()
{
   float edges[] = { 3.0, 4.0, 5.0,
                     8.0, 3.0, 8.0,
                     4.0, 4.0, 5.0,
                     3.0, 3.0, 3.0,
                     9.0, 9.0, 1.0 };

   size_t nEdges = sizeof(edges) / sizeof(*edges);

   size_t maxIndex = 0;
   float maxRadius = Radius(edges[maxIndex], edges[maxIndex + 1], edges[maxIndex + 2]);

   for (size_t i = 0; i <= nEdges - 3; i += 3)
   {
      float radius = Radius(edges[i], edges[i + 1], edges[i + 2]);
      std::cout << "a = " << edges[i]     << ", "
                << "b = " << edges[i + 1] << ", "
                << "c = " << edges[i + 2] << ", "
                << "radius = " << radius << std::endl;

      if (maxRadius < radius)
      {
         maxIndex = i;
         maxRadius = radius;
      }
   }

   std::cout << std::endl
             << "maximal: "
             << "a = " << edges[maxIndex]     << ", "
             << "b = " << edges[maxIndex + 1] << ", "
             << "c = " << edges[maxIndex + 2] << ", "
             << "radius = " << maxRadius << std::endl;

   return 0;
}


Output:
1
2
3
4
5
6
7
a = 3, b = 4, c = 5, radius = 6.48074
a = 8, b = 3, c = 8, radius = 10.0943
a = 4, b = 4, c = 5, radius = 7.06018
a = 3, b = 3, c = 3, radius = 4.89898
a = 9, b = 9, c = 1, radius = 9.73328

maximal: a = 8, b = 3, c = 8, radius = 10.0943


Create a new paste based on this one


Comments: