tikz-函数计算pgfmathparse,pgfmathresult

来源:互联网 发布:linux 统计大文件行数 编辑:程序博客网 时间:2024/06/06 00:43

要点:
- 调用pgfmathparse命令进行函数计算,而用pgfmathresult取计算结果;
- 三角函数可以传入角度值,也可以传入弧度;
- 传入弧度时,数值后面空一格之后加个字母r。

示例:三种画直角三角形的代码

第一种:直接给出根号3的值1.732,但这种方法易读性不好;而且对于理想主义来讲,远不如直接传入根号3会让心情更加愉悦。

\begin{tikzpicture}[scale=1]\coordinate (A) at (0,0);\coordinate (B) at (1.732,0);\coordinate (C) at (1.732,1);\draw (A)node [below left]{A}      --(B)node [below right]{B}      --(C)node [above]{C}      --cycle;\end{tikzpicture}

第二种:直接让tikz计算出根号3的值

\begin{tikzpicture}[scale=1]\pgfmathparse{sqrt(3)}\coordinate (A) at (0,0);\coordinate (B) at (\pgfmathresult,0);\coordinate (C) at (\pgfmathresult cm,1);\draw (A)node [below left]{A}      --(B)node [below right]{B}      --(C)node [above]{C}      --cycle;\end{tikzpicture}

第三种:和第二种类似,不过这里在第二种介绍了sqrt()之后,顺便介绍三角函数的使用方法。进一步地,给出角度和弧度两种调用方式。

\begin{tikzpicture}[scale=1]\coordinate (A) at (0,0);\pgfmathparse{cos(30)}\coordinate (B) at (2*\pgfmathresult,0);\pgfmathparse{cos(pi/6 r)}\coordinate (C) at (2*\pgfmathresult, 1);\draw (A)node [below left]{A}      --(B)node [below right]{B}      --(C)node [above]{C}      --cycle;\end{tikzpicture}

效果:

这里写图片描述

0 0
原创粉丝点击