tdplotsetrotatedcoord ' 参数

tdplotsetrotatedcoord ' 参数

这需要在原点 (A) = (0,0) 且尺寸为 2 厘米的红色参考系中制作一个金字塔(四面体,SABCD),然后在面上描绘一个绿色三角形 ((S), (B), (C)),为此,毫无疑问需要暂时确定原点 (B) 的参考点(蓝色),其横坐标与半线 [BC] 重合,因此与主横坐标轴平行,纵坐标与半右 [BS] 重合。

必须使用路径 绘制绿色三角形(start) -- ++(60:2) -- ++(-60:2) -- cycle。我无法确定计算 参数的代码行\tdplotsetrotatedcoords{\alpha}{\beta}{\gamma}。下面的代码可以编译,只需更正计算。注意:BC 的首项系数(因此是蓝色标记中的横坐标)与原始红色标记 (A) 中的线 AD 的首项系数相同。我们可以在模型上引入其他焦点线\node at (0,0, -5) {alpha: \alpha, beta: \beta gamma; \gamma}

\input{preambule-utf8.ltx}
 


\begin{document}
 
    
    
    \newcommand{\DefinePoints}[1]{%
        \foreach \x/\y/\z/\name in {#1} {
            \coordinate (\name) at (\x, \y, \z);
        }
    }
    

        
    \tdplotsetmaincoords{70}{120}  % Si absent, « tdplot_main_coords » sera inconnu 
                
    \begin{tikzpicture}[tdplot_main_coords,
    line cap=round,line join=round,>=triangle 45,scale=2]
    
\tdplotsetmaincoords{70}{120} 

\draw[line width=1pt, red] (0,0,0) -- (3,0,0) node[below right]{$X$};
\draw[line width=1pt, red] (0,0,0) -- (0,3,0) node[below right]{$Y$};
\draw[line width=1pt, red] (0,0,0) -- (0,0,2.5) node[below right]{$Z$};


\def\cote{2}
\DefinePoints{
    0/                0/                      0/A, 
    \cote/                0/                      0/B,
    \cote/         \cote/                      0/C,
    0/          \cote/                     0/D,
    0.5*\cote/  0.5*\cote/         \cote     /S,
    0/                0/          \cote     /Z%
}       

\draw (A) -- (B) -- (C) -- (D) -- cycle;
\foreach \point in {A, B, C, D} {
    \draw  (S)  -- (\point);
}

\draw  (A) -- (S) -- (B);
\draw   (B) -- (S) -- (C);

% Calcul des angles pour le changemnt de repère momentané 

    \tdplotsetrotatedcoordsorigin{(A)}
    

% Calcul des vecteurs BC, BS et AD
\coordinate (BC) at ($(C)-(B)$);
\coordinate (BS) at ($(S)-(B)$);
\coordinate (AD) at ($(D)-(A)$);

% Calcul des vecteurs BC, BS et AD
\coordinate (BC) at ($(C)-(B)$);
\coordinate (BS) at ($(S)-(B)$);
\coordinate (AD) at ($(D)-(A)$);



% Calcul de l'angle α entre BC et l'axe x
\pgfmathanglebetweenpoints
{\pgfpoint{1cm}{0cm}}
{\pgfpointanchor{BC}{center}}
\let\alpha\pgfmathresult

% Calcul de l'angle β entre BS et l'axe y
\pgfmathanglebetweenpoints
{\pgfpoint{0cm}{1cm}}
{\pgfpointanchor{BS}{center}}
\let\beta\pgfmathresult

% Calcul de l'angle γ entre AD et l'axe z
\pgfmathanglebetweenpoints
{\pgfpoint{1cm}{0cm}}
{\pgfpointanchor{AD}{center}}
\let\gamma\pgfmathresult

% Utiliser ces angles pour définir le repère bleu
\tdplotsetrotatedcoords{\alpha}{\beta}{\gamma}

    \tdplotsetrotatedcoordsorigin{(B)}

\node at (0,0, -5)  {alpha : \alpha, beta : \beta gamma ; \gamma} ; 

\begin{scope}[tdplot_rotated_coords]
    
    % Draw blue axes
    \draw[blue, thick,->](0,0)--(3,0,0)node[below right]{$X'$};
    \draw[blue, thick,->](0,0)--(0,3,0)node[below left]{$Y'$};
    \draw[blue, thick,->](0,0)--(0,0,3)node[above]{$Z'$};    
    
  \draw[-, green, line width=2pt] (B) -- ++(60:2) -- ++(-60:2) ; %   -- cycle ;
    
\end{scope}




\foreach \n/\pos  in {S/above, A/{above left}, B/{above left}, C/below, D/{above right}, Z/right}{
    \tkzDrawPoint (\n)
    \tkzLabelPoints[\pos](\n)           
} 
\node at (0,0, -5)  {alpha : \alpha, beta : \beta gamma ; \gamma} ; 
    
\end{tikzpicture}

    \end{document}

谢谢你帮助我摆脱因无法解决这个问题而导致的强迫症 80)

我期待着目标更持久


考虑到我对“tikz-3dplot_documentation.pdf”的阅读,我试图在我的代码注释中更加明确地说明,一定是有些东西我忘记了,因为结果是:

在此处输入图片描述

使用以下代码。

    \newcommand{\DefinePoints}[1]{%
        \foreach \x/\y/\z/\name in {#1} {
            \coordinate (\name) at (\x, \y, \z);
        }
    }
    
    
\tdplotsetmaincoords{70}{120}%
 

    \begin{tikzpicture} [ 
             tdplot_main_coords,        
             cube/.style={very thick,black},
              grid/.style={very thin,gray},
                           axis/.style={->,blue,thick},
           rotated axis/.style={->,purple,thick},
           line cap=round,
           line join=round,
           >=triangle 45,
           scale=3]
  
  \draw[axis, tdplot_main_coords, red] (0,0,0) -- (4,0,0) node[anchor=south]{$x$};
 \draw[axis,  tdplot_main_coords, red] (0,0,0) -- (0,3,0) node[anchor=north west]{$y$};
  \draw[axis, tdplot_main_coords, red] (0,0,0) -- (0,0,3) node[anchor=west]{$z$};
  
  
  \def\cote{2}
   \pgfmathsetmacro{\hauteur}{sqrt(3) } 
   
  \DefinePoints{
    0/                0/                      0/A, 
    \cote/                0/                      0/B,
    \cote/         \cote/                      0/C,
    0/          \cote/                     0/D,
    0.5*\cote/  0.5*\cote/    \hauteur  /S,
    0/                0/          \cote     /Z%
  }       
  
  \draw[ ] (A) -- (B) -- (C) -- (D) -- cycle;
  \foreach \point in {A, B, C, D} {
    \draw  (S)  -- (\point);
  }
  
  \draw[ ]  (A) -- (S) -- (B);
  \draw[ ]   (B) -- (S) -- (C);
 
% -------------------------------------------- 
% Calculate the rotation angles
% α (alpha) : Rotation z of α degrees to align the z' axis with the global Z axis
\pgfmathanglebetweenpoints
{\pgfpointanchor{B}{center}}
{\pgfpointanchor{Z}{center}}
\let\alpha\pgfmathresult

% β (beta) : Rotation y of β degrees with respect to the system resulting from the first rotation
\pgfmathanglebetweenpoints
{\pgfpointanchor{B}{center}}
{\pgfpointanchor{D}{center}} % Use the point corresponding to the Y axis in the system resulting from the first rotation
\let\beta\pgfmathresult

% γ (gamma) : Rotation z of γ degrees with respect to the system resulting from the first two rotations
\pgfmathanglebetweenpoints
{\pgfpointanchor{B}{center}}
{\pgfpointanchor{B}{center}} % Use the point corresponding to the X axis in the system resulting from the first two rotations
\let\gamma\pgfmathresult

\tdplotsetrotatedcoords{60}{90}{0}

\tdplotsetrotatedcoordsorigin{(B)}

% ---------------------------------------------------
 

    \begin{scope}[tdplot_rotated_coords]
 
 
    % draw the rotated coordinate frame axes
    \draw[rotated axis, blue, line width=1pt] (0,0,0) -- (3,0,0) node[anchor=west]{$x'$};
    \draw[rotated axis, blue, line width=1pt]  (0,0,0) -- (0,4,0) node[anchor=south west]{$y'$};
    \draw[rotated axis, blue, line width=1pt]  (0,0,0) -- (0,0,3) node[anchor=west]{$z'$};
    
    
    \draw (0,0,0) -- (1.5*\cote,0,0) -- (1.5*\cote, 1.5*\cote, 0) -- (0,1.5*\cote,0) -- cycle ; 
 
 % Tracer le triangle vert avec un chemin relatif dans le plan (SBC)    
  
  \draw[-, green, line width=2pt] (B) -- ++(60:2) -- ++(-60:2) ; %   -- cycle ;
 
    
 \end{scope} 
  
    \node at (1,-1, -2)  {alpha : \alpha } ; 
   \node at (1,-1, -2.5)  {beta  : \beta} ; 
  \node at (1,-1, -3)  {gamma : \gamma} ; 
  
                
        \foreach \n/\pos  in {S/above, A/{above left}, B/{above left}, C/below, D/{above right}, Z/right}{
            \tkzDrawPoint (\n)
            \tkzLabelPoints[\pos](\n)           
        } 
 

    \end{tikzpicture}

我失眠了!

答案1

我又睡着了在此处输入图片描述

 \documentclass[12pt]{standalone}
 
 \usepackage{tkz-base}
 \usepackage{tikz-3dplot}
 %
 % Jj Dhénin: 2023/10/11
 
 % Uncomment if necessary
 % \newcommand{\MainAxes}{}  % main_coords,
 % \newcommand{\RotatedAxes}{}  % rotated axis,
 % \newcommand{\FacilitateFocus}{}
 
 \tikzset{
    axis/.style={->, blue, thick},
    rotated axis/.style={->, purple, thick},
    base/.style={gray!60},
    line cap=round,
    line join=round,
    >=triangle 45,
    base/.style={gray!50}
 }
 
 \begin{document}
    
    % Following the tkz-euclide model, "\definePoints"
    \newcommand{\DefinePoints}[1]{%
        \foreach \x/\y/\z/\name in {#1} {
            \coordinate (\name) at (\x, \y, \z);
        }
    }
    
    % The small base triangle
    % #1: Initial position, e.g., (X)
    % #2: Length of the triangle's side
    % #3: Color and other style arguments
    \newcommand\faisUn[3] {\fill[#3] #1  -- ++(-60:#2)  -- ++(-#2,0) -- cycle;
    }
    
    % Three "solid" triangles around an empty triangle
    % #1: Initial position, e.g., (X)
    % #2: Length of the triangle's side
    % #3: Color and other style arguments
    \newcommand{\faisTrois}[3]{
        \coordinate  (X) at (#1) ;
        \coordinate  (tmpA) at (X) ;
        \def\coteA{#2}
        \faisUn{(X)} {\coteA}{#3}
        \coordinate (X) at ([shift={(-120:\coteA)}]X);
        \faisUn{(X)} {\coteA} {#3}
        \coordinate (X) at ([shift={(\coteA,0)}]X);
        \faisUn{(X)} {\coteA} {#3}
        \coordinate  (X) at (tmpA) ;
    }
    
    % Three times three "solid" triangles around an empty triangle
    % #1: Initial position, e.g., (X)
    % #2: Length of the triangle's side
    % #3: Color and other style arguments
    \newcommand{\faisNeuf}[3]{
        \coordinate  (X) at (#1) ;
        \coordinate  (tmpB) at (X) ;
        \def\coteB{#2}
        
        \faisTrois{X}{\coteB}{#3}
        
        \coordinate (X) at ([shift={(-120:2*\coteB)}]X);
        
        \faisTrois{X}{\coteB}{#3}
        \coordinate (X) at ([shift={(2*\coteB,0)}]X);
        
        \faisTrois{X}{\coteB}{#3}
        
        \coordinate  (X) at (tmpB) ;
    }
    
    % 3 x three times 3 "solid" triangles around an empty triangle
    % #1: Initial position, e.g., (X)
    % #2: Length of the triangle's side
    % #3: Color and other style arguments
    \newcommand{\faisTroisNeuf}[3]{
        \coordinate  (X) at (#1) ;
        \coordinate  (tmpC) at (X) ;
        \def\coteC{#2}
        
        \faisNeuf{X}{\coteC}{#3}
        
        \coordinate (X) at ([shift={(-120:4*\coteB)}]X);
        \faisNeuf{X}{\coteC}{#3}
        
        \coordinate (X) at ([shift={(4*\coteB,0)}]X);
        \faisNeuf{X}{\coteC}{#3}
    }
    
    % ------------
    % Create a face based on
    % #1: Orientation of the abscissas according to the face
    % #2: Bottom-left vertex of the face (A or B or C or D)
    % #3: Color and other style of the face
    % #4: Step (level of division)
    \newcommand\faireFace[4]{
        
        \def\alpha{#1}
        %   \beta has been calculated once and for all during initialization
        \def\gamma{90}
        
        % Origin at the bottom right of the triangle
        \tdplotsetrotatedcoordsorigin{#2}
        
        \tdplotsetrotatedcoords{\alpha}{\beta}{\gamma}
        
        \begin{scope}[tdplot_rotated_coords]
            \ifdefined\RotatedAxes
            \draw[rotated axis, blue, line width=1pt] (0,0,0) -- (5,0,0) node[anchor=west]{$x'$};
            \draw[rotated axis, blue, line width=1pt]  (0,0,0) -- (0,4,0) node[anchor=south west]{$y'$};
            \draw[rotated axis, blue, line width=1pt]  (0,0,0) -- (0,0,3) node[anchor=west]{$z'$};
            \fi
            
            % Use the top of the triangle to position it, regardless of its size
            \coordinate  (X) at (S) ;
            
            \ifnum #4=4
            \def\cote{4}    % Length of the edge
            \def\coteDeco{0.25} % Length of the side of the small triangle
            \faisTroisNeuf{X} {\coteDeco}{#3}
            
            \coordinate (X) at ([shift={(-0.25*\cote,0)}]X);
            \coordinate (X) at ([shift={(-120:0.25*\cote)}]X);
            
            \faisTroisNeuf{X} {\coteDeco}{#3}
            
            \coordinate (X) at ([shift={(0.25*\cote,0)}]X);
            \coordinate (X) at ([shift={(60:0.25*\cote)}]X);
            \faisTroisNeuf{X} {\coteDeco}{#3}
            \fi
            \ifnum #4=3
            \def\cote{4}    % Length of the edge
            \def\coteDeco{0.5} % Length of the side of the small triangle
            
            \faisNeuf{X}{\coteDeco}{#3}
            
            \coordinate (X) at ([shift={(-120:0.5*\cote)}]X);
            \faisNeuf{X}{\coteDeco}{#3}
            
            \coordinate (X) at ([shift={(0.5*\cote,0)}]X);
            \faisNeuf{X}{\coteDeco}{#3}
            
            \fi
            
            \ifnum #4=2
            \def\cote{4}    % Length of the edge
            \def\coteDeco{1} % Length of the side of the small triangle
            
            \faisTrois{X}{\coteDeco}{#3}
            
            \coordinate (X) at ([shift={(-120:0.5*\cote)}]X);
            \faisTrois{X}{\coteDeco}{#3}
            
            \coordinate (X) at ([shift={(0.5*\cote,0)}]X);
            \faisTrois{X}{\coteDeco}{#3}
            
            \fi
            
            \ifnum #4=1
            
            \def\cote{4}    % Length of the edge
            \def\coteDeco{2} % Length of the side of the small triangle
            
            \faisUn{(X)} {\coteDeco} {#3}
            
            \coordinate (X) at ([shift={(-120:0.5*\cote)}]X);
            \faisUn{(X)} {\coteDeco} {#3}
            
            \coordinate (X) at ([shift={(0.5*\cote,0)}]X);
            \faisUn{(X)} {\coteDeco} {#3}
            
            \fi
            
            \ifnum #4=0
            
            \def\cote{4}    % Length of the edge
            \def\coteDeco{4} % Length of the side of the small triangle
            
            \faisUn{(X)} {\coteDeco} {#3}
            
            \fi
            
        \end{scope}
    } % End of command faireFace
    
    \tdplotsetmaincoords{70}{120}%
    
    % We need five different pyramids
    % #1: Step number
    % #2: Measurement of the pyramid
    % #3: Measurement of the triangle's side (according to the step)
    \newcommand\faisLaPyramide[1]{
        \setbox1\hbox{
            \begin{tikzpicture} [
                tdplot_main_coords,
                scale=0.35       % Set the scale here!
                ]
                
                % Draw the main axes
                \ifdefined\MainAxes
                \draw[axis, tdplot_main_coords, red] (0,0,0) -- (5,0,0) node[anchor=south]{$x$};
                \draw[axis,  tdplot_main_coords, red] (0,0,0) -- (0,5,0) node[anchor=north west]{$y$};
                \draw[axis, tdplot_main_coords, red] (0,0,0) -- (0,0,3) node[anchor=west]{$z$};
                \fi
                
                % Initialization of characteristics
                \def\cote{4}    % Length of the edge
                
                \def\coteDeco{0.25} % Length of the side of the small triangle
                % Measurement of the height of the main face
                \pgfmathsetmacro{\SMbc} {sqrt( (\cote)^2   -    (0.5*\cote)^2 }
                % Measurement of the height of the pyramid
                \pgfmathsetmacro{\hauteur}   {sqrt( (\SMbc)^2   -    (0.5*\cote)^2 }
                
                % Angle of a face with the base
                \pgfmathsetmacro{\beta}{atan2(\hauteur, 0.5*\cote}
                % Vertices and useful points
                \DefinePoints{
                    0/                0/                      0/A,
                    \cote/                0/                      0/B,
                    \cote/         \cote/                      0/C,
                    0/          \cote/                     0/D,
                    0.5*\cote/  0.5*\cote/    \hauteur  /S,
                    \cote/  0.5*\cote/    0/Mbc
                }
                
                % Shaded base
                \fill [base] (A) -- (B) -- (C) -- (D) -- cycle;
                
                \ifdefined\FacilitateFocus
                % Pyramid's contour
                \foreach \point in {A, B, C, D} {
                    \draw  (S)  -- (\point);
                }
                
                \draw[ ]  (A) -- (S) -- (B);
                \draw[ ]   (B) -- (S) -- (C);
                \fi
                
                % Face on the right (DSA)
                % Starting with a face hidden by the front
                \faireFace{180} {(D)} {red!40}  {#1}   % Perspective distorts and deceives
                
                % Front face on the right (DSA)
                \faireFace{270}  {(A)} {red!50} {#1}    % Perspective distorts and deceives
                
                % Front face on the left (BSC)
                \faireFace{0} {(B)}  {red!60} {#1}
                
                % Front face on the right (CSD)
                \faireFace{90}  {(C)} {red!70} {#1}
                
                \ifdefined\FacilitateFocus
                \foreach \n/\pos  in {S/above, A/{above left}, B/{above left}, C/below, D/{above right},   Mbc/below}{
                    \tkzDrawPoint (\n)
                    \tkzLabelPoints[\pos](\n)
                }
                \fi
                
            \end{tikzpicture}
        } % End of setbox1\hbox
    } % End of command\faisLaPyramide
    
    \begin{tikzpicture}
        
        \faisLaPyramide{0}
        \node at (0,0) {\box1};
        
        \faisLaPyramide{1}
        \node at (2,0) {\box1};
        
        \faisLaPyramide{2}
        \node at (4,0) {\box1};
        
        \faisLaPyramide{3}
        \node at (6,0) {\box1};
        
        \faisLaPyramide{4}
        \node at (8,0) {\box1};
    \end{tikzpicture}
    
 \end{document}

很诚挚

相关内容