Skip to content

Instantly share code, notes, and snippets.

@leingang
Last active May 3, 2016 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leingang/71ceab3d19bd5c05f3dd6724fb20a24e to your computer and use it in GitHub Desktop.
Save leingang/71ceab3d19bd5c05f3dd6724fb20a24e to your computer and use it in GitHub Desktop.
My first attempts at asymptote
settings.outformat="png";
settings.render=16;
size (10cm,0);
pair O = (0,0);
pair A = (sqrt(3),1);
pair B = (-sqrt(3),1);
pen surfacepen=rgb(0,0,0.8)+opacity(0.75);
pen notthere=opacity(0.5);
// axes
draw((-2.25,0) -- (2.25,0),
arrow=Arrow(TeXHead),
L=Label("$x$",
position=EndPoint,
align=N)
);
draw((0,-0.25) -- (0,2.25),
arrow=Arrow(TeXHead),
L=Label("$z$",
position=EndPoint,
align=N)
);
path hemisphere = arc(O,r=2,angle1=0,angle2=180);
path demihemisphere = A -- B -- arc(0,r=2,angle1=30,angle2=150) -- cycle;
draw(hemisphere,opacity(0.25));
draw(demihemisphere,surfacepen);
fill(demihemisphere,surfacepen+opacity(0.5));
// dot(A);
draw(O--A,notthere);
pair Q=(1.5,3);
pair Qp=(-Q.y,Q.x);
path ray= O -- Q;
pair D = intersectionpoint(A--B,ray);
pair E = intersectionpoint(hemisphere,ray);
draw(O--E,notthere);
dot(D);
// dot(E);
label("1",(0,1),NW);
label("2",(0,2),NW);
// angle marker
draw(arc(O,
intersectionpoint(scale(0.5)*unitcircle,O--(0,2)),
intersectionpoint(scale(0.5)*unitcircle,ray),
direction=CW),
arrow=Arrow(TeXHead),
L=Label("$\varphi$",
position=MidPoint,
align=N),
notthere);
draw(arc(O,
intersectionpoint(scale(1.5)*unitcircle,O--(0,2)),
intersectionpoint(scale(1.5)*unitcircle,O--A),
direction=CW),
arrow=Arrow(TeXHead),
L=Label("$\pi/3$",
position=Relative(0.75),
align=N),
notthere);
// distance marker
draw(O--D,
L=shift(Qp)*rotate(degrees(atan2(Q.y,Q.x)))*Label(
"$\sec(\varphi)$",
position=Relative(0.5)),
nullpen);
settings.outformat="png";
settings.render=16;
import three;
size (10cm,0);
currentprojection = orthographic(2,-5,2);
/* axes */
draw(-2.5 X -- 2.5 X,
arrow=Arrow3(TeXHead2),
L=Label("$x$",
position=EndPoint,
align=N)
);
draw(-2.5 Y -- 2.5 Y,
arrow=Arrow3(TeXHead2),
L=Label("$y$",
position=EndPoint,
align=N)
);
draw(-0.5 Z -- 2.5 Z,
arrow=Arrow3(TeXHead2),
L=Label("$z$",
position=EndPoint,
align=N)
);
// surface
path3 p=arc(O,2Z,(sqrt(3),0,1));
surface s=surface(p,c=O,axis=Z);
draw(scale(2,2,2)*unithemisphere,opacity(0.25));
draw(s,rgb(0,0,0.8)+opacity(0.75));
@leingang
Copy link
Author

leingang commented May 3, 2016

Output:

foo

bar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment