BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Rick_SAS
SAS Super FREQ

In the spirit of Pi Day, and motivated by the great holiday posts by @tc, I thought I'd post a challenge for the graphics gurus. While writing a Pi Day blog post about how Isaac Newton approximated pi to 16 decimals places, I needed to create a diagram that shows the geometry that Newton used in the calculation. I was in a hurry, so I used PowerPoint to create the image.

 

My challenge: Can you create the image by using PROC SGPLOT (or the GTL)?

 

I'll give you a hint: Archimedes knew that you could approximate a circle to any accuracy by using a polygon with many sid...

 

To keep it simple, you do NOT have to use the square-root symbol in your plot; use 'sqrt(3)' instead.

Here's the figure from my Pi Day post. Good luck!

 

NewtonPi1.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
/*I forgot the vertical symbol*/
data have;
id1=1;
do theta=0 to constant('pi') by 0.01;
 x=0.5*cos(theta)+0.5; y=0.5*sin(theta);output;
end;

id2=1;
do theta=0 to (2/3)*constant('pi') by 0.01;
 _x=0.5*cos(theta)+0.5; _y=0.5*sin(theta);output;
end;
_x=0.25;_y=0;output;

x1=0.5;  y1=0.66;output;
x1=1.32; y1=0;output;

x2=0.5; y2=0;datalabel='C';output;
x2=0;   y2=0;datalabel='O';output;
x2=0.25;y2=0;datalabel='A';output;
x3=0.25;y3=sqrt(3)/4;datalabel='B';output;

id3=1;x4=0.3;y4=0.05;output;
id3=1;x4=0.3;y4=0;output;
id3=2;x4=0.3;y4=0.05;output;
id3=2;x4=0.25;y4=0.05;output;

run;


%sganno

data sganno;
 %SGARROW( X1=0, Y1=0,X2=0,Y2=100,DIRECTION= "OUT",X1SPACE="DATAVALUE",Y2SPACE="WALLPERCENT",
            X2SPACE="DATAVALUE",Y1SPACE="DATAVALUE",LINECOLOR="blue" ,SHAPE="BARBED" )
 %SGARROW( X1=0, Y1=0,X2=100,Y2=0,DIRECTION= "OUT",X1SPACE="DATAVALUE",Y2SPACE="DATAVALUE",
            X2SPACE="WALLPERCENT",Y1SPACE="DATAVALUE",LINECOLOR="blue" ,SHAPE="BARBED" )

%SGTEXT( LABEL="O",ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0, Y1=0, WIDTH=12)
%SGTEXT(LABEL="0", ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0,Y1=-0.05,WIDTH=12)

%SGTEXT( LABEL="A",ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.25, Y1=0, WIDTH=12)
%SGTEXT(LABEL="1/4", ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.25,Y1=-0.05,WIDTH=12)

%SGTEXT( LABEL="C  ",ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.5, Y1=0, WIDTH=12)
%SGTEXT(LABEL="1/2", ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.5,Y1=-0.05,WIDTH=12)

%SGTEXT(LABEL="M", ANCHOR="BOTTOM" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.125,Y1=0.1,WIDTH=12,FILLCOLOR="white")
%SGTEXT(LABEL="r = 1/2", ANCHOR="BOTTOMLEFT" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.4,Y1=0.2,WIDTH=12)
%SGTEXT( LABEL="x",ANCHOR="TOP" , X1SPACE="WALLPERCENT",Y1SPACE="DATAVALUE",TEXTSIZE= 12,X1=95, Y1=0, WIDTH=12,FILLTRANSPARENCY=1)
%SGTEXT( LABEL="y",ANCHOR="RIGHT" , X1SPACE="DATAVALUE",Y1SPACE="WALLPERCENT",TEXTSIZE= 12,X1=0, Y1=90, WIDTH=12,FILLTRANSPARENCY=1)
%SGTEXT( LABEL="3/4  ",ANCHOR="RIGHT" , X1SPACE="WALLPERCENT",Y1SPACE="DATAVALUE",TEXTSIZE= 12,X1=0, Y1=0.433, WIDTH=12,FILLTRANSPARENCY=1)

