tikz-函数计算pgfmathparse,pgfmathresult

要点:
- 调用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}

效果:

这里写图片描述

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值