Forgot password?
 Create new account
View 30|Reply 3

tikz 画复合三角函数需注意的一点

[Copy link]

701

Threads

110K

Posts

910K

Credits

Credits
94165
QQ

Show all posts

kuing Posted at yesterday 14:55 |Read mode
Last edited by kuing at yesterday 15:24画 sin(x) 的图像通常可以这样:
  1. \tikz{
  2. \draw[domain=0:2*pi,smooth] plot (\x,{sin(\x r)});
  3. }
Copy the Code

效果:



那如果画 sin(sin(x)) 呢?
或许你会说:那还不容易嘛?将上面的 sin(\x r) 改成 sin(sin(\x r)) 不就得了?
来试试:
  1. \tikz{
  2. \draw[domain=0:2*pi,smooth] plot (\x,{sin(sin(\x r))});
  3. }
Copy the Code

效果:



???啥?就是根直线?不可能呀,出 bug 了吧……

正确画法:
  1. \tikz{
  2. \draw[domain=0:2*pi,smooth] plot (\x,{sin(sin(\x r)r)});
  3. }
Copy the Code

效果:

其实没出 bug,是因为 tikz 的三角函数默认是角度制,弧度制得加 r。
对于 sin(sin(\x r)) 内层有 r 是弧度制,但外层没有,所以外层是角度制,结果就这样了。
因此每层都应该要有 r。

701

Threads

110K

Posts

910K

Credits

Credits
94165
QQ

Show all posts

 Author| kuing Posted at yesterday 15:43
Last edited by kuing at yesterday 16:01顺便说一下,反三角函数的输出也是角度制,即 atan(1) 得到的是 45 而不是 `\pi/4`。
因此要画 arctan(x) 时如果用
  1. \tikz{
  2. \draw[domain=-3:3,smooth] plot (\x,{atan(\x)});
  3. }
Copy the Code

那线条将会飞上天!(此处无法展示)
应该改成
  1. \tikz{
  2. \draw[domain=-3:3,smooth] plot (\x,{atan(\x)/(1r)});
  3. }
Copy the Code

(我试过直接 /r 是不行的,r 前似乎必须有数值,而 /1r 也不行,必须 /(1r))
效果:


由以上可知,如果要画 sin(arccos(x)),就不用加任何东西,比如:
  1. \tikz{
  2. \draw[domain=-1:1,smooth] plot (\x,{sin(acos(\x))});
  3. }
Copy the Code

(两边不圆滑,可加大 samples(默认 25),这里仅作演示所以不加)

但如果要画 arccos(sin(x)),那就里外两层都得处理:
  1. \tikz{
  2. \draw[domain=0:2*pi] plot (\x,{acos(sin(\x r))/(1r)});
  3. }
Copy the Code

(由于知道是直线,所以去掉 smooth)

3150

Threads

8482

Posts

610K

Credits

Credits
66119
QQ

Show all posts

hbghlyj Posted at 13 hr ago

Comment

才知道有这么个选项😃  Posted at 4 hr ago

手机版Mobile version|Leisure Math Forum

2025-4-19 17:57 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list