title: Distance from a point to a line/segment
body: <p>I have to compute the distance from a point to a line (check if it is line or a line segment). I am not sure that the bool function IsSegment is working properly. Can i have some suggestions? Thank you.</p>
  
  <pre><code>double Distance_From_Line_to_Point(int *a, int *b, int *c, bool IsSegment) {
      double distance;
      int dot1;
      int dot2;
      distance = Cross_Product(a, b, c) / Distance(a, b);
      if (IsSegment(a,b,c) == true) {
          dot1 = Dot_Product(a, b, c);
          if (dot1 &gt; 0) {
              return Distance(b, c);
          }
          dot2 = Dot_Product(b, a, c);
          if (dot2 &gt; 0) {
              return Distance(a, c);
          }
      }
      return fabs(distance);
  }
  
  bool IsSegment(int *a, int *b, int *c) {
      double angle1;
      double angle2;
      angle1 = atan(double(b[1] - a[1]) / (b[0] - a[0]));
      angle2 = atan(double(c[1] - b[1]) / (c[0] - b[0]));
      if ((angle2 - angle1) * (180 / PI) &gt; 90) {
          return false;
      }
      return true;
  }
  </code></pre>