tikz 中的组合旋转

tikz 中的组合旋转

tikz给定一个三角公式(我认为应该很简单:l*cosl*sin),如何在 for 循环中使旋转的中心演变?

我正在尝试制作一个手臂伸展的方案,两个关节可以移动。 绕肩部旋转没问题,但绕肘部旋转时我无法更新旋转中心,因此手臂无法保持一致:

在此处输入图片描述

正如您所看到的,前臂已经完全移动了……

我为肘部设置的初始旋转中心确实允许我围绕肘部旋转,只有当我尝试同时旋转两者时才会遇到麻烦。

下面是我的代码,有一个小序言,我在其中逐一定义了骨骼,然后是相当简短的文档。

\documentclass{standalone}
\usepackage{tikz}    
\usetikzlibrary{calc}

\makeatother

\def\humerusS#1#2#3#4{
    \begin{scope}[shift={#1}, rotate around={#2:#3}, scale={#4}, draw opacity=1]        
        \draw[fill=white] (.81, 6.53) -- (.91, 6.63) -- (1.1, 6.65) -- 
    (1.25, 6.55) -- (1.25, 5.72) -- (1.02,4.6) -- 
    (1.04, 4.14) -- (1.13, 4.2) -- (1.14, 3.92) -- 
    (1.05, 3.84) -- (0.95, 3.84) -- (.83, 3.94) -- 
    (.83, 4.17) -- (.88, 4.52) -- (.90, 4.85) -- 
    (1, 5.37) -- (1.04, 5.66) -- (1.03, 6.05) -- 
    (.85, 6.47) -- (.81, 6.53);
    \end{scope}
}   
\def\claviculaS#1#2#3{
    \begin{scope}[shift={#1}, rotate=#2, scale={#3}, draw opacity=1]        
        \draw (1.02, 6.79) -- (1.19, 6.79) -- (1.33, 6.71) -- 
    (1.7, 6.35) -- (1.62, 6.22) -- (1.52, 6.26) -- 
    (1.52, 6.32) -- (1.4, 6.5) -- (1.24, 6.66) -- 
    (1.16, 6.71) -- (1.02, 6.71) -- (1.02, 6.79);
    \end{scope}
}   
\def\scapulaS#1#2#3{
    \begin{scope}[shift={#1}, rotate=#2, scale={#3}, draw opacity=1]        
        \draw (.02, 5.41) -- (0, 5.5) -- (.08, 6.06) -- 
    (.21, 6.3) -- (.35, 6.43) -- (.46, 6.5) -- 
    (.69, 6.61)--(.83, 6.74)--(.92, 6.76)--(.96, 6.73)--
    (.91, 6.68)--(.8, 6.56)--(.8, 6.48)--(.9, 6.25)--
    (.6, 6.03)--(.41, 5.79)--(.3, 5.6)--(.11, 5.41)--(.02, 5.41);
    \end{scope}
}   
\def\ulnaS#1#2#3#4{
    \begin{scope}[shift={#1}, rotate around={#2:#3}, scale={#4}, draw opacity=1]        
        \draw[fill=white] (.78, 4.19)--(.86, 3.86)--(1.06, 3.3)--(1.21, 2.88)--
    (1.56, 2.12)--(1.83, 1.62)--(1.99, 1.45)--(1.98, 1.38)--
    (1.94, 1.32)--(1.96, 1.24)--(1.9, 1.2)--(1.8, 1.32)--
    (1.75, 1.51)--(1.57, 1.84)--(1.06, 2.8)--(.82, 3.37)--
    (.7, 3.63)--(.6, 4.05)--(.62, 4.16)--(.78, 4.19);
    \end{scope}
}   
\def\radiusS#1#2#3#4{
    \begin{scope}[shift={#1}, rotate around={#2:#3}, scale={#4}, draw opacity=1]        
        \draw[fill=white] (.89, 3.8)--(1.09, 3.82)--(1.13, 3.57)--(1.39, 3.22)--
    (1.68, 2.77)--(1.85,2.44)--(2.08, 1.79)--(2.24, 1.45)--(2.24, 1.36)--
    (1.98, 1.38)--(1.93, 1.55)--(1.86, 1.91)--(1.79, 2.12)--(1.53, 2.72)--
    (1.19, 3.26)--(1.04, 3.41)--(.97, 3.62)--(.89, 3.8);
    \end{scope}
}   
\def\handS#1#2#3#4{
    \begin{scope}[shift={#1}, rotate around={#2:#3}, scale={#4}, draw opacity=1]        
        \draw[fill=white] (1.98, 1.35)--(2.21, 1.36)--(2.32, 1.28)--(2.34, 1.19)--
    (2.66, .77)--(2.67, .73)--(2.62, .75)--(2.32, 1.14)--(2.33, 1.04)--
    (2.72, .24)--(2.72, .19)--(2.68, .22)--(2.3, 1.04)--(2.24, 1.05)--
    (2.25, .97)--(2.6, .05)--(2.6, 0)--(2.56, .03)--(2.21, .99)--
    (2.17, 1.05)--(2.16, .98)--(2.4, .18)--(2.39, .14)--(2.36, .18)--
    (2.11, 1.03)--(2.12, .74)--(2.25, .32)--(2.25, .27)--(2.22, .31)--
    (2.06, .82)--(2.03, 1.21)--(1.97, 1.32)--(1.98, 1.35);
    \end{scope}
}   

\def\repereXY#1#2#3{
    \begin{scope}[shift={#1}, rotate=#2, scale={#3}, draw opacity=1]        
        \draw[->] (0,0) -- (1,0) node[above] {$x$};
        \draw[->] (0,0) -- (0,1) node[above] {$y$};        
    \end{scope}
} 

\begin{document}
\begin{tikzpicture}     
    \node (elbow_flex_0) at (1, 3.97) {};        
    \coordinate (shoulder_flex) at (1.05, 6.5);        

    %do not rotate
    \scapulaS{(0,0)}{0}{1}        
    \claviculaS{(0,0)}{0}{1}        

    \foreach \sf in {0,1,...,30} {
        \humerusS{(0,0)}{\sf}{(shoulder_flex)}{1}        

        %\node (elbow_flex) at ([rotate around={\sf:(shoulder_flex)}]elbow_flex_0) {};        
        \path (elbow_flex_0) ++({3.56*sin(\sf)}:{-3.56*cos(\sf)}) node (elbow_flex) {}; 

        \def\ef{50}
        %\foreach \ef in {55,56,...,69} {
            \radiusS{(elbow_flex)}{\ef}{(elbow_flex)}{1}        
            \ulnaS{(elbow_flex)}{\ef}{(elbow_flex)}{1}        
            \handS{(elbow_flex)}{\ef}{(elbow_flex)}{1}     
        %}   
    }

    %reference frame
    \repereXY{(4,5.5)}{0}{.5}      

\end{tikzpicture}
\end{document}

答案1

你的问题是,我认为在 //\radiusS的定义中,坐标远离下臂的枢轴点。\ulnaS\handS(0,0)

我的意思是,当您shift=(elbow_flex)在选项中执行 时scope,其效果是将向量(elbow_flex)添加到范围内的每个点,因此它就是(0,0)最终scope位于 的坐标elbow_flex

但是,例如在 中\radiusS,骨骼的上端位于 附近的坐标处(0.9,3.8),因此移动后它会变得很远。

我会让你自己找出正确的坐标,但作为一个例子,如果你修改下臂的三个宏,那么移动看起来就像

shift={($#1+(-0.89,-3.8)$)}

并删除\path(重新)定义的elbow_flex,输出变为:

代码输出

\documentclass{standalone}
\usepackage{tikz}    
\usetikzlibrary{calc}

\makeatother

\def\humerusS#1#2#3#4{
    \begin{scope}[shift={#1}, rotate around={#2:#3}, scale={#4}, draw opacity=1]        
        \draw[fill=white] (.81, 6.53) -- (.91, 6.63) -- (1.1, 6.65) -- 
    (1.25, 6.55) -- (1.25, 5.72) -- (1.02,4.6) -- 
    (1.04, 4.14) -- (1.13, 4.2) -- (1.14, 3.92) -- 
    (1.05, 3.84) -- (0.95, 3.84) -- (.83, 3.94) -- 
    (.83, 4.17) -- (.88, 4.52) -- (.90, 4.85) -- 
    (1, 5.37) -- (1.04, 5.66) -- (1.03, 6.05) -- 
    (.85, 6.47) -- (.81, 6.53);
    \end{scope}
}   
\def\claviculaS#1#2#3{
    \begin{scope}[shift={#1}, rotate=#2, scale={#3}, draw opacity=1]        
        \draw (1.02, 6.79) -- (1.19, 6.79) -- (1.33, 6.71) -- 
    (1.7, 6.35) -- (1.62, 6.22) -- (1.52, 6.26) -- 
    (1.52, 6.32) -- (1.4, 6.5) -- (1.24, 6.66) -- 
    (1.16, 6.71) -- (1.02, 6.71) -- (1.02, 6.79);
    \end{scope}
}   
\def\scapulaS#1#2#3{
    \begin{scope}[shift={#1}, rotate=#2, scale={#3}, draw opacity=1]        
        \draw (.02, 5.41) -- (0, 5.5) -- (.08, 6.06) -- 
    (.21, 6.3) -- (.35, 6.43) -- (.46, 6.5) -- 
    (.69, 6.61)--(.83, 6.74)--(.92, 6.76)--(.96, 6.73)--
    (.91, 6.68)--(.8, 6.56)--(.8, 6.48)--(.9, 6.25)--
    (.6, 6.03)--(.41, 5.79)--(.3, 5.6)--(.11, 5.41)--(.02, 5.41);
    \end{scope}
}   
\def\ulnaS#1#2#3#4{
    \begin{scope}[shift={($#1+(-0.89,-3.8)$)}, rotate around={#2:#3}, scale={#4}, draw opacity=1]        
        \draw[fill=white] (.78, 4.19)--(.86, 3.86)--(1.06, 3.3)--(1.21, 2.88)--
    (1.56, 2.12)--(1.83, 1.62)--(1.99, 1.45)--(1.98, 1.38)--
    (1.94, 1.32)--(1.96, 1.24)--(1.9, 1.2)--(1.8, 1.32)--
    (1.75, 1.51)--(1.57, 1.84)--(1.06, 2.8)--(.82, 3.37)--
    (.7, 3.63)--(.6, 4.05)--(.62, 4.16)--(.78, 4.19);
    \end{scope}
}   
\def\radiusS#1#2#3#4{
    \begin{scope}[shift={($#1+(-0.89,-3.8)$)}, rotate around={#2:#3}, scale={#4}, draw opacity=1]        
        \draw[fill=white] (.89, 3.8)--(1.09, 3.82)--(1.13, 3.57)--(1.39, 3.22)--
    (1.68, 2.77)--(1.85,2.44)--(2.08, 1.79)--(2.24, 1.45)--(2.24, 1.36)--
    (1.98, 1.38)--(1.93, 1.55)--(1.86, 1.91)--(1.79, 2.12)--(1.53, 2.72)--
    (1.19, 3.26)--(1.04, 3.41)--(.97, 3.62)--(.89, 3.8);
    \end{scope}
}   
\def\handS#1#2#3#4{
    \begin{scope}[shift={($#1+(-0.89,-3.8)$)}, rotate around={#2:#3}, scale={#4}, draw opacity=1]        
        \draw[fill=white] (1.98, 1.35)--(2.21, 1.36)--(2.32, 1.28)--(2.34, 1.19)--
    (2.66, .77)--(2.67, .73)--(2.62, .75)--(2.32, 1.14)--(2.33, 1.04)--
    (2.72, .24)--(2.72, .19)--(2.68, .22)--(2.3, 1.04)--(2.24, 1.05)--
    (2.25, .97)--(2.6, .05)--(2.6, 0)--(2.56, .03)--(2.21, .99)--
    (2.17, 1.05)--(2.16, .98)--(2.4, .18)--(2.39, .14)--(2.36, .18)--
    (2.11, 1.03)--(2.12, .74)--(2.25, .32)--(2.25, .27)--(2.22, .31)--
    (2.06, .82)--(2.03, 1.21)--(1.97, 1.32)--(1.98, 1.35);
    \end{scope}
}   

\def\repereXY#1#2#3{
    \begin{scope}[shift={#1}, rotate=#2, scale={#3}, draw opacity=1]        
        \draw[->] (0,0) -- (1,0) node[above] {$x$};
        \draw[->] (0,0) -- (0,1) node[above] {$y$};        
    \end{scope}
} 

\begin{document}
\begin{tikzpicture}     
    \node (elbow_flex_0) at (1, 3.97) {};        
    \coordinate (shoulder_flex) at (1.05, 6.5);        

    %do not rotate
    \scapulaS{(0,0)}{0}{1}        
    \claviculaS{(0,0)}{0}{1}        

    \foreach \sf in {0,1,...,30} {
        \humerusS{(0,0)}{\sf}{(shoulder_flex)}{1}        

        \node(elbow_flex) at ([rotate around={\sf:(shoulder_flex)}]elbow_flex_0) {};        
%        \path (elbow_flex_0) ++({3.56*sin(\sf)}:{-3.56*cos(\sf)}) node (elbow_flex) {}; 

        \def\ef{50}
        %\foreach \ef in {55,56,...,69} {
            \radiusS{(elbow_flex)}{\ef}{(elbow_flex)}{1}        
            \ulnaS{(elbow_flex)}{\ef}{(elbow_flex)}{1}        
            \handS{(elbow_flex)}{\ef}{(elbow_flex)}{1}     
%        %}   
    }

    %reference frame
    \repereXY{(4,5.5)}{0}{.5}      

\end{tikzpicture}
\end{document}

相关内容