Intersection of a line with a plane, where is wrong in my code?

Let SABCD be a pyramid, A(0,0,0), B(-2,5,0), C(4,4,0), D(6,2,0), S(a,b,h), O is intersection of two line AC and BD. A plane passing through O and parallel to the lines AB and SC cut the lines AB, BC, SB, SA respectively at E, F, G, H. We can prove that EF, GH are parallel to AB and OH is parallel to SC. In my code, I see that, OH is not parallel to SC. By calculting, I have coordinates of the point H (in picture is H') is

({-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))})

and then, OH' is parallel to SC. This is my code base on the answer at Intersection of a line with a plane, where is wrong in third way?

 \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{%
\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{%
\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)}
\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}


Where is wrong in my code?

I did as marmot's comment, and got

\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{%
\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{%
\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)}
\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}


Code is written by Maple

\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}

• In your code, you have the normals (-5 \h, -2 \h, -28 + 5 \a + 2 \b). I guess these should be (-5*\h, -2*\h, -28 + 5*\a + 2*\b) since the LaTeX (TikZ) parser does not automatically insert multiplication signs. – marmot Feb 3 at 15:43
• I did as you said, but I didn't get the correct result. – minhthien_2016 Feb 4 at 0:57

I am sorry, you are right. There were still parsing errors. Essentially, some minus signs do not get correctly multiplied. To correct this, I rewrote the vector operations as

\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))}


After this is done (and adds the multiplication signs in the normal, which are however not essential), one confirms what you are saying.

\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{%
\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{%
\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))}
\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} • It is interesting. – minhthien_2016 Feb 4 at 1:35
• @minhthien_2016 I am really very sorry. I should have thought about this but I didn't. – marmot Feb 4 at 1:38
• Please write a simplest code. I use Maple to check. – minhthien_2016 Feb 4 at 1:38
• @minhthien_2016 I believe this answer reproduces your result obtained with Maple. Is that true? – marmot Feb 4 at 2:01
• @minhthien_2016 No. It will take a long while. – marmot Feb 18 at 2:17