jDSGI - Java2D DATA Step Graphics Interface
  Back - Next   [ 6 of 27 ]
image  
by Richard A. DeVenezia, Copyright 2004  HOME
/*
 * Richard A. DeVenezia
 * June 1, 2004
 *
 * jDSGI test 6
 */

data _null_;

 %*
  * geometric model based of formulas found at
  * http://mathworld.wolfram.com/Ellipse.html formula #25
  * (polar coordinate form where theta is measured from the
  * center of the ellipse)
  *
  *;

  if symexist('goutpath') then goutpath=symget('goutpath'); else goutpath=pathname('WORK');
  if symexist ('gsftype') then gsftype=symget('gsftype'); else gsftype='png';

  gsf = cats(goutPath,"\","test6");

  width  = 500;
  height = 500;

  %canvas (_g, width, height, 0ffffffx)

  * 0,0 -> ul  :  1,1 -> lr;

  cxf = 0.6;
  cyf = 0.8;

  * < 1, major is vertical
  * > 1, major is horizontal
  * =1, circle;

  whRatio = 1/2.5;

  cx = width  * cxf;
  cy = height * cyf;

  r1 = cx**2 + cy**2;                   * to ul;
  r2 = (width-cx)**2 + cy**2;           * to ur;
  r3 = cx**2 + (height-cy)**2;          * to ll;
  r4 = (width-cx)**2 + (height-cy)**2 ; * to lr;

  r1 = sqrt(r1);
  r2 = sqrt(r2);
  r3 = sqrt(r3);
  r4 = sqrt(r4);

  r = max (of r1-r4);

  %setColor (0000000x);

  if r = r1 then do;
    dy = -cy;
    dx = -cx;
  end;
  else
  if r = r2 then do;
    dy = -cy;
    dx = width - cx;
  end;
  else
  if r = r3 then do;
    dy = height - cy;
    dx = -cx;
  end;
  else
  if r = r4 then do;
    dy = height - cy;
    dx = width  - cx;
  end;

  ratio = -dy/dx;
  theta = atan (ratio);
  thetad = theta * 360 / 2 / constant('pi');

  e_sq = 1 - 1 / whRatio ** 2;

  k = ( 1 - e_sq * cos(theta)**2 ) / ( 1 - e_sq) ;

  n = 300;

  do i = 0 to n;

    f = i / n ;

    rhat = (1-f) * r;

    a_sq = rhat**2 * k;

    a = sqrt (a_sq);
    b = a / whRatio;

    %setColorRGB (255 * f, 255 * f, 127);

    %fillOval (cx-a, cy-b, 2*a, 2*b);
  end;

  %canvas_saveAs (gsf, gsftype, savedAs);

  %canvas_delete();

  if savedAs ne '' then call system ("start " || savedAs);
run;