美文网首页
Tikz:定义点/极坐标点、路径、交点

Tikz:定义点/极坐标点、路径、交点

作者: 胜负55开 | 来源:发表于2020-11-16 21:19 被阅读0次

    下面一个例子展示如何使用Tikz完成:

    • 定义一个坐标点,以备后面画线时直接使用;
    • 定义一个极坐标点,以备在圆上快速定点;
    • 根据定义的点进行路径的定义;
    • 根据定义的路径计算路径的交点
    • 根据定义的坐标点进行封闭区域/形状的旋转

    注意:以上的所有操作不需要额外导入Tikz中的其他库,直接导入\usepackages{tikz}就可以实现上面的各种功能。

    % 极坐标定点示例:长度不带单位,默认坐标单位一样! —— 方便!
    % 极坐标更方便的一点:代码改动小!只用调角度即可!
    \begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale = 3]
        %\draw [thick, <->] (-2,2.5) node [left] {$x_2$} -- (-2,-2) -- (2.5,-2) node [below right] {$x_1$};  
        \draw (0,0) circle [radius = 1];  % 注意:为了普通坐标和极坐标可以通用,把圆心定在原点!
        % 第一个三角形:
        \coordinate (O) at (0:0);  % 原点
        \coordinate (A) at (90:1);  
        \coordinate (B) at (210:1);
        \coordinate (C) at (-30:1);
        \draw [red] (A) -- (B) -- (C) -- (A);
        % 第二个三角形:
        \coordinate (D) at (-90:1);  
        \coordinate (E) at (30:1);
        \coordinate (F) at (150:1);
        \draw [green] (D) -- (E) -- (F) -- (D);
        % 定义路径:不画出来
        \path [name path = AB] (A) -- (B); \path [name path = AC] (A) -- (C); \path [name path = BC] (B) -- (C);
        \path [name path = DE] (D) -- (E); \path [name path = DF] (D) -- (F); \path [name path = EF] (E) -- (F);
        % 算交点:不画出来
        \path [ name intersections = {of = AB and EF, by = i1} ]; 
        \path [ name intersections = {of = AB and DF, by = i2} ];
        \path [ name intersections = {of = AC and EF, by = i3} ];
        \path [ name intersections = {of = AC and DE, by = i4} ];
        \path [ name intersections = {of = BC and DF, by = i5} ];
        \path [ name intersections = {of = BC and DE, by = i6} ];     
        % 填充:
        %\draw [very thin, fill = green, opacity = 0.5] (A) -- (i1) -- (i3) -- (A);
        \draw [very thin, fill = green, opacity = 0.5] (E) -- (i3) -- (i4) -- (E);
        %\draw [very thin, fill = green, opacity = 0.5] (C) -- (i4) -- (i6) -- (C);
        \draw [very thin, fill = green, opacity = 0.5] (D) -- (i5) -- (i6) -- (D);
        %\draw [very thin, fill = green, opacity = 0.5] (B) -- (i2) -- (i5) -- (B);
        \draw [very thin, fill = green, opacity = 0.5] (F) -- (i1) -- (i2) -- (F);
        
        % 旋转一个图形:在scope环境中
        \begin{scope}[rotate around={33:(O)}]
            % 坐标需要重定一遍
            \coordinate (A1) at (90:1);  
            \coordinate (B1) at (210:1);
            \coordinate (C1) at (-30:1);
            \draw[blue] (A1) -- (B1) -- (C1) -- cycle;  % cycle写最后表示闭环
        \end{scope}
    \end{tikzpicture}
    \caption{定义点+极坐标点、路径、交点、旋转}
    \end{figure}
    

    效果如下:


    效果图

    相关文章

      网友评论

          本文标题:Tikz:定义点/极坐标点、路径、交点

          本文链接:https://www.haomeiwen.com/subject/ibazbktx.html