home *** CD-ROM | disk | FTP | other *** search
/ vis-ftp.cs.umass.edu / vis-ftp.cs.umass.edu.tar / vis-ftp.cs.umass.edu / pub / Software / ASCENDER / ascendMar8.tar / UMass / BuildingFinder / Staging / LineSegColIntercept.c < prev    next >
C/C++ Source or Header  |  1995-06-06  |  2KB  |  90 lines

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2.  
  3. Name : LineSegColIntercept
  4. Type : int
  5. Written on   : 20-Nov-90     By : A. Etemadi
  6. Modified on  :               By : 
  7. Directory    : ~ees1ae/vap/PerceptualGrouping/LPEG/src/LineRoutines
  8.  
  9. ==============================================================================
  10.  
  11. Input parameters    : 
  12.  
  13.  StartCol        -- The column number of the start point of the line
  14.  StartRow        -- The row number of the start point of the line
  15.  EndCol        -- The column number of the end point of the line
  16.  EndRow        -- The row number of the end point of the line 
  17.  
  18. Output result       : 
  19.  
  20.  -1 = Intercept point is at infinity (ie line is horizontal)
  21.   0 = successful in calculating gradient
  22.  
  23. Output parameters   :
  24.  
  25.  ColIntercept        -- Intercept of the line (y = m.x + c) with x axis
  26.  
  27. Calling procedure:
  28.  
  29.  double StartCol;
  30.  double StartRow;
  31.  double EndCol;
  32.  double EndRow;
  33.  
  34.  double ColIntercept;
  35.  
  36.  LineSegColIntercept( StartCol,
  37.                StartRow,
  38.              EndCol,
  39.                    EndRow,
  40.             &ColIntercept)
  41.  
  42. Functionality: 
  43.  
  44. This function finds the Intercept point of a line with the x axis, given 
  45. any two points that lie along the line. 
  46.  
  47. ----------------------------------------------------------------------------*/
  48.  
  49. #include <stdio.h>     /* Standard C I/O library */
  50. #include <math.h>      /* Standard C mathematics library */
  51. #include <errno.h>     /* Standard C error handling routines */
  52. /* #include <strings.h> */   /* Standard C string handling routines */
  53. #include <ctype.h>     /* Standard C type identification routines */
  54. #include "../header.h"
  55.  
  56. int LineSegColIntercept(double StartCol,
  57.                double StartRow,
  58.               double  EndCol,
  59.                double EndRow,
  60.                double *ColIntercept)
  61.  
  62. {
  63.  
  64. #ifdef debug
  65.           fprintf(stderr," Start of function LineSegColIntercept \n");
  66. #endif
  67.  
  68.     if (EndCol == StartCol) {     /* Line is vertical */
  69.     *ColIntercept = StartCol; 
  70.     return(0);
  71.     }
  72.  
  73.     if ( EndRow != StartRow) {    /* Line is not horizontal */
  74.     *ColIntercept = (StartCol*EndRow - EndCol*StartRow)/
  75.                   (EndRow - StartRow); 
  76.     return(0);
  77.     }
  78.  
  79.   *ColIntercept = HUGE;     /* Line is horizontal */
  80.  
  81.  
  82.   return(-1);
  83.  
  84. #ifdef debug
  85.           fprintf(stderr," End of function LineSegColIntercept \n");
  86. #endif
  87.  
  88. }
  89.  
  90.