home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / 3PTPAS.ZIP / 3PTPAS.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1992-12-21  |  2.9 KB  |  101 lines

  1. {================================================}
  2. {     This program is taken from the book,       }
  3. { "PASCAL programs in science and engineering"   }
  4. {    by Jules H. Gilder & J. Scott Barrus        }
  5. {   Published by, HAYDEN ISBN 0-8104-6265-6      }
  6. {                                                }
  7. {================================================}
  8. {                                                }
  9. { Title:  Circle Finder                          }
  10. {                                                }
  11. { Program Summary: Program will find the center  }
  12. { and radius of a circle that is formed by three }
  13. { points not in a straight line.                 }
  14. {                                                }
  15. {================================================}
  16.  
  17. Program Circle_Finder;
  18.  
  19.  uses Crt;
  20.  
  21.   var
  22.     answer,
  23.     cont     : Char;
  24.     out      : Text;
  25.     X1,X2,X3,
  26.     Y1,Y2,Y3,
  27.     Part1,
  28.     Part2,
  29.     Part3,
  30.     Part4,
  31.     X,Y,
  32.     Radius   : Real;
  33.  
  34. Procedure Title;
  35.    begin
  36.         Clrscr;
  37.         Writeln;
  38.         Writeln('Circle Finder');
  39.         Writeln;Writeln;
  40.         Writeln('This program will find the center and');
  41.         Writeln('radius of a circle that is determined');
  42.         Writeln('by any three points in a plane that ');
  43.         Writeln('does not form a straight line.');
  44.         Writeln;
  45.         Writeln('Note: For all entries that require');
  46.         Writeln('      data entries (x,y); separate ');
  47.         Writeln('      all data with a space.');
  48.         Writeln;Writeln;
  49.    end;  { Title }
  50.  
  51. Procedure Input;
  52.   begin
  53.      Write('Enter first point  (X,Y):   ');
  54.      Readln(X1,Y1);
  55.      Write('Enter second point (X,Y):   ');
  56.      Readln(X2,Y2);
  57.      Write('Enter third point  (X,Y):   ');
  58.      Readln(X3,Y3);
  59.      Writeln;Writeln;Writeln;
  60.   end;
  61.  
  62. Procedure Find;
  63.    begin
  64.      Part1 := ((X2-X1) * (X2+X1) + (Y2-Y1) * (Y2 + Y1)) / (2.0 * (X2-X1));
  65.      Part2 := ((X3-X1) * (X3+X1) + (Y3-Y1) * (Y3 + Y1)) / (2.0 * (X3-X1));
  66.      Part3 := (Y2 - Y1) / (X2 - X1);
  67.      Part4 := (Y3 - Y1) / (X3 - X1);
  68.      Y := (Part2 - Part1) / (Part4 - Part3);
  69.      X := Part2 - Part4 * Y;
  70.      Radius := SQRT (SQR (X3 - X) + SQR (Y3 - Y));
  71.    end;
  72.  
  73. Procedure Print1;
  74.    begin
  75.       Writeln('The circle defined by the following');
  76.       Writeln('three points:');
  77.       Writeln;
  78.       Writeln(' X1 = ',X1:7:4,' Y1 = ',Y1:7:4);
  79.       Writeln(' X2 = ',X2:7:4,' Y2 = ',Y2:7:4);
  80.       Writeln(' X3 = ',X3:7:4,' Y3 = ',Y3:7:4);
  81.       Writeln;
  82.       Writeln('has a radius = ',Radius:4:4);
  83.       Writeln;
  84.       Writeln('at a center located at:');
  85.       Writeln;
  86.       Writeln(' X = ',X:4:4,'    Y = ',Y:4:4);
  87.    end; { Print1 }
  88.  
  89. begin  { Main }
  90.   Repeat
  91.         Title;
  92.            Writeln;Writeln;
  93.         Input;
  94.         Find;
  95.         Print1;
  96.           Writeln;Writeln;
  97.           Write('Do you have another 3 points? (Y/N)');
  98.           Readln(cont);
  99.    Until cont in ['n','N'];
  100. end.
  101.