marmotghost / tikz-3dtools

Experimental library for 3d operations with TikZ
8 stars 0 forks source link

Where is wrong in this code about the point G? #8

Closed minhthien2016 closed 2 years ago

minhthien2016 commented 2 years ago

Where is wrong in this code about the point G? I think, there points G, T, H coincide. Because v1v2v3v4 is regular tetrahedron.

\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{calc,3dtools}
\begin{document}
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill},
    declare function={l12=5;l23=5;l13=5; l14=5;l24=5;l34=5;},3d/install view={phi=110,theta=70}]
        \draw[->, save named path=ox] (0,0,0) -- (7,0,0) node[anchor=north east]{$x$};
    \draw [->,save named path=oy] (0,0,0) -- (0,7,0) node[anchor=north west]{$y$};
    \draw [->,save named path=oz] (0,0,0) -- (0,0,7) node[anchor=south]{$z$};
    % ^^^ the lengths of the tetrahedron; 
    % l12 is the distance between vertex 1 and vertex 2, etc.
\pgfmathsetmacro{\mytheta}{acos(( l12*l12 + l13*l13-l23*l23)/(2*l12*l13))}
    \path (0,0,0) coordinate (v1) (0,l12,0) coordinate (v2)
    ({l13*cos(\mytheta)},{l13*sin(\mytheta)},0) coordinate (v3);
    \path[overlay,3d/aux keys/i1=v5,3d/aux keys/i2=v4,3d/intersection of three spheres={A={(v1)},B={(v2)},C={(v3)}, rA=l14,rB=l24,rC=l34}]; 

    \path[3d/plane through={(v1) and (v2) and (v3) named pABC}];
    \path[3d/project={(v4) on pABC}] coordinate (H);
\pgfmathsetmacro{\mybarycenter}{barycenter("(v1),(v2),(v3)")}
\path (\mybarycenter) coordinate (G);   
\path[3d/circumcircle center={A={(v1)},B={(v2)},C={(v3)}}] coordinate (T);
\draw[3d/hidden] (v1) -- (v2);
    \draw[3d/visible] (v4) -- (v1) -- (v3) -- (v2)-- cycle (v4) -- (v3);    
    \path foreach \p/\g in {v1/-90,v2/-90,v3/-90,v4/90,H/0,G/0,T/180}
    {(\p)node[dot]{}+(\g:3mm) node{$\p$}};
    \end{tikzpicture}
\end{document}  

image

marmotghost commented 2 years ago

According to Wikipedia "A regular tetrahedron is a tetrahedron in which all four faces are equilateral triangles.". This does not seem to be the case for the tetrahedron shown in the screen shot.

minhthien2016 commented 2 years ago

How about with this line declare function={l12=5;l23=5;l13=5; l14=5;l24=5;l34=5;}?

minhthien2016 commented 2 years ago

I solve this problem

\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{calc,3dtools}
\begin{document}
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill},declare function={a=1; l12=6*a;l23=6*a;l13=6*a; l14=6*a;l24=6*a;l34=6*a;},3d/install view={phi=70,theta=70}]
    \pgfmathsetmacro{\mytheta}{acos(( l23*l23+ l24*l24-l34*l34)/(2*l23*l24))}
    \path (0,0,0) coordinate (v2) (l13,0,0) coordinate (v3)
    ({l24*cos(\mytheta)},{l24*sin(\mytheta)},0) coordinate (v4);
    \path[overlay,3d/aux keys/i1=v1,3d/aux keys/i2=v5,3d/intersection of three spheres={A={(v2)},B={(v3)},C={(v4)}, rA=l12,rB=l13,rC=l14}]; 
    \path[3d/plane through={(v4) and (v2) and (v3) named pABC}];
    \path[3d/project={(v1) on pABC}] coordinate (H);    
    \pgfmathsetmacro{\mybarycenter}{barycenter("(v4),(v2),(v3)")}
    \path (\mybarycenter) coordinate (G);   
    \path[3d/circumcircle center={A={(v4)},B={(v2)},C={(v3)}}] coordinate (T);
    \draw[3d/hidden] (v4) -- (v2);
    \draw[3d/visible] (v4) -- (v1) -- (v2) -- (v3)-- cycle (v1) -- (v3);    
    \path foreach \p/\g in {v1/90,v2/-90,v3/-90,v4/90,H/90,G/-90,T/0}
    {(\p)node[dot]{}+(\g:3mm) node{$\p$}};
\end{tikzpicture}
\end{document}

image