home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / PLOT / SURFUTI3.ZIP / SCSHROT.INC < prev    next >
Encoding:
Text File  |  1990-09-03  |  3.2 KB  |  121 lines

  1. { procedures SCALENODES, SHIFTNODES, and ROTATENODES }
  2.  
  3. procedure SCALENODES (Firstnode, Lastnode: integer; Scale: vector);
  4. { Scale all nodes in this solid by the factors specified }
  5.  
  6. var Axis:       integer;  { axis to scale on }
  7.     Node:       integer;  { node # }
  8.  
  9. begin
  10. {$ifdef BIGMEM}
  11. with ptra^ do
  12. begin
  13. {$endif}
  14.   for Axis := 1 to 3 do
  15.     if (Scale[Axis] <> 0.0) and (Scale[Axis] <> 1.0) then
  16.       for Node := Firstnode to Lastnode do
  17.         World[Node][Axis] := World[Node][Axis] * Scale[Axis];
  18.       { for Node }
  19.     { if Scale... }
  20.   { for Axis }
  21. {$ifdef BIGMEM}
  22. end; {with}
  23. {$endif}
  24. end; { procedure SCALENODES }
  25.  
  26. procedure SHIFTNODES (Firstnode, Lastnode: integer; Shift: vector);
  27. { Shift all nodes in this solid by the vector specified }
  28.  
  29. var Axis:       integer;  { axis to scale on }
  30.     Node:       integer;  { node # }
  31.  
  32. begin
  33. {$ifdef BIGMEM}
  34. with ptra^ do
  35. begin
  36. {$endif}
  37.   for Axis := 1 to 3 do
  38.     if (Shift[Axis] <> 0.0) then
  39.       for Node := Firstnode to Lastnode do
  40.         World[Node][Axis] := World[Node][Axis] + Shift[Axis];
  41.       { for Node }
  42.     { if Scale... }
  43.   { for Axis }
  44. {$ifdef BIGMEM}
  45. end; {with}
  46. {$endif}
  47. end; { procedure SHIFTNODES }
  48.  
  49. function ATAN2 (Y, X: real): real;
  50. { returns the arc-tangent, in radians, of Y/X, in the range of -PI to PI. }
  51.  
  52. const PI = 3.141592654;
  53. begin
  54.   if (Y = 0.0) then begin
  55.     if (X >= 0.0) then
  56.       ATAN2 := 0.0
  57.     else
  58.       ATAN2 := PI;
  59.   end else if (Y > 0) then begin
  60.     if (X = 0.0) then
  61.       ATAN2 := PI / 2.0
  62.     else if (X > 0.0) then
  63.       ATAN2 := arctan (Y / X)
  64.     else
  65.       ATAN2 := PI - arctan (Y / -X);
  66.   end else begin
  67.     if (X = 0.0) then
  68.       ATAN2 := -PI / 2.0
  69.     else if (X > 0.0) then
  70.       ATAN2 := arctan (Y / X)
  71.     else
  72.       ATAN2 := -PI + arctan (Y/ X);
  73.   end; { if Y }
  74. end; { procedure ATAN2 }
  75.  
  76. procedure ROTATENODES (Firstnode, Lastnode: integer; Rotate: vector);
  77. { Rotate all nodes in this solid by the rotation vector specified }
  78.  
  79. var Anglerad:   real;     { angle in radians }
  80.     Node:       integer;  { node # }
  81.     Axis:       integer;  { axis to rotate about }
  82.     A1, A2:     integer;  { other two axes }
  83.     Dist:       real;     { distance to X,Y coord }
  84.     Theta2:     real;     { new angle, after rotating }
  85.  
  86. begin
  87. {$ifdef BIGMEM}
  88. with ptra^ do
  89. begin
  90. {$endif}
  91.   for Axis := 1 to 3 do begin
  92.     if (Rotate[Axis] <> 0.0) then begin
  93.       { Convert degrees to radians }
  94.       Anglerad := 3.141592654 * Rotate[Axis] / 180.0;
  95.       for Node := Firstnode to Lastnode do begin
  96.         case Axis of
  97.         1: begin
  98.              A1 := 2;
  99.              A2 := 3;
  100.            end;
  101.         2: begin
  102.              A1 := 3;
  103.              A2 := 1;
  104.            end;
  105.         3: begin
  106.              A1 := 1;
  107.              A2 := 2;
  108.            end;
  109.         end; { case Axis of }
  110.         Dist := sqrt (sqr(World[Node][A1]) + sqr(World[Node][A2]));
  111.         Theta2 := atan2 (World[Node][A2], World[Node][A1]) + Anglerad;
  112.         World[Node][A1] := Dist * cos(Theta2);
  113.         World[Node][A2] := Dist * sin(Theta2);
  114.       end; { for Node }
  115.     end; { if Rotate[Axis] }
  116.   end; { for Axis }
  117. {$ifdef BIGMEM}
  118. end; {with}
  119. {$endif}
  120. end; { procedure ROTATENODES }
  121.