From 85e029236cfc4e616c7948c209a836793e4cda24 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Tue, 2 Jul 2013 15:47:01 +0200 Subject: [PATCH] added sphere example --- math/asymptote/sphere-sphere/Makefile | 35 ++++++++++++ math/asymptote/sphere-sphere/Readme.md | 9 ++++ math/asymptote/sphere-sphere/latexmkrc | 4 ++ .../asymptote/sphere-sphere/sphere-sphere.tex | 53 +++++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 math/asymptote/sphere-sphere/Makefile create mode 100644 math/asymptote/sphere-sphere/Readme.md create mode 100644 math/asymptote/sphere-sphere/latexmkrc create mode 100644 math/asymptote/sphere-sphere/sphere-sphere.tex diff --git a/math/asymptote/sphere-sphere/Makefile b/math/asymptote/sphere-sphere/Makefile new file mode 100644 index 0000000..142efb0 --- /dev/null +++ b/math/asymptote/sphere-sphere/Makefile @@ -0,0 +1,35 @@ +SOURCE = sphere-sphere +DELAY = 80 +DENSITY = 300 +WIDTH = 512 + +make: + latexmk -pdf $(SOURCE).tex + make clean + +clean: + rm -rf $(TARGET) *.class *.html *.log *.aux *.data *.gnuplot *.dvi *.ps *.pre *.fls *.fdb_latexmk *.asy sphere-sphere-1.tex + +gif: + pdfcrop $(SOURCE).pdf + convert -verbose -delay $(DELAY) -loop 0 -density $(DENSITY) $(SOURCE)-crop.pdf $(SOURCE).gif + make clean + +png: + make + make svg + inkscape $(SOURCE).svg -w $(WIDTH) --export-png=$(SOURCE).png + +transparentGif: + convert $(SOURCE).pdf -transparent white result.gif + make clean + +svg: + make + #inkscape $(SOURCE).pdf --export-plain-svg=$(SOURCE).svg + pdf2svg $(SOURCE).pdf $(SOURCE).svg + # Necessary, as pdf2svg does not always create valid svgs: + inkscape $(SOURCE).svg --export-plain-svg=$(SOURCE).svg + rsvg-convert -a -w $(WIDTH) -f svg $(SOURCE).svg -o $(SOURCE)2.svg + inkscape $(SOURCE)2.svg --export-plain-svg=$(SOURCE).svg + rm $(SOURCE)2.svg diff --git a/math/asymptote/sphere-sphere/Readme.md b/math/asymptote/sphere-sphere/Readme.md new file mode 100644 index 0000000..e8c65c8 --- /dev/null +++ b/math/asymptote/sphere-sphere/Readme.md @@ -0,0 +1,9 @@ +This is an example from `pst-solides3d` documentation. + +Compiled example +---------------- +![Example](sphere-sphere.png) + +Credits +------- +Thanks to [g.kov](http://tex.stackexchange.com/users/27243/g-kov) ([answer](http://tex.stackexchange.com/a/121900/5645)) diff --git a/math/asymptote/sphere-sphere/latexmkrc b/math/asymptote/sphere-sphere/latexmkrc new file mode 100644 index 0000000..1cca873 --- /dev/null +++ b/math/asymptote/sphere-sphere/latexmkrc @@ -0,0 +1,4 @@ +sub asy {return system("asy '$_[0]'");} +add_cus_dep("asy","eps",0,"asy"); +add_cus_dep("asy","pdf",0,"asy"); +add_cus_dep("asy","tex",0,"asy"); diff --git a/math/asymptote/sphere-sphere/sphere-sphere.tex b/math/asymptote/sphere-sphere/sphere-sphere.tex new file mode 100644 index 0000000..59aff8e --- /dev/null +++ b/math/asymptote/sphere-sphere/sphere-sphere.tex @@ -0,0 +1,53 @@ +\documentclass{article} +\usepackage{lmodern} +\usepackage[inline]{asymptote} +\begin{document} +\begin{figure} +\begin{asy} +settings.prc=false; +settings.render=0; +import graph3; + +currentprojection=orthographic(camera=(150,900,412),up=(-0.4,-0.7,1.4),target=(100,111,1),zoom=0.5); +currentlight=nolight; +size(300);size3(300); + +real r1=162; +real r2=100; + +triple v1=(0,0,0); +triple v2=(250,0,0); + +// from http://mathworld.wolfram.com/Sphere-SphereIntersection.html : +real d=arclength(v1--v2); // distance between v1,v2 +real a=1/2/d*sqrt((2*d*r1)^2-(d^2-r2^2+r1^2)^2); + +triple P=(sqrt(r1^2-a^2),0,-a); + +triple fs1(pair t){ + return v1+r1*(cos(t.x)*sin(t.y),sin(t.x)*sin(t.y),cos(t.y)); +} + +triple fs2(pair t){ + return v2+r2*(cos(t.x)*sin(t.y),sin(t.x)*sin(t.y),cos(t.y)); +} + +surface s1=surface(fs1,(0,0),(2pi,pi),16,Spline); +surface s2=surface(fs2,(0,0),(2pi,pi),16,Spline); + +draw(s1 + ,darkgreen+opacity(0.2) + ,render(compression=Low,merge=true) +); + +draw(s2 + ,darkblue+opacity(0.2) + ,render(compression=Low,merge=true) +); + +dot(v1); label("$V_1$",v1,-X+Z); +dot(v2); label("$V_2$",v2,-X+Z); +dot(P); label("$P$",P,-X-Z); +\end{asy} +\end{figure} +\end{document}