%SGTEXT( LABEL="(*ESC*){unicode '221A'x}",ANCHOR="RIGHT" , X1SPACE="WALLPERCENT",Y1SPACE="DATAVALUE",TEXTSIZE= 12,X1=-3, Y1=0.433, WIDTH=12,FILLTRANSPARENCY=1)
%SGTEXT( LABEL="(*ESC*){unicode '2013'x}",ANCHOR="RIGHT" , X1SPACE="WALLPERCENT",Y1SPACE="DATAVALUE",TEXTSIZE= 12,X1=-1.7, Y1=0.448, WIDTH=12,FILLTRANSPARENCY=1)

run;


proc sgplot data=have noborder aspect=0.5 sganno=sganno noautolegend pad=(left=40);
polygon id=id1 x=x y=y/fillpattern nofill fillpatternattrs=(color=brown);
polygon id=id2 x=_x y=_y/fill fillattrs=(color=white);

series x=x y=y/smoothconnect lineattrs=(color=blue thickness=2);
scatter x=x1 y=y1/markerattrs=(size=0);

scatter x=x3 y=y3/markerattrs=(symbol=circlefilled) 
        datalabel=datalabel datalabelpos=topleft datalabelattrs=(size=12);
scatter x=x2 y=y2/markerattrs=(symbol=circlefilled) ;
vector x=x3 y=y3/xorigin=0.5 yorigin=0 noarrowheads lineattrs=(color=blue thickness=2);
dropline x=x3 y=y3/dropto=x lineattrs=(pattern=solid color=blue thickness=2) ;
dropline x=x3 y=y3/dropto=y lineattrs=(pattern=shortdash color=blue thickness=2) ;

series x=x4 y=y4/group=id3 lineattrs=(pattern=solid color=blue thickness=2) ;

yaxis offsetmin=0.01 offsetmax=0   label='y' display=none min=-0.006 ;
xaxis offsetmin=0.01 offsetmax=0  label='x' display=none;

run;

Ksharp_0-1678438897635.png

 

View solution in original post

3 REPLIES 3
Ksharp
Super User

Rick,

Finally, I got it worked . It is really uneasy. Have fun with the following code.

 

 

data have;
id1=1;
do theta=0 to constant('pi') by 0.01;
 x=0.5*cos(theta)+0.5; y=0.5*sin(theta);output;
end;

id2=1;
do theta=0 to (2/3)*constant('pi') by 0.01;
 _x=0.5*cos(theta)+0.5; _y=0.5*sin(theta);output;
end;
_x=0.25;_y=0;output;

x1=0.5;  y1=0.66;output;
x1=1.32; y1=0;output;

x2=0.5; y2=0;datalabel='C';output;
x2=0;   y2=0;datalabel='O';output;
x2=0.25;y2=0;datalabel='A';output;
x3=0.25;y3=sqrt(3)/4;datalabel='B';output;
run;


%sganno

data sganno;
 %SGARROW( X1=0, Y1=0,X2=0,Y2=100,DIRECTION= "OUT",X1SPACE="DATAVALUE",Y2SPACE="WALLPERCENT",
            X2SPACE="DATAVALUE",Y1SPACE="DATAVALUE",LINECOLOR="blue" ,SHAPE="BARBED" )
 %SGARROW( X1=0, Y1=0,X2=100,Y2=0,DIRECTION= "OUT",X1SPACE="DATAVALUE",Y2SPACE="DATAVALUE",
            X2SPACE="WALLPERCENT",Y1SPACE="DATAVALUE",LINECOLOR="blue" ,SHAPE="BARBED" )

%SGTEXT( LABEL="O",ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0, Y1=0, WIDTH=12)
%SGTEXT(LABEL="0", ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0,Y1=-0.05,WIDTH=12)

%SGTEXT( LABEL="A",ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.25, Y1=0, WIDTH=12)
%SGTEXT(LABEL="1/4", ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.25,Y1=-0.05,WIDTH=12)

%SGTEXT( LABEL="C  ",ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.5, Y1=0, WIDTH=12)
%SGTEXT(LABEL="1/2", ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.5,Y1=-0.05,WIDTH=12)

