{$80286,check,double [a+,b+,l-,o=120,n+,r+,u-] Oregon Software Compiler options} PROGRAM labcoord(input, output); {-----------------------------------------------------------------------------} { Pascal Translation of LABCOORD.FOR by Andrew Dainis 5-DEC-88 } { } { "A good programmer can write FORTRAN programs in any language." } {-----------------------------------------------------------------------------} CONST pi = 3.1415926; VAR s12, s23, s34, s14, s13, s24: REAL; a, w, cs34, x3, y3, x4, y4: REAL; FUNCTION acos(x: REAL): REAL;{Arc Cosine function} BEGIN acos := 1.5708 - 2 * ARCTAN(x / (1 + SQRT(1 - x * x))) END; PROCEDURE strike_any_key; VAR ch: char; BEGIN Writeln; Writeln; write(' Hit to continue'); read(ch); Writeln END; BEGIN{Main} Writeln; Writeln(' LABCOORD ... Pascal-2 version 24-Jul-95.'); Writeln; Writeln; Writeln(' This program will calculate the X,Y coordinates of four points given the'); Writeln(' the six distances between the points (four sides and two diagonals).'); Writeln; Writeln(' Point 1 is made the coordinate system origin, and point 2 is placed on the'); Writeln(' positive Y-axis. The measurements 1-2, 2-3, 3-4, 4-1, 1-3, and 2-4 are'); Writeln(' assumed to be entered in that order and the first five are used to compute'); Writeln(' the point coordinates. The sixth distance is computed from the first five'); Writeln(' and should agree with the measured distance between points 2 and 4.'); Writeln; Writeln(' The points are read clockwise starting at the origin and are all assumed'); Writeln(' to lie in the Z plane.'); strike_any_key; Writeln; Writeln(' Enter the distances in millimeters.'); Writeln; write(' Enter the distance between points 1 and 2 [mm] :'); Readln(s12); write(' Enter the distance between points 2 and 3 [mm] :'); Readln(s23); write(' Enter the distance between points 3 and 4 [mm] :'); Readln(s34); write(' Enter the distance between points 4 and 1 [mm] :'); Readln(s14); write(' Enter the distance between points 1 and 3 [mm] :'); Readln(s13); write(' Enter the distance between points 2 and 4 [mm] :'); Readln(s24); IF (s12 < 100.0) OR (s23 < 100.0) OR (s34 < 100.0) OR (s14 < 100.0) THEN BEGIN Writeln; Writeln(' Warning - the results may not be accurate if any side is less than 100mm!'); Writeln; END; a := (s12 * s12 + s14 * s14 - s24 * s24) / (2.0 * s12 * s14); w := acos(a); IF (a < 0) THEN w := pi - w;{ a > 90 degrees } w := pi / 2.0 - w; x4 := s14 * COS(w); y4 := s14 * SIN(w); IF (a < 0) THEN y4 := - y4; a := (s12 * s12 + s23 * s23 - s13 * s13) / (2.0 * s12 * s23); w := acos(a); IF (a < 0) THEN w := pi - w; w := w - pi / 2.0; x3 := s23 * COS(w); y3 := s12 + s23 * SIN(w); IF (a < 0) THEN y3 := s12 - s23 * SIN(w); cs34 := SQRT((x4 - x3) * (x4 - x3) + (y4 - y3) * (y4 - y3)); a := cs34 - s34; Writeln; IF (ABS(a) < 4.999) THEN BEGIN Writeln(' X Y'); Writeln(' Point 1 is located at 0.0 0.0'); Writeln(' Point 2 is located at 0.0', s12: 7: 1); Writeln(' Point 3 is located at', x3: 7: 1, y3: 7: 1); Writeln(' Point 4 is located at', x4: 7: 1, y4: 7: 1); Writeln; write(' The calculated distance between points 2 to 4 is'); IF (a < 0) THEN Writeln(' longer')ELSE Writeln(' shorter'); a := ABS(a); Writeln(' than the measured distance by ', a: 3: 2, ' mm.'); Writeln; IF (a < 0.5) THEN Writeln(' Accept this result.') ELSE Writeln(' If you remeasure the distances you may be able to obtain a better result.'); END ELSE BEGIN Writeln(' The difference between the calculated diagonal distance and the measured'); Writeln(' distance is greater than 5mm - you have either entered the distances'); Writeln(' incorrectly or else made a large error when you made the measurements.'); END; Strike_any_key; END{main} .