anlyx

4_RA

Oct 24th, 2021
934
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Window to ViewPort Transformation
  2. using System;
  3.  
  4. class GFG
  5. {
  6.  
  7. // Function for window to viewport transformation
  8. static void WindowtoViewport(int x_w, int y_w,
  9.                             int x_wmax, int y_wmax,
  10.                             int x_wmin, int y_wmin,
  11.                             int x_vmax, int y_vmax,
  12.                             int x_vmin, int y_vmin)
  13. {
  14.     // point on viewport
  15.     int x_v, y_v;
  16.  
  17.     // scaling factors for x coordinate
  18.     // and y coordinate
  19.     float sx, sy;
  20.  
  21.     // calculatng Sx and Sy
  22.     sx = (float)(x_vmax - x_vmin) /
  23.                 (x_wmax - x_wmin);
  24.     sy = (float)(y_vmax - y_vmin) /
  25.                 (y_wmax - y_wmin);
  26.  
  27.     // calculating the point on viewport
  28.     x_v = (int) (x_vmin +
  29.         (float)((x_w - x_wmin) * sx));
  30.     y_v = (int) (y_vmin +
  31.         (float)((y_w - y_wmin) * sy));
  32.  
  33.     Console.Write("The point on viewport: " +
  34.                 "({0}, {1} )\n ", x_v, y_v);
  35. }
  36.  
  37. // Driver Code
  38. public static void Main(String[] args)
  39. {
  40.  
  41.     // boundary values for window
  42.     int x_wmax = 80, y_wmax = 80,
  43.         x_wmin = 20, y_wmin = 40;
  44.  
  45.     // boundary values for viewport
  46.     int x_vmax = 60, y_vmax = 60,
  47.         x_vmin = 30, y_vmin = 40;
  48.  
  49.     // point on window
  50.     int x_w = 30, y_w = 80;
  51.  
  52.     WindowtoViewport(30, 80, 80, 80, 20,
  53.                     40, 60, 60, 30, 40);
  54. }
  55. }
RAW Paste Data