%SGTEXT(LABEL="M", ANCHOR="BOTTOM" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.125,Y1=0.1,WIDTH=12,FILLCOLOR="white")
%SGTEXT(LABEL="r = 1/2", ANCHOR="BOTTOMLEFT" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.4,Y1=0.2,WIDTH=12)
%SGTEXT( LABEL="x",ANCHOR="TOP" , X1SPACE="WALLPERCENT",Y1SPACE="DATAVALUE",TEXTSIZE= 12,X1=95, Y1=0, WIDTH=12,FILLTRANSPARENCY=1)
%SGTEXT( LABEL="y",ANCHOR="RIGHT" , X1SPACE="DATAVALUE",Y1SPACE="WALLPERCENT",TEXTSIZE= 12,X1=0, Y1=90, WIDTH=12,FILLTRANSPARENCY=1)
%SGTEXT( LABEL="3/4  ",ANCHOR="RIGHT" , X1SPACE="WALLPERCENT",Y1SPACE="DATAVALUE",TEXTSIZE= 12,X1=0, Y1=0.433, WIDTH=12,FILLTRANSPARENCY=1)

%SGTEXT( LABEL="(*ESC*){unicode '221A'x}",ANCHOR="RIGHT" , X1SPACE="WALLPERCENT",Y1SPACE="DATAVALUE",TEXTSIZE= 12,X1=-3, Y1=0.433, WIDTH=12,FILLTRANSPARENCY=1)
%SGTEXT( LABEL="(*ESC*){unicode '2013'x}",ANCHOR="RIGHT" , X1SPACE="WALLPERCENT",Y1SPACE="DATAVALUE",TEXTSIZE= 12,X1=-1.7, Y1=0.448, WIDTH=12,FILLTRANSPARENCY=1)
run;


proc sgplot data=have noborder aspect=0.5 sganno=sganno noautolegend pad=(left=40);
polygon id=id1 x=x y=y/fillpattern nofill fillpatternattrs=(color=brown);
polygon id=id2 x=_x y=_y/fill fillattrs=(color=white);

series x=x y=y/smoothconnect lineattrs=(color=blue thickness=2);
scatter x=x1 y=y1/markerattrs=(size=0);

scatter x=x3 y=y3/markerattrs=(symbol=circlefilled) 
        datalabel=datalabel datalabelpos=topleft datalabelattrs=(size=12);
scatter x=x2 y=y2/markerattrs=(symbol=circlefilled) ;
vector x=x3 y=y3/xorigin=0.5 yorigin=0 noarrowheads lineattrs=(color=blue thickness=2);
dropline x=x3 y=y3/dropto=x lineattrs=(pattern=solid color=blue thickness=2) ;
dropline x=x3 y=y3/dropto=y lineattrs=(pattern=shortdash color=blue thickness=2) ;

yaxis offsetmin=0.01 offsetmax=0   label='y' display=none min=-0.006 ;
xaxis offsetmin=0.01 offsetmax=0  label='x' display=none;

run;

Ksharp_0-1678434332925.png

 

Ksharp
Super User
/*I forgot the vertical symbol*/
data have;
id1=1;
do theta=0 to constant('pi') by 0.01;
 x=0.5*cos(theta)+0.5; y=0.5*sin(theta);output;
end;

id2=1;
do theta=0 to (2/3)*constant('pi') by 0.01;
 _x=0.5*cos(theta)+0.5; _y=0.5*sin(theta);output;
end;
_x=0.25;_y=0;output;

x1=0.5;  y1=0.66;output;
x1=1.32; y1=0;output;

x2=0.5; y2=0;datalabel='C';output;
x2=0;   y2=0;datalabel='O';output;
x2=0.25;y2=0;datalabel='A';output;
x3=0.25;y3=sqrt(3)/4;datalabel='B';output;

id3=1;x4=0.3;y4=0.05;output;
id3=1;x4=0.3;y4=0;output;
id3=2;x4=0.3;y4=0.05;output;
id3=2;x4=0.25;y4=0.05;output;

run;


%sganno

data sganno;
 %SGARROW( X1=0, Y1=0,X2=0,Y2=100,DIRECTION= "OUT",X1SPACE="DATAVALUE",Y2SPACE="WALLPERCENT",
            X2SPACE="DATAVALUE",Y1SPACE="DATAVALUE",LINECOLOR="blue" ,SHAPE="BARBED" )
 %SGARROW( X1=0, Y1=0,X2=100,Y2=0,DIRECTION= "OUT",X1SPACE="DATAVALUE",Y2SPACE="DATAVALUE",
            X2SPACE="WALLPERCENT",Y1SPACE="DATAVALUE",LINECOLOR="blue" ,SHAPE="BARBED" )

