How to add text as 2D in 3D onto a plane?

This is really just (and only;-) for fun. I was playing with similar tasks in TikZ. The following code requires the 3dtools library, and some version of the project on plane and orthonormal basis vectors of plane will be added to this library at some point. Given three points A, B and C, say, these tools allow you to switch to plane that contains these points. The basis vectors of this plane are orthonormal, and the first one is parallel to A--B.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3dtools}
\tikzset{project on plane/.code n args={3}{%
\pgfmathsetmacro{\myn}{TD("(#2)x(#3)")}
\pgfmathsetmacro{\mynormalization}{1/sqrt(TD("(\myn)o(\myn)")}
\pgfmathsetmacro{\myn}{TD("\mynormalization*(\myn)")}
\pgfmathsetmacro{\myproj}{-1*TD("(#1)o(\myn)")}
\pgfmathsetmacro{\myprojcoord}{TD("(#1)+\myproj*(\myn)")}
\tikzset{insert path={(\myprojcoord)}}
},orthonormal basis vectors of plane/.code n args={3}{%
\pgfmathsetmacro{\mya}{TD("(#2)-(#1)")}
\pgfmathsetmacro{\mynormalization}{1/sqrt(TD("(\mya)o(\mya)")}
\pgfmathsetmacro{\mya}{TD("\mynormalization*(\mya)")}
\pgfmathsetmacro{\myb}{TD("(#3)-(#1)")}
\pgfmathsetmacro{\mynormalization}{1/sqrt(TD("(\myb)o(\myb)")}
\pgfmathsetmacro{\myb}{TD("\mynormalization*(\myb)")}
\pgfmathsetmacro{\myn}{TD("(\mya)x(\myb)")}
\pgfmathsetmacro{\mynormalization}{1/sqrt(TD("(\myn)o(\myn)")}
\pgfmathsetmacro{\myn}{TD("\mynormalization*(\myn)")}
\pgfmathsetmacro{\myc}{TD("(\myn)x(\mya)")}
\tikzset{insert path={
 (\mya) coordinate(\pgfkeysvalueof{/tikz/3d/projections/planex})
 (\myc) coordinate(\pgfkeysvalueof{/tikz/3d/projections/planey})
 }}},
3d/projections/.cd,planex/.initial=planex,planey/.initial=planey}

\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords,bullet/.style={draw,fill,black,inner
    sep=1.5pt,circle,opacity=1},font=\sffamily]
 \path (4,0,0) coordinate (v1) 
       (0,6,0) coordinate (v2) 
       (-2,-3,0) coordinate (p0);
 \draw[fill=orange] (p0)  -- ++ (v1) -- ++ (v2) -- ++ ($-1*(v1)$) -- cycle;
 \draw[thick,blue,-stealth] (p0) -- ++ (v1) node[left]{$v_1$};
 \draw[thick,blue,-stealth] (p0) -- ++ (v2) node[above]{$v_2$};
 \path        (1,2,4) coordinate (pA)
  [project on plane={pA}{v1}{v2}] coordinate (pB)
  [3d coordinate={(pC)=(p0)+0.2*(v1)+0.2*(v2)}];
 \draw[thick,blue,fill=black,fill opacity=0.3,text opacity=1,text=black] 
  (pA)  node[bullet,label=right:$A$]  {}
  -- (pB) node[bullet,label=right:$B$] {} 
  -- (pC) node[bullet,label=left:$C$] {} -- cycle;
 \path[orthonormal basis vectors of plane={pC}{pB}{pA}]; 
 \begin{scope}[x={(planex)},y={(planey)},canvas is xy plane at z=0,
    transform shape]
  \path ($(pC)!0.5!(pB)$) node[above,yellow] {from $C$ to $B$};
 \end{scope}
 \path[orthonormal basis vectors of plane={pB}{pA}{pC}]; 
 \begin{scope}[x={(planex)},y={(planey)},canvas is xy plane at z=0,
    transform shape]
  \path ($(pB)!0.5!(pA)$) node[above,yellow] {from $B$ to $A$};
 \end{scope}
 \path[orthonormal basis vectors of plane={pA}{pC}{pB}]; 
 \begin{scope}[x={(planex)},y={(planey)},canvas is xy plane at z=0,
    transform shape]
  \path ($(pA)!0.5!(pC)$) node[above,yellow] {from $A$ to $C$};
 \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

I am certainly not claiming that this can compete with asymptote.


Here is my attempt:

// run asy -f pdf <name>.asy
settings.outformat="pdf"; 
settings.prc=false;
settings.render=0;

usepackage("amssymb");

import three;
unitsize(1cm);
defaultpen(fontsize(12pt));
defaultpen(linewidth(1bp));
size(10cm,0);
currentprojection=orthographic(1.5,0.8,0.5);
triple v1=(4,0,0),v2=(0,6,0),p0=(-2,-3,0);
path3 pl=plane(v1,v2,p0);
transform3 proj=planeproject(pl);
triple pA=(1,2,3.5), pB=proj*pA, pC=p0+.2*v1+.2*v2, 
vnP=unit(cross(v1,v2)),pD=rotate(90,pC,pC+vnP)*pB; 
draw(surface(pl),orange+opacity(.5));
draw(Label("$\vec{v}_1$"),p0--p0+v1,1bp+green,Arrow3(size=8));
draw(Label("$\vec{v}_2$",position=Relative(0.7)),p0--p0+v2,N,1bp+green,Arrow3(size=8));
layer();
draw(surface(pA--pB--pC--cycle),opacity(0.5)+gray,1bp+.8blue);

dot("$A$",pA); dot("$B$",pB); dot("$C$",pC,dir(pC-pB));
dot("$p_0$",p0,NW);

// draw a dimension arrow from A to B to d mm above the segment with the text (gg dich)
// https://melusine.eu.org/syracuse/asymptote/comin/geoespace.asy
void cote(triple A1,triple B1, string text, real d,bool line=true,
real pos=.5, real a=1, bool trait=false,pen sty=black, pen joinpen=dotted,
align alignLabel=RightSide ){
pair M,N;
pair A=project(A1);
pair B=project(B1);
M=A+d/10*dir(degrees(B-A)+90);
N=B+d/10*dir(degrees(B-A)+90);
if(line==false)
label(Label(text,Rotate(dir(degrees(a*(N-M)))),position=Relative(pos),align=alignLabel),N--M); 
else {
label(Label(text,Rotate(dir(degrees(a*(N-M)))),position=Relative(pos),align=alignLabel),N--M);
draw(N--M,Arrows(size=5),p=sty);}
if(trait==true){ draw(A--M^^B--N,joinpen); }
}
cote(pC,pA,"\footnotesize distance $AC$",-3.5,line=false);
cote(pC,pB,"\footnotesize distance $BC$",0,line=false);
cote(pA,pB,"\footnotesize distance $AB$",-3.5,line=false);
cote(pC,(pA+pB)/2,"${\vartriangle}ABC$",-2,line=false,pos=.4);

shipout(bbox(2mm,Fill(white)));

enter image description here

Tags:

Asymptote