2007年10月7日星期日

Latex 使用 epix 生成 tikz 图形

使用 epix 生成 tikz 图形
lyanry posted @ 2007年10月07日 08:24AM in 文档标记语言 with tags epix TikZ

前几天瞎逛,发现了这么一个东西:
http://mathcs.holycross.edu/~ahwang/current/ePiX.html

epix 提供了一套 c++ 风格的绘图语法,对绘图代码处理后生成可以嵌入到 latex 文档中的 pstricks、tikz、eepic 图形。

其生成 tikz 图形的基本过程如下:

1. epix 所处理的源文档示例 sphere.xp:
/* -*-ePiX-*- */
#include "epix.h"
using namespace ePiX;

const double k(2*M_PI/(360*sqrt(3))); // assume "degrees" mode

double exp_cos(double t) { return exp(k*t)*Cos(t); }
double exp_sin(double t) { return exp(k*t)*Sin(t); }
double minus_exp_cos(double t) { return -exp_cos(t); }
double minus_exp_sin(double t) { return -exp_sin(t); }

int main()
{
picture(P(-1,-1), P(1,1), "2.5 x 2.5in");

begin();
degrees(); // set angle units
camera.at(P(1, 2.5, 3));

sphere(); // draw unit sphere's horizon

pen(Blue(1.6)); // hidden portions of loxodromes
backplot_N(exp_cos, exp_sin, -540, 540, 180);
backplot_N(minus_exp_cos, minus_exp_sin, -540, 540, 180);

pen(Red(1.6));
backplot_N(exp_sin, minus_exp_cos, -540, 540, 180);
backplot_N(minus_exp_sin, exp_cos, -540, 540, 180);

pen(Black(0.3)); // coordinate grid

for (int i=0; i<=12; ++i) {
latitude(90-15*i, 0, 360);
longitude(30*i, 0, 360);
}

bold(Blue()); // visible portions of loxodromes
frontplot_N(exp_cos, exp_sin, -540, 540, 360);
frontplot_N(minus_exp_cos, minus_exp_sin, -540, 540, 360);

pen(Red());
frontplot_N(exp_sin, minus_exp_cos, -540, 540, 360);
frontplot_N(minus_exp_sin, exp_cos, -540, 540, 360);

end();
}

2. 使用 epix 处理 sphere.xp ,输出 tikz 图形文档 sphere.eepic:
$ epix --tikz sphere.xp

3. 将 sphere.eepic 文档插入 latex 文档中:
\documentclass{article}

\usepackage{tikz}
\pagestyle{empty}

\begin{document}

\input{sphere.eepic}

\end{document}

使用 pdflatex 处理后,可得到这样的图形:






--
一步一步教你从互联网赚钱 http://www.zqzn.com/index.asp?rid=key480769
投资理财 http://li-cai.blogspot.com/

没有评论: