直线与平面的交点,我的代码哪里错误?

直线与平面的交点,我的代码哪里错误?

假设SABCD是金字塔,A(0,0,0)B(-2,5,0)C(4,4,0)D(6,2,0),是两条直线和的交点。一个平面通过并平行于直线,分别在,,,处与直线 ,,相交。我们可以证明, 平行于S(a,b,h),平行 于。在我的代码中,我看到 , 不平行于。通过计算,我得到了点(图中为)的坐标为OACBDOABSCABBCSBSAEFGHEFGHABOHSCOHSCHH'

({-238*\h*\a/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))}, {-238*\h*\b/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))}, {-238*\h^2/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))})

然后,OH'与 平行SC

在此处输入图片描述

这是我的代码库,答案如下一条线与一个平面的交点,第三种方法哪里错了?

 \documentclass[border=3.14mm,12pt,tikz]{standalone}
\usepackage{tikz,tikz-3dplot} 

\usetikzlibrary{intersections,calc,backgrounds}
%% smuggling from https://tex.stackexchange.com/a/470979/121799
\newcounter{smuggle}
\DeclareRobustCommand\smuggleone[1]{%
    \stepcounter{smuggle}%
    \expandafter\global\expandafter\let\csname smuggle@\arabic{smuggle}\endcsname#1%
    \aftergroup\let\aftergroup#1\expandafter\aftergroup\csname smuggle@\arabic{smuggle}\endcsname
}
\DeclareRobustCommand\smuggle[2][1]{%
    \smuggleone{#2}%
    \ifnum#1>1
    \aftergroup\smuggle\aftergroup[\expandafter\aftergroup\the\numexpr#1-1\aftergroup]\aftergroup#2%
    \fi
}

\def\parsecoord(#1,#2,#3)>(#4,#5,#6){%
    \def#4{#1}%
    \def#5{#2}%
    \def#6{#3}%
    \smuggle{#4}%
    \smuggle{#5}%
    \smuggle{#6}%
}
\def\SPTD(#1,#2,#3).(#4,#5,#6){#1*#4+#2*#5+#3*#6}
\def\VPTD(#1,#2,#3)x(#4,#5,#6){(#2*#6-#3*#5,#3*#4-#1*#6,#1*#5-#2*#4)}
\def\VecMinus(#1,#2,#3)-(#4,#5,#6){(#1-#4,#2-#5,#3-#6)}
\def\VecAdd(#1,#2,#3)+(#4,#5,#6){(#1+#4,#2+#5,#3+#6)}
\tikzset{intersection of line trough/.style args={#1 and #2 with plane
        containing #3 and normal #4}{%
        /utils/exec={\pgfmathsetmacro{\ltest}{abs(\SPTD#2.#4-(\SPTD#1.#4))}
            \parsecoord#1>(\myAx,\myAy,\myAz)
            \parsecoord#2>(\myBx,\myBy,\myBz)
            \ifdim\ltest pt<0.01pt
            \typeout{Plane\space and\space line\space are\space parallel!\ltest}
            \pgfmathsetmacro{\myd}{0}
            \else
            \pgfmathsetmacro{\myd}{((\SPTD#3.#4)-(\SPTD#1.#4))/((\SPTD#2.#4)-(\SPTD#1.#4))}
            \fi
            %\typeout{({\myAx+\myd*(\myBx-\myAx)},{\myAy+\myd*(\myBy-\myAy)},{\myAz+\myd*(\myBz-\myAz)})}
            \def\myP{({\myAx+\myd*(\myBx-\myAx)},{\myAy+\myd*(\myBy-\myAy)},{\myAz+\myd*(\myBz-\myAz)})}
            \smuggle\myP},
        insert path={%
            \myP}
}}

\begin{document}
    \tdplotsetmaincoords{70}{90}
    \begin{tikzpicture}[tdplot_main_coords,scale=1,line join = round, line cap = round]
    \pgfmathsetmacro\a{3}
    \pgfmathsetmacro\b{3}
    \pgfmathsetmacro\h{4}


    % definitions
    \path 
    coordinate(A) at (0,0,0)
    coordinate (D) at (6,2,0)
    coordinate (C) at (4,4,0) 
    coordinate (B) at (-2,5,0)                            
    coordinate (S) at (\a,\b,\h)
    coordinate (H') at ({-238*\h*\a/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))}, {-238*\h*\b/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))}, {-238*\h^2/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))})
    ;   

\begin{scope}
\draw [dashed,  name path=B--D] (B) -- (D);
\draw [dashed,  name path=A--C] (A) -- (C);
\path [name intersections={of=B--D and A--C,by=O}];
\end{scope}     

\def\mynormal{\VPTD(-2,5,0)x(4 - \a, 4 - \b, -\h)}
    \typeout{\mynormal:(-5 \h, -2 \h, -28 + 5 \a + 2 \b)}
    \path[intersection of line trough={(0,0,0) and (6,2,0) with plane containing (34/11, 34/11, 0) and normal (-5 \h, -2 \h, -28 + 5 \a + 2 \b)}]  coordinate (E);

    \def\mynormal{\VPTD(-2,5,0)x(4 - \a, 4 - \b, -\h)}
    \typeout{\mynormal:(-5 \h, -2 \h, -28 + 5 \a + 2 \b)}
    \path[intersection of line trough={ (-2,5,0) and (4,4,0) with plane containing (34/11, 34/11, 0) and normal (-5 \h, -2 \h, -28 + 5 \a + 2 \b)}]  coordinate (F);

    \def\mynormal{\VPTD(-2,5,0)x(4 - \a, 4 - \b, -\h)}
    \typeout{\mynormal:(-5 \h, -2 \h, -28 + 5 \a + 2 \b)}
    \path[intersection of line trough={(0,0,0) and (\a,\b,\h) with plane containing (34/11, 34/11, 0) and normal (-5 \h, -2 \h, -28 + 5 \a + 2 \b)}]  coordinate (H);

    \def\mynormal{\VPTD(-2,5,0)x(4 - \a, 4 - \b, -\h)}
    \typeout{\mynormal:(-5 \h, -2 \h, -28 + 5 \a + 2 \b)}
    \path[intersection of line trough={(-2,5,0) and (\a,\b,\h) with plane containing (34/11, 34/11, 0) and normal (-5 \h, -2 \h, -28 + 5 \a + 2 \b)}]  coordinate (G);

   \begin{scope}
    \draw[very thick]
  (S)--(A) -- (D) --(C) -- (B) --cycle 
  (S)-- (B) (S)--(C) (S)--(D) (H)--(E) (F)--(G);
  \draw[dashed]
  (S) -- (O)   (A) --(B) (H)--(G) (E)-- (F) (O) --(H);
   \end{scope} 

 \draw[dashed,red] (O) -- (H'); 


    \foreach \point/\position in {A/left,D/below,C/below,S/above,B/right,O/below,E/left,F/right,G/right,H/left,H'/above}
    {
        \fill (\point) circle (1.5pt);
        \node[\position=1.5pt] at (\point) {$\point$};
    }

    \end{tikzpicture}
\end{document} 

我的代码哪里错误了?

我按照 marmot 的评论做了,得到了

\documentclass[border=3.14mm,12pt,tikz]{standalone}
\usepackage{tikz,tikz-3dplot} 

\usetikzlibrary{intersections,calc,backgrounds}
%% smuggling from https://tex.stackexchange.com/a/470979/121799
\newcounter{smuggle}
\DeclareRobustCommand\smuggleone[1]{%
    \stepcounter{smuggle}%
    \expandafter\global\expandafter\let\csname smuggle@\arabic{smuggle}\endcsname#1%
    \aftergroup\let\aftergroup#1\expandafter\aftergroup\csname smuggle@\arabic{smuggle}\endcsname
}
\DeclareRobustCommand\smuggle[2][1]{%
    \smuggleone{#2}%
    \ifnum#1>1
    \aftergroup\smuggle\aftergroup[\expandafter\aftergroup\the\numexpr#1-1\aftergroup]\aftergroup#2%
    \fi
}

\def\parsecoord(#1,#2,#3)>(#4,#5,#6){%
    \def#4{#1}%
    \def#5{#2}%
    \def#6{#3}%
    \smuggle{#4}%
    \smuggle{#5}%
    \smuggle{#6}%
}
\def\SPTD(#1,#2,#3).(#4,#5,#6){#1*#4+#2*#5+#3*#6}
\def\VPTD(#1,#2,#3)x(#4,#5,#6){(#2*#6-#3*#5,#3*#4-#1*#6,#1*#5-#2*#4)}
\def\VecMinus(#1,#2,#3)-(#4,#5,#6){(#1-#4,#2-#5,#3-#6)}
\def\VecAdd(#1,#2,#3)+(#4,#5,#6){(#1+#4,#2+#5,#3+#6)}
\tikzset{intersection of line trough/.style args={#1 and #2 with plane
        containing #3 and normal #4}{%
        /utils/exec={\pgfmathsetmacro{\ltest}{abs(\SPTD#2.#4-(\SPTD#1.#4))}
            \parsecoord#1>(\myAx,\myAy,\myAz)
            \parsecoord#2>(\myBx,\myBy,\myBz)
            \ifdim\ltest pt<0.01pt
            \typeout{Plane\space and\space line\space are\space parallel!\ltest}
            \pgfmathsetmacro{\myd}{0}
            \else
            \pgfmathsetmacro{\myd}{((\SPTD#3.#4)-(\SPTD#1.#4))/((\SPTD#2.#4)-(\SPTD#1.#4))}
            \fi
            %\typeout{({\myAx+\myd*(\myBx-\myAx)},{\myAy+\myd*(\myBy-\myAy)},{\myAz+\myd*(\myBz-\myAz)})}
            \def\myP{({\myAx+\myd*(\myBx-\myAx)},{\myAy+\myd*(\myBy-\myAy)},{\myAz+\myd*(\myBz-\myAz)})}
            \smuggle\myP},
        insert path={%
            \myP}
}}

\begin{document}
    \tdplotsetmaincoords{70}{90}
    \begin{tikzpicture}[tdplot_main_coords,scale=1,line join = round, line cap = round]
    \pgfmathsetmacro\a{3}
    \pgfmathsetmacro\b{3}
    \pgfmathsetmacro\h{4}


    % definitions
    \path 
    coordinate(A) at (0,0,0)
    coordinate (D) at (6,2,0)
    coordinate (C) at (4,4,0) 
    coordinate (B) at (-2,5,0)                            
    coordinate (S) at (\a,\b,\h)
    coordinate (H') at ({-238*\h*\a/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))}, {-238*\h*\b/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))}, {-238*\h^2/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))})
    ;   

\begin{scope}
\draw [dashed,  name path=B--D] (B) -- (D);
\draw [dashed,  name path=A--C] (A) -- (C);
\path [name intersections={of=B--D and A--C,by=O}];
\end{scope}     

\def\mynormal{\VPTD(-2,5,0)x(4 - \a, 4 - \b, -\h)}
    \typeout{\mynormal:(-5*\h, -2*\h, -28 + 5*\a + 2*\b)}
    \path[intersection of line trough={(0,0,0) and (6,2,0) with plane containing (34/11, 34/11, 0) and normal (-5*\h, -2*\h, -28 + 5*\a + 2*\b)}]  coordinate (E);

    \def\mynormal{\VPTD(-2,5,0)x(4 - \a, 4 - \b, -\h)}
    \typeout{\mynormal:(-5*\h, -2*\h, -28 + 5*\a + 2*\b)}
    \path[intersection of line trough={ (-2,5,0) and (4,4,0) with plane containing (34/11, 34/11, 0) and normal (-5*\h, -2*\h, -28 + 5*\a + 2*\b)}]  coordinate (F);

    \def\mynormal{\VPTD(-2,5,0)x(4 - \a, 4 - \b, -\h)}
    \typeout{\mynormal:(-5*\h, -2*\h, -28 + 5*\a + 2*\b)}
    \path[intersection of line trough={(0,0,0) and (\a,\b,\h) with plane containing (34/11, 34/11, 0) and normal (-5*\h, -2*\h, -28 + 5*\a + 2*\b)}]  coordinate (H);

    \def\mynormal{\VPTD(-2,5,0)x(4 - \a, 4 - \b, -\h)}
    \typeout{\mynormal:(-5*\h, -2*\h, -28 + 5*\a + 2*\b)}
    \path[intersection of line trough={(-2,5,0) and (\a,\b,\h) with plane containing (34/11, 34/11, 0) and normal (-5*\h, -2*\h, -28 + 5*\a + 2*\b)}]  coordinate (G);

   \begin{scope}
    \draw[very thick]
  (S)--(A) -- (D) --(C) -- (B) --cycle 
  (S)-- (B) (S)--(C) (S)--(D) (H)--(E) (F)--(G);
  \draw[dashed]
  (S) -- (O)   (A) --(B) (H)--(G) (E)-- (F) (O) --(H);
   \end{scope} 

 \draw[dashed,red] (O) -- (H'); 


    \foreach \point/\position in {A/left,D/below,C/below,S/above,B/right,O/below,E/left,F/right,G/right,H/left,H'/above}
    {
        \fill (\point) circle (1.5pt);
        \node[\position=1.5pt] at (\point) {$\point$};
    }

    \end{tikzpicture}
\end{document} 

代码由

\documentclass[border=3.14mm,12pt,tikz]{standalone}
\usepackage{tikz,tikz-3dplot} 

\begin{document}

\tdplotsetmaincoords{70}{90}
    \begin{tikzpicture}[tdplot_main_coords,scale=1,line join = round, line cap = round]
    \pgfmathsetmacro\a{3}
    \pgfmathsetmacro\b{3}
    \pgfmathsetmacro\h{4}


    % definitions
    \path 
    coordinate(A) at (0,0,0)
    coordinate (D) at (6,2,0)
    coordinate (C) at (4,4,0) 
    coordinate (B) at (-2,5,0)                            
    coordinate (S) at (\a,\b,\h)
    coordinate (O) at (34/11, 34/11, 0)
coordinate (E) at (42/11, 14/11, 0)
coordinate (F) at (29/11, 93/22, 0) 
coordinate (H) at ({-238*\h*\a/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))}, {-238*\h*\b/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))}, {-238*\h^2/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))})
coordinate (G) at ({-2-238*\h*(2+\a)/(11*(-5*\h*(2+\a)-2*\h*(-5+\b)+(-28+2*\b+5*\a)*\h))}, {5-238*\h*(-5+\b)/(11*(-5*\h*(2+\a)-2*\h*(-5+\b)+(-28+2*\b+5*\a)*\h))},{ -238*\h^2/(11*(-5*\h*(2+\a)-2*\h*(-5+\b)+(-28+2*\b+5*\a)*\h))});   

 \begin{scope}
    \draw[very thick]
  (S)--(A) -- (D) --(C) -- (B) --cycle 
  (S)-- (B) (S)--(C) (S)--(D) (H)--(E) (F)--(G);
  \draw[dashed]
  (S) -- (O)   (A) --(B) (H)--(G) (E)-- (F) (O) --(H);
   \end{scope} 

 \draw[dashed,red] (O) -- (H); 


    \foreach \point/\position in {A/left,D/below,C/below,S/above,B/right,O/below,E/left,F/right,G/right,H/left}
    {
        \fill (\point) circle (1.5pt);
        \node[\position=1.5pt] at (\point) {$\point$};
    }

    \end{tikzpicture}
\end{document} 

在此处输入图片描述 在此处输入图片描述

答案1

抱歉,您说得对。仍然有解析错误。本质上,有些减号没有正确相乘。为了纠正这个问题,我将向量运算重写为

\def\SPTD(#1,#2,#3).(#4,#5,#6){((#1)*(#4)+1*(#2)*(#5)+1*(#3)*(#6))}
\def\VPTD(#1,#2,#3)x(#4,#5,#6){((#2)*(#6)-1*(#3)*(#5),(#3)*(#4)-1*(#1)*(#6),(#1)*(#5)-1*(#2)*(#4))}
\def\VecMinus(#1,#2,#3)-(#4,#5,#6){(#1-1*(#4),#2-1*(#5),#3-1*(#6))}
\def\VecAdd(#1,#2,#3)+(#4,#5,#6){(#1+1*(#4),#2+1*(#5),#3+1*(#6))}

完成此操作后(并在常规中添加乘法符号,但这不是必需的),就可以确认您所说的内容。

\documentclass[border=3.14mm,12pt,tikz]{standalone}
\usepackage{tikz,tikz-3dplot} 

\usetikzlibrary{intersections,calc,backgrounds}
%% smuggling from https://tex.stackexchange.com/a/470979/121799
\newcounter{smuggle}
\DeclareRobustCommand\smuggleone[1]{%
    \stepcounter{smuggle}%
    \expandafter\global\expandafter\let\csname smuggle@\arabic{smuggle}\endcsname#1%
    \aftergroup\let\aftergroup#1\expandafter\aftergroup\csname smuggle@\arabic{smuggle}\endcsname
}
\DeclareRobustCommand\smuggle[2][1]{%
    \smuggleone{#2}%
    \ifnum#1>1
    \aftergroup\smuggle\aftergroup[\expandafter\aftergroup\the\numexpr#1-1\aftergroup]\aftergroup#2%
    \fi
}

\def\parsecoord(#1,#2,#3)>(#4,#5,#6){%
    \def#4{#1}%
    \def#5{#2}%
    \def#6{#3}%
    \smuggle{#4}%
    \smuggle{#5}%
    \smuggle{#6}%
}
\def\SPTD(#1,#2,#3).(#4,#5,#6){((#1)*(#4)+1*(#2)*(#5)+1*(#3)*(#6))}
\def\VPTD(#1,#2,#3)x(#4,#5,#6){((#2)*(#6)-1*(#3)*(#5),(#3)*(#4)-1*(#1)*(#6),(#1)*(#5)-1*(#2)*(#4))}
\def\VecMinus(#1,#2,#3)-(#4,#5,#6){(#1-1*(#4),#2-1*(#5),#3-1*(#6))}
\def\VecAdd(#1,#2,#3)+(#4,#5,#6){(#1+1*(#4),#2+1*(#5),#3+1*(#6))}
\tikzset{intersection of line trough/.style args={#1 and #2 with plane
        containing #3 and normal #4}{%
        /utils/exec={\pgfmathsetmacro{\ltest}{abs(\SPTD#2.#4-(\SPTD#1.#4))}
            \parsecoord#1>(\myAx,\myAy,\myAz)
            \parsecoord#2>(\myBx,\myBy,\myBz)
            \ifdim\ltest pt<0.01pt
            \typeout{Plane\space and\space line\space are\space parallel!\ltest}
            \pgfmathsetmacro{\myd}{0}
            \else
            \pgfmathsetmacro{\myd}{((\SPTD#3.#4)-(\SPTD#1.#4))/((\SPTD#2.#4)-(\SPTD#1.#4))}
            \fi
            %\typeout{({\myAx+\myd*(\myBx-\myAx)},{\myAy+\myd*(\myBy-\myAy)},{\myAz+\myd*(\myBz-\myAz)})}
            \def\myP{({\myAx+\myd*(\myBx-\myAx)},{\myAy+\myd*(\myBy-\myAy)},{\myAz+\myd*(\myBz-\myAz)})}
            \smuggle\myP},
        insert path={%
            \myP}
}}

\begin{document}
    \tdplotsetmaincoords{70}{90}
    \begin{tikzpicture}[tdplot_main_coords,scale=1,line join = round, line cap = round]
    \pgfmathsetmacro\a{3}
    \pgfmathsetmacro\b{3}
    \pgfmathsetmacro\h{4}


    % definitions
    \path 
    coordinate(A) at (0,0,0)
    coordinate (D) at (6,2,0)
    coordinate (C) at (4,4,0) 
    coordinate (B) at (-2,5,0)                            
    coordinate (S) at (\a,\b,\h)
    coordinate (H') at ({-238*\h*\a/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))}, {-238*\h*\b/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))}, {-238*\h^2/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))})
    ;   

\begin{scope}
\draw [dashed,  name path=B--D] (B) -- (D);
\draw [dashed,  name path=A--C] (A) -- (C);
\path [name intersections={of=B--D and A--C,by=O}];
\end{scope}     

    \def\mynormal{\VPTD(-2,5,0)x({4 - 1*\a},{ 4 - 1*\b},{ -(\h)})}
    %\def\mynormal{\VPTD(-2,5,0)x(4 - \a, 4 - \b, -\h)}
    %\pgfmathprintnumberto{\mynormal}{\myX}
    \edef\temp{\noexpand\parsecoord\mynormal>(\noexpand\myNx,\noexpand\myNy,\noexpand\myNz)}
    \temp
    \pgfmathsetmacro{\myNx}{\myNx}
    \pgfmathsetmacro{\myNy}{\myNy}
    \pgfmathsetmacro{\myNz}{\myNz}
    \edef\temp{\noexpand\parsecoord(-5*\h, -2*\h, -28 + 5*\a + 2*\b)>(\noexpand\myNPx,\noexpand\myNPy,\noexpand\myNPz)}
    \temp
    \pgfmathsetmacro{\myNPx}{\myNPx}
    \pgfmathsetmacro{\myNPy}{\myNPy}
    \pgfmathsetmacro{\myNPz}{\myNPz}
    \typeout{before\space computing:\space\mynormal\space vs.\space(-5*\h, -2*\h, -28 + 5*\a + 2*\b)}
    \typeout{after\space computing:\space(\myNx,\myNy,\myNz)\space vs.\space(\myNPx,\myNPy,\myNPz)}
    \path[intersection of line trough={(0,0,0) and (6,2,0) with plane containing (34/11, 34/11, 0) and normal (-5*\h, -2*\h, -28 + 5*\a + 2*\b)}]  coordinate (E);

    %\def\mynormal{\VPTD(-2,5,0)x(4 - \a, 4 - \b, -\h)}
    %\typeout{\mynormal:(-5*\h, -2*\h, -28 + 5*\a + 2*\b)}
    \path[intersection of line trough={ (-2,5,0) and (4,4,0) with plane containing (34/11, 34/11, 0) and normal (-5*\h, -2*\h, -28 + 5*\a + 2*\b)}]  coordinate (F);

    %\def\mynormal{\VPTD(-2,5,0)x(4 - \a, 4 - \b, -\h)}
    %\typeout{\mynormal:(-5*\h, -2*\h, -28 + 5*\a + 2*\b)}
    \path[intersection of line trough={(0,0,0) and (\a,\b,\h) with plane containing (34/11, 34/11, 0) and normal (-5*\h, -2*\h, -28 + 5*\a + 2*\b)}]  coordinate (H);

    %\def\mynormal{\VPTD(-2,5,0)x(4 - \a, 4 - \b, -\h)}
    %\typeout{\mynormal:(-5*\h, -2*\h, -28 + 5*\a + 2*\b)}
    \path[intersection of line trough={(-2,5,0) and (\a,\b,\h) with plane containing (34/11, 34/11, 0) and normal (-5*\h, -2*\h, -28 + 5*\a + 2*\b)}]  coordinate (G);

   \begin{scope}
    \draw[very thick]
  (S)--(A) -- (D) --(C) -- (B) --cycle 
  (S)-- (B) (S)--(C) (S)--(D) (H)--(E) (F)--(G);
  \draw[dashed]
  (S) -- (O)   (A) --(B) (H)--(G) (E)-- (F) (O) --(H);
   \end{scope} 

 \draw[dashed,red] (O) -- (H'); 


    \foreach \point/\position in {A/left,D/below,C/below,S/above,B/right,O/below,E/left,F/right,G/right,H/left,H'/above}
    {
        \fill (\point) circle (1.5pt);
        \node[\position=1.5pt] at (\point) {$\point$};
    }

    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

这是一个替代方案,它需要3dtools来自这里. 这将使用与 相同的样式来计算坐标这个答案,但不需要用户在前言中粘贴所有宏,因为现在解析由库通过解析器完成。请注意,输入坐标可以是显式的,也可以是符号的,但正如手册符号需要与语法一起放入

\path (6,2,0) coordinate (D);

尽管

\坐标(D)在(6,2,0);

我们祈祷在 pgf 的未来版本中两者都能正常工作。

\documentclass[tikz,border=1 mm,12pt]{standalone} 
\usepackage{tikz-3dplot} 
\usetikzlibrary{3dtools} 
\tikzset{intersection of line trough/.code args={#1 and #2 with plane
        containing #3 and normal #4}{%
        \pgfmathsetmacro{\ltest}{abs(TD("#2o#4")-TD("#1o#4"))}%
             \ifdim\ltest pt<0.01pt            
              \message{Plane and line are parallel!^^J}
              \pgfmathsetmacro{\myd}{0}
             \else
              \pgfmathsetmacro{\myd}{(TD("#3o#4")-TD("#1o#4"))/(TD("#2o#4")-TD("#1o#4"))}%
             \fi
             \pgfmathsetmacro{\myP}{TD("#1+\myd*#2-\myd*#1")}%
        \pgfkeysalso{insert path={%
            (\myP)
            }}
}}

\begin{document}

\tdplotsetmaincoords{70}{90}
    \begin{tikzpicture}[tdplot_main_coords,scale=1,line join = round, line cap = round]
    \pgfmathsetmacro\a{3}
    \pgfmathsetmacro\b{3}
    \pgfmathsetmacro\h{4}


    % definitions
    \path 
  (0,0,0) coordinate (A) 
 (6,2,0) coordinate(D) 
 (4,4,0)coordinate(C) 
 (-2,5,0) coordinate(B) 
 (\a,\b,\h) coordinate(S) 
 (34/11, 34/11, 0) coordinate(O) 
 (42/11, 14/11, 0) coordinate(E) 
 (29/11, 93/22, 0)coordinate(F) 
 ({-238*\h*\a/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))}, {-238*\h*\b/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))}, {-238*\h^2/(11*(-5*\h*\a-2*\h*\b+(-28+2*\b+5*\a)*\h))}) coordinate(H) 
 ({-2-238*\h*(2+\a)/(11*(-5*\h*(2+\a)-2*\h*(-5+\b)+(-28+2*\b+5*\a)*\h))}, {5-238*\h*(-5+\b)/(11*(-5*\h*(2+\a)-2*\h*(-5+\b)+(-28+2*\b+5*\a)*\h))},{ -238*\h^2/(11*(-5*\h*(2+\a)-2*\h*(-5+\b)+(-28+2*\b+5*\a)*\h))}) coordinate(G);
    \path[intersection of line trough={(0,0,0) and (6,2,0) with plane containing
    (34/11, 34/11, 0) and normal (-5*\h, -2*\h, -28 + 5*\a + 2*\b)}] 
    coordinate (E');
    \path[intersection of line trough={ (B) and (C) with plane
    containing (34/11, 34/11, 0) and normal (-5*\h, -2*\h, -28 + 5*\a +
    2*\b)}]  coordinate (F');
    \path[intersection of line trough={(A) and (\a,\b,\h) with plane
    containing (O) and normal (-5*\h, -2*\h, -28 + 5*\a +
    2*\b)}]  coordinate (H');
    \path[intersection of line trough={(B) and (S) with plane
    containing (O) and normal (-5*\h, -2*\h, -28 + 5*\a +
    2*\b)}]  coordinate (G');


 \begin{scope}
    \draw[very thick]
  (S)--(A) -- (D) --(C) -- (B) --cycle 
  (S)-- (B) (S)--(C) (S)--(D) (H)--(E) (F)--(G);
  \draw[dashed]
  (S) -- (O)   (A) --(B) (H)--(G) (E)-- (F) (O) --(H);
   \end{scope} 
 \path[red] foreach \X in {E,F,G,H}
  {(\X) node[above] {$\X$} (\X') node[below] {$\X'$}};
 \draw[dashed,red] (O) -- (H); 

    \foreach \point/\position in {A/left,D/below,C/below,S/above,B/right,O/below,E/left,F/right,G/right,H/left}
    {
        \fill (\point) circle (1.5pt);
        \node[\position=1.5pt] at (\point) {$\point$};
    }

    \end{tikzpicture}
\end{document} 

在此处输入图片描述

红色的东西只是为了表明它有效。

编辑code/.style args:按照 Henri Menke 在评论中的建议,更改为。

相关内容