%SGTEXT( LABEL="O",ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0, Y1=0, WIDTH=12)
%SGTEXT(LABEL="0", ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0,Y1=-0.05,WIDTH=12)

%SGTEXT( LABEL="A",ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.25, Y1=0, WIDTH=12)
%SGTEXT(LABEL="1/4", ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.25,Y1=-0.05,WIDTH=12)

%SGTEXT( LABEL="C  ",ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.5, Y1=0, WIDTH=12)
%SGTEXT(LABEL="1/2", ANCHOR="TOP" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.5,Y1=-0.05,WIDTH=12)

%SGTEXT(LABEL="M", ANCHOR="BOTTOM" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.125,Y1=0.1,WIDTH=12,FILLCOLOR="white")
%SGTEXT(LABEL="r = 1/2", ANCHOR="BOTTOMLEFT" , DRAWSPACE= "DATAVALUE" ,TEXTSIZE= 12,X1=0.4,Y1=0.2,WIDTH=12)
%SGTEXT( LABEL="x",ANCHOR="TOP" , X1SPACE="WALLPERCENT",Y1SPACE="DATAVALUE",TEXTSIZE= 12,X1=95, Y1=0, WIDTH=12,FILLTRANSPARENCY=1)
%SGTEXT( LABEL="y",ANCHOR="RIGHT" , X1SPACE="DATAVALUE",Y1SPACE="WALLPERCENT",TEXTSIZE= 12,X1=0, Y1=90, WIDTH=12,FILLTRANSPARENCY=1)
%SGTEXT( LABEL="3/4  ",ANCHOR="RIGHT" , X1SPACE="WALLPERCENT",Y1SPACE="DATAVALUE",TEXTSIZE= 12,X1=0, Y1=0.433, WIDTH=12,FILLTRANSPARENCY=1)

%SGTEXT( LABEL="(*ESC*){unicode '221A'x}",ANCHOR="RIGHT" , X1SPACE="WALLPERCENT",Y1SPACE="DATAVALUE",TEXTSIZE= 12,X1=-3, Y1=0.433, WIDTH=12,FILLTRANSPARENCY=1)
%SGTEXT( LABEL="(*ESC*){unicode '2013'x}",ANCHOR="RIGHT" , X1SPACE="WALLPERCENT",Y1SPACE="DATAVALUE",TEXTSIZE= 12,X1=-1.7, Y1=0.448, WIDTH=12,FILLTRANSPARENCY=1)

run;


proc sgplot data=have noborder aspect=0.5 sganno=sganno noautolegend pad=(left=40);
polygon id=id1 x=x y=y/fillpattern nofill fillpatternattrs=(color=brown);
polygon id=id2 x=_x y=_y/fill fillattrs=(color=white);

series x=x y=y/smoothconnect lineattrs=(color=blue thickness=2);
scatter x=x1 y=y1/markerattrs=(size=0);

scatter x=x3 y=y3/markerattrs=(symbol=circlefilled) 
        datalabel=datalabel datalabelpos=topleft datalabelattrs=(size=12);
scatter x=x2 y=y2/markerattrs=(symbol=circlefilled) ;
vector x=x3 y=y3/xorigin=0.5 yorigin=0 noarrowheads lineattrs=(color=blue thickness=2);
dropline x=x3 y=y3/dropto=x lineattrs=(pattern=solid color=blue thickness=2) ;
dropline x=x3 y=y3/dropto=y lineattrs=(pattern=shortdash color=blue thickness=2) ;

series x=x4 y=y4/group=id3 lineattrs=(pattern=solid color=blue thickness=2) ;

yaxis offsetmin=0.01 offsetmax=0   label='y' display=none min=-0.006 ;
xaxis offsetmin=0.01 offsetmax=0  label='x' display=none;

run;

Ksharp_0-1678438897635.png

 

Rick_SAS
SAS Super FREQ

@Ksharp posted a very nice program. Anyone want to solve it without using the annotation facility? 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1069 views
  • 9 likes
  • 2 in conversation