8

These are things I try:

settings.outformat="pdf"; 
settings.prc=false;
settings.render=0;

import three; unitsize(1cm); size(8cm,0); currentprojection=orthographic(2,1,0.8); 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,4), pB=projpA,
pC=p0+.2
v1+.2v2, vnP=unit(cross(v1,v2)), pD=rotate(90,pC,pC+vnP)pB; draw(surface(pl),orange); draw(Label("$\vec{v_1}$"),p0--p0+v1,1bp+blue,Arrow3(size=8)); draw(Label("$\vec{v_2}$"),p0--p0+v2,N,1bp+blue,Arrow3(size=8)); label(project("abc",v1,v2,p0+(.5,.5,0))); draw(surface(pA--pB--pC--cycle),opacity(.5)+gray,1bp+.8blue); label(project("abc",v1,v2,p0+(.5,.5,0))); dot("$A$",pA); dot("$B$",pB); dot("$C$",pC,dir(pC-pB)); triple pBpC=pC-pB,pBpA=pA-pB; label(project("abc",pBpC,pBpA,pC+(.5,.5,0))); dot("$p_0$",p0,NW); shipout(bbox(2mm,Fill(white)));

enter image description here

All text onto plane ABC.

How to place and rotate text onto a plane in the line direction in the following case?

Additional:

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

import three; unitsize(1cm); defaultpen(fontsize(12pt)); defaultpen(linewidth(1bp)); size(10cm,0); currentprojection=orthographic(1.5,0.5,0.8); 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,4), pB=projpA, pC=p0+.2v1+.2v2, vnP=unit(cross(v1,v2)),pD=rotate(90,pC,pC+vnP)pB; draw(surface(pl),orange+opacity(.2)); draw(surface(pA--pB--pC--cycle),opacity(.5)+gray,1bp+.8blue); draw(Label("$\vec{v_1}$"),p0--p0+v1,1bp+blue,Arrow3(size=8)); draw(Label("$\vec{v_2}$"),p0--p0+v2,N,1bp+blue,Arrow3(size=8)); path3 pll=plane(pB-pC,pB-pA,pC);

dot("$A$",pA); dot("$B$",pB); dot("$C$",pC,dir(pC-pB)); // 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/10dir(degrees(B-A)+90); N=B+d/10dir(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,"distance $AC$",-4,line=false); cote(pC,pB,"distance $BC$",-5,sty=dashed); cote(pA,pB,"distance $AB$",-2,a=-1,alignLabel=LeftSide);

// macros3D.asy void cote3D(picture pic=currentpicture,Label L="", triple A, triple B, real d=5mm, triple v, bool cc=true,pen p=currentpen, pen joinpen=dotted,pen textLabel=currentpen, arrowbar3 arrow=Arrows3(size=5)) { transform3 T=shift(dunit(v)); triple A=A, B=B; pic.add(new void(picture f, transform3 t) { picture opic; path3 dist; triple Ap=tA, Bp=tB; triple a=TAp, b=T*Bp; if (cc) {dist=a--b;} else {dist=b--a;} draw(opic,Label(L,textLabel),dist,p,arrow); draw(opic,a--Ap^^b--Bp,joinpen); add(f,opic); }, true); } cote3D("distance $AC$",pA,pB,d=-5mm,cc=false,textLabel=yellow,pC-pB); shipout(bbox(2mm,Fill(white)));

enter image description here

A problem is discovered, how to fix my code?

2 Answers2

10

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.

2

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

Andrey L.
  • 1,794
  • 2
    Please do not get me wrong but this does not really seem to project the text on the triangle. Rather, it seems to me that it (just) rotates the text to be along the edge. To see what I mean try e.g. currentprojection=orthographic(1.5,3.1,0.5);. –  Jan 23 '20 at 16:15
  • @Schrödinger'scat I completely agree with you, it is not 'true' projection. This is just the answer to the question "A problem is discovered, how to fix my code?" – Andrey L. Jan 24 '20 at 09:56