# 3d projection on a line in Tikz-3d

I am trying to draw (in tikz-3d) a perpendicular from a point to a line that is not a coordinate axis. The question is how to find a projection of this point. I need some analog to tikz-euclide:

\tkzDefPointBy[projection=onto B--C](A) \tkzGetPoint{H1}


but in 3D.

The question is above, but this is the "code" that doesn't give me what I want. The goal is to draw the orthocenter of the triangle ABC in space.

\documentclass{article}
\usepackage{tikz,tkz-euclide,tikz-3dplot}
\usetkzobj{all}
\usetikzlibrary{intersections}
\begin{document}
\tdplotsetmaincoords{70}{100}
\begin{tikzpicture}[tdplot_main_coords, scale=1]
%============ Object Definitions ============================
\coordinate [label= above:$A$] (A) at (0, 0, 3);
\coordinate [label= right:$B$] (B) at (0, 4, 0);
\coordinate [label= below left:$C$] (C) at (4, 0, 0);
\coordinate [label= below left:$D$] (D) at (0, 0,0);
\tkzDefPointBy[projection=onto B--C](A) \tkzGetPoint{H1}
\tkzDefPointBy[projection=onto A--C](B) \tkzGetPoint{H2}
\tkzInterLL(A,H1)(B,H2) \tkzGetPoint{H}
%============ Denotations ====================================
\tkzLabelPoint[below right](H1){$H_1$}
\tkzLabelPoint[left](H2){$H_2$}
\tkzMarkRightAngle[size=0.2](C,H1,A)
\tkzMarkRightAngle[size=0.2](C,H2,B)
\tkzMarkRightAngle[size=0.2](A,D,B)
\tkzMarkRightAngle[size=0.2](A,D,C)
\tkzMarkRightAngle[size=0.2](C,D,B)
%============ Drawing ======================================
\draw [dash pattern=on 5pt off 5pt] (D)--(B);
\draw [dash pattern=on 5pt off 5pt] (D)--(H);
\draw [thick,draw=white,double=black,double distance= 1pt](A)--(H1);
\draw [thick,draw=white,double=black,double distance= 1pt](C)--(A);
\draw (A)--(B);
\draw (B)--(C);
\draw (D)--(A);
\draw (D)--(C);
\draw (B)--(H2);
\tkzDrawPoints(A,B,C,D,H1,H2,H)
\end{tikzpicture}
\end{document}


Output:

I used tikz-euclid notation to make it clear what I want. The lines

\tkzDefPointBy[projection=onto B--C](A) \tkzGetPoint{H1}
\tkzDefPointBy[projection=onto A--C](B) \tkzGetPoint{H2}


are supposed to be substituted by something that works in 3D.

• If you need something which knows about 3D, seriously consider using software which has this feature. TikZ can fake 3D but no more than that. A programme like Asymptote, on the other hand, deals with 3D by design.
– cfr
Jul 24, 2016 at 18:00

Asymptote solution:

\documentclass{article}
\usepackage{asymptote}
\begin{document}
\begin{asy}
settings.outformat = "pdf";
settings.render = 0;
import three;
size(5cm, 0);
currentprojection=orthographic((5,2,3));

real a=3;
real b=4;
real c=4;

triple A=(0,0,a);
triple B=(0,b,0);
triple C=(c,0,0);

draw(A--B--C--A,linewidth(1));
draw(O--A^^O--B^^O--C,dashed);

path3 p=O--(6,6*c/b,0);
path3 q=B--C;
path3 p1=O--(6,0,6*c/a);
path3 q1=A--C;

triple H1=intersectionpoint(p,q);
triple H2=intersectionpoint(p1,q1);

path3 h1=A--H1;
path3 h2=B--H2;
triple H=intersectionpoint(h1,h2);

draw(h1);
draw(h2);
draw(O--H,dashed);
dot(Label("$H_2$",align=W),H2);
dot(Label("$H_1$",align=S),H1);
dot(Label("$H$",align=NE),H);
dot(Label("$A$",align=N),A);
dot(Label("$B$",align=E),B);
dot(Label("$C$",align=W),C);
dot(Label("$O$",align=S),O);

\end{asy}

\end{document}


Advantages: this works and finds intersections that tkz-euclide cannot do so far.