全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1295 4
2013-12-12
/* Richard A. DeVenezia
* www.devenezia.com
* 5/16/2004
*/
ods listing ;
%let pixels=600;
%let pixels=143;
goptions reset=all target=png device=png xpixels=&pixels ypixels=&pixels;
goptions gsfname=gout;
filename gout "%sysfunc(pathname(WORK))\bezier-curve.png";
filename gout "\\extreme\samples\bezier-curve.png";
data _null_;
/* Adapted from http://www.codetoad.com/vb_bezier.asp
  * A cubic Bezier curve is defined by four points.
  *
  * (x0,y0) & (x3,y3) are endpoints and
  * (x1,y1) & (x2,y2) are control points.
  *
  * The following equations define the points
  * on the curve.  Both are evaluated for an
  * arbitrary number of values of t between 0 and 1.
  *
  * X(t) = ax * t ^ 3 + bx * t ^ 2 + cx * t + x0
  *
  * X1 = x0 + cx / 3
  * X2 = X1 + (cx + bx) / 3
  * x3 = x0 + cx + bx + ax
  *
  * Y(t) = ay * t ^ 3 + by * t ^ 2 + cy * t + y0
  *
  * Y1 = y0 + cy / 3
  * Y2 = Y1 + (cy + by) / 3
  * y3 = y0 + cy + by + ay
  */
  libname = 'WORK';
  memname = 'BEZIER';
  entname = 'CURVE';
  rc = gset ('CATALOG', libname, memname);
  rc = ginit();
  rc = graph('CLEAR', entname);
  f = 1;
  rc = gset ('WINDOW', 1, -f,-f, f,f);
  rc = gset ('TRANSNO', 1);
  rc = gset ('COLREP', 1, 'CXAAAAAA');
  rc = gset ('COLREP', 2, 'BLACK');
  rc = gset ('COLREP', 1, 'CXCCCCFF');
  rc = gset ('COLREP', 2, 'CX0000FF');
  r = .95 * f;
  rc = gset ('LINCOLOR', 2);
* rc = gset ('LINWIDTH', 1);
* rc = gset ('LINTYPE', 1);
  rc = gdraw('ARC', 0,0,r, 0,360);
  rc = gset ('LINCOLOR', 1);
* rc = gset ('LINWIDTH', 1);
* rc = gset ('LINTYPE', 1);
  rc = gset ('ASF', 'LINWIDTH', 'INDIVIDUAL');
  nVerts=12;
  do i = 1 to nVerts;
    theta1 = 2 * constant('PI') * (i-1) / nVerts;
    theta2 = 2 * constant('PI') * (i  ) / nVerts;
    x0 = r * cos(theta1) ;
    y0 = r * sin(theta1) ;
    x3 = r * cos(theta2) ;
    y3 = r * sin(theta2) ;
    * aff - arc flattening factor none=0..1=straight;
    do aff = 0 to 1-1e-6 by .25;
      link drawBez;
    end;
  end;
  rc = graph('UPDATE');*,'NOSHOW');
  rc = gterm();
  stop;
drawBez:
  array x[0:3] x0-x3;
  array y[0:3] y0-y3;
  x1 = aff * (x0 + x3) / 2;
  y1 = aff * (y0 + y3) / 2;
  x2 = x1;
  y2 = y1;
  cx = 3 * (x(1) - x(0));
  bx = 3 * (x(2) - x(1)) - cx;
  ax = x(3) - x(0) - cx - bx;
  cy = 3 * (y(1) - y(0));
  by = 3 * (y(2) - y(1)) - cy;
  ay = y(3) - y(0) - cy - by;

  xtp = x(0);
  ytp = y(0);
  iterations = 20;
  do t = 0 to 1 by 1/iterations;
    xt = ax * t ** 3 + bx * t ** 2 + cx * t + x(0);
    yt = ay * t ** 3 + by * t ** 2 + cy * t + y(0);
*   rc = gdraw('LINE', 2, xtp,xtp, ytp,ytp);
    rc = gdraw('LINE', 2, xtp,xt , ytp,yt );
    xtp = xt;
    ytp = yt;
  end;
return;
run;
options noxwait;
x "start %sysfunc(pathname(gout))";
来自大神,图挺漂亮的。目前阶段,好多地方都看不懂,欢迎各位大神来解惑。

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-12-12 15:43:07
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-12-12 16:57:31
学习了link和return, stop,谢谢了。画图部分的计算太复杂了,看不懂+1.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-12-13 14:41:52
NOTE: 高于 9.3 的 SAS 版本将不再支持 DSGI。
NOTE: 正在写入 HTML Body(主体)文件: sashtml.htm
NOTE: 有 2 条记录写入“C:\Users\hxyc01\AppData\Local\Temp\SAS Temporary
      Files\_TD5200_HXYC01-PC_\curve.png”。
ERROR: 物理文件“\\extreme\samples\bezier-curve.png”不存在。
NOTE: “DATA 语句”所用时间(总处理时间):
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-12-13 16:45:40
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群