圆上的径向框

圆上的径向框

我需要一个有 8 个径向框的图表,目前我有

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows}

\begin{document}
\thispagestyle{empty}
\begin{center}
    
     \begin{tikzpicture}
        \draw (0,0) circle (2.3);
        \draw[thick, black, -] (0,0) -- ++(45:1.5) node[coordinate] (a) {} node[right, black] {$m$};
        \draw (0.1,0.7) node [right] {$r_A$};
        \draw (1.4,-0.2) node[right] {$r_B$};
        \draw[thick, red!50!black,->] (2.75, 0) -- (2.75,1.3) node[right, black]{$v_B$};
        \draw[thick, black, |-|] (0,0) -- ++(0:2.75);
        \draw[thick, green!50!black,->] (a) -- ++(135:1cm) node[right, black]{$v_A$};
        \filldraw (1.04,1.06) circle (2.5pt);
        \filldraw (0,0) circle (1.5pt);
        \draw (-0.2,2.3) -- (-0.2, 3) -- (0.2,3) -- (0.2,2.3);
        \draw (-0.2,-2.3) -- (-0.2, -3) -- (0.2,-3) -- (0.2,-2.3);
        \draw (-2.3,-0.2) -- (-3, -0.2) -- (-3,0.2) -- (-2.3,0.2);
        \draw (2.3,-0.2) -- (3, -0.2) -- (3,0.2) -- (2.3,0.2);
        \def\Radius{2.3cm}
        \draw
    \foreach \a in {0, 45, ..., 350} {
      (0, 0) -- (\a:\Radius)
      }
    ;
    
     \end{tikzpicture}
    
   \end{center}
   \end{document}

这使:

我希望有另外四个径向遮罩,分别为 45、135、225 和 315 度,我对乳胶还不太熟悉,所以如果能得到一点帮助,我将不胜感激

答案1

我建议先画出 4 个细长的矩形,然后在上面放置一个白色圆圈。

在此处输入图片描述

以下是代码:

\begin{tikzpicture}
\foreach \a in {0,45,90,135}{\draw[rotate=\a] (-3,-.2) rectangle (3,.2);}
\draw[fill=white](0,0) circle[radius=2.3];
\foreach \a in {0,45,90,135}{\draw (\a:2.3)--(\a:-2.3);}
\draw[thick] (0,0) node[inner sep=1pt, circle, fill, draw]{}
    -- ++(45:1.5) node[inner sep=1.5pt, circle, fill, draw,  
    label={[label distance=-.5mm,label position=right]$m$},
    label={[midway, label distance=-1.5mm, label position=above left] $r_{\!A}$}] (a) {};
\draw[thick, red!50!black,->] (2.75, 0) -- ++(0,1.3) node[right, black]{$v_B$};
\draw[thick, |-|, shorten <= -.4pt, shorten >= -.4pt] (0,0) -- ++(0:2.75)
    node[pos=.6,below]{$r_B$};
\draw[thick, green!50!black,->] (a) -- ++(135:1cm) node[right, black]{$v_A$};
\end{tikzpicture}

我做了其他一些改变:

  • 使用shorten负参数(线条粗细)将|-|箭头与垂直线对齐。
  • 将黑色圆圈作为节点
  • midway使用或放置标签pos=

答案2

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\nrect}{8} % number of rectangles
\pgfmathsetlengthmacro{\rcircle}{2cm} % radius of circle
\pgfmathsetlengthmacro{\rlength}{2.5cm} % length of rectangle
\pgfmathsetlengthmacro{\rwidth}{0.5cm} % width of rectangle

\begin{scope}
\clip (\rcircle,0) arc[start angle=0, end angle=360,radius=\rcircle] --
    (0:\rlength+\rwidth) arc[start angle=0, end angle=-360,radius=\rlength+\rwidth] --
    cycle;

\foreach \x in {1,...,\nrect} {% draw rectangles
    \draw ({90+(\x-1)*(360/\nrect)}:\rwidth/2) --
        ++({-90+(\x-1)*(360/\nrect)}:\rwidth) --
        ++({(\x-1)*(360/\nrect)}:\rlength) --
        ++({90+(\x-1)*(360/\nrect)}:\rwidth) -- cycle;
}
\end{scope}

\draw (0,0) circle[radius=\rcircle];
\end{tikzpicture}
\end{document}

在此处输入图片描述

编辑另一种方法

\begin{tikzpicture}
\pgfmathsetlengthmacro{\rcircle}{2cm} % radius of circle
\pgfmathsetlengthmacro{\rlength}{0.5cm} % length of rectangle
\pgfmathsetlengthmacro{\rwidth}{0.5cm} % width of rectangle
\pgfmathsetmacro{\mang}{asin(0.5*\rwidth/\rcircle)}

\foreach \x in {0,45,...,315} {\draw (\x-\mang:\rcircle) -- ++(\x:\rlength) --
    ++(90+\x:\rwidth) -- (\x+\mang:\rcircle);}

\draw (0,0) circle[radius=\rcircle];
\end{tikzpicture}

而且非常简单......

\begin{tikzpicture}
\foreach \x in {0,45,90,135} {\draw[rotate=\x] (-3,-0.2) rectangle (3,0.2);}
\filldraw[fill=white] (0,0) circle[radius=2.3];
\end{tikzpicture}

在此处输入图片描述

答案3

一些基本的数学计算就可以完成这项工作。”

在此处输入图片描述

\documentclass{article}
\usepackage{expl3}
\usepackage{tikz}




\ExplSyntaxOn

\fp_new:N \g_my_tf_x_fp
\fp_new:N \g_my_tf_y_fp

% #1: x-coord; #2: y-coord; #3: angle
\cs_set:Npn \my_rotate_point:nnn #1#2#3 {
    \fp_gset:Nn \g_my_tf_x_fp {(#1)*cos(#3)-(#2)*sin(#3)}
    \fp_gset:Nn \g_my_tf_y_fp {(#1)*sin(#3)+(#2)*cos(#3)}
}

% #1: x-coord; #2: y-coord; #3: t-x; #4: 4-y
\cs_set:Npn \my_translate_point:nnnn #1#2#3#4 {
    \fp_gset:Nn \g_my_tf_x_fp {(#1)+(#3)}
    \fp_gset:Nn \g_my_tf_y_fp {(#2)+(#4)}
}

\cs_set:Npn \my_draw_rectangle:nnnnnnnn #1#2#3#4#5#6#7#8 {
    \draw[myrect] (#1cm,#2cm)--(#3cm,#4cm)--(#5cm,#6cm)--(#7cm,#8cm)--cycle{};
}

\fparray_new:Nn \g_my_array_fparray {8}

\cs_set:Nn \my_draw_array: {
    \my_draw_rectangle:nnnnnnnn
        {\fparray_item:Nn \g_my_array_fparray {1}}
        {\fparray_item:Nn \g_my_array_fparray {2}}
        {\fparray_item:Nn \g_my_array_fparray {3}}
        {\fparray_item:Nn \g_my_array_fparray {4}}
        {\fparray_item:Nn \g_my_array_fparray {5}}
        {\fparray_item:Nn \g_my_array_fparray {6}}
        {\fparray_item:Nn \g_my_array_fparray {7}}
        {\fparray_item:Nn \g_my_array_fparray {8}}
}

\cs_set:Npn \my_init_array:nn #1#2 {
    \fparray_gset:Nnn \g_my_array_fparray {1}{0}
    \fparray_gset:Nnn \g_my_array_fparray {2}{0}
    \fparray_gset:Nnn \g_my_array_fparray {3}{#1}
    \fparray_gset:Nnn \g_my_array_fparray {4}{0}
    \fparray_gset:Nnn \g_my_array_fparray {5}{#1}
    \fparray_gset:Nnn \g_my_array_fparray {6}{#2}
    \fparray_gset:Nnn \g_my_array_fparray {7}{0}
    \fparray_gset:Nnn \g_my_array_fparray {8}{#2}
}

\fp_new:N \l_tmpc_fp
\fp_new:N \l_tmpd_fp

% #1: circle radius (in cm)
% #2: box width
% #3: box height
% #4: angles
\newcommand{\circleandbox}[4]{
    \clist_set:Nn \l_tmpa_clist {#4}
    \int_step_variable:nNn {\clist_count:N \l_tmpa_clist} \l_tmpa_tl {
        \my_init_array:nn {#2}{#3}
        \int_step_variable:nNn {4} \l_tmpb_tl {
            \my_translate_point:nnnn {\fparray_item:Nn \g_my_array_fparray {2*(\l_tmpb_tl)-1}}
                                     {\fparray_item:Nn \g_my_array_fparray {2*(\l_tmpb_tl)}}
                                     {\fp_eval:n {-0.15 * (#2)}} {\fp_eval:n {-0.5 * (#3)}}
            \fp_set_eq:NN \l_tmpa_fp \g_my_tf_x_fp
            \fp_set_eq:NN \l_tmpb_fp \g_my_tf_y_fp
            \my_rotate_point:nnn {\l_tmpa_fp} {\l_tmpb_fp} {
                \fp_eval:n {\clist_item:Nn \l_tmpa_clist {\l_tmpa_tl} * \c_one_degree_fp}
            }
            \fp_set_eq:NN \l_tmpa_fp \g_my_tf_x_fp
            \fp_set_eq:NN \l_tmpb_fp \g_my_tf_y_fp
            \my_rotate_point:nnn {#1} {0} {
                \fp_eval:n {\clist_item:Nn \l_tmpa_clist {\l_tmpa_tl} * \c_one_degree_fp}
            }
            \fp_set_eq:NN \l_tmpc_fp \g_my_tf_x_fp
            \fp_set_eq:NN \l_tmpd_fp \g_my_tf_y_fp
            \my_translate_point:nnnn {\l_tmpa_fp}
                                     {\l_tmpb_fp}
                                     {\l_tmpc_fp} {\l_tmpd_fp}
            \fparray_gset:Nnn \g_my_array_fparray {2*(\l_tmpb_tl)-1} {\g_my_tf_x_fp}
            \fparray_gset:Nnn \g_my_array_fparray {2*(\l_tmpb_tl)} {\g_my_tf_y_fp}
        }
        \my_draw_array:
    }
    \draw[mycirc] (0cm,0cm) circle (#1cm);
}

\ExplSyntaxOff

\tikzset{
    myrect/.style={
        draw
    },
    mycirc/.style={
        draw,
        fill=white
    }
}

\begin{document} 

\begin{tikzpicture}
\circleandbox{3}{0.5}{0.2}{0, 30, 60, 90, 120, 150}
\end{tikzpicture}
\begin{tikzpicture}
\circleandbox{2.5}{0.3}{0.4}{120, 150, 180, 210, 240, 270}
\end{tikzpicture}


\end{document}

相关内容