以下是我尝试过的方法:
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=proj*pA,
pC=p0+.2*v1+.2*v2,
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)));
将所有文本放到平面上ABC
。
in the line direction
在以下情况下,如何将文本放置并旋转到平面上?
额外的:
// 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=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(.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/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,"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(d*unit(v));
triple A=A, B=B;
pic.add(new void(picture f, transform3 t) {
picture opic;
path3 dist;
triple Ap=t*A, Bp=t*B;
triple a=T*Ap, 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)));
发现一个问题,如何修复我的代码?
答案1
这真的只是(也仅仅是;-)为了好玩。我在 Ti 中玩过类似的任务。钾Z.以下代码需要3dtools 库project on plane
,以及的某个版本orthonormal basis vectors of plane
将在某个时候添加到此库中。给定三个点A
、B
和C
,这些工具允许您切换到包含这些点的平面。此平面的基向量是正交的,并且第一个基向量与 平行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}
我当然不是声称这可以与之竞争asymptote
。
答案2
这是我的尝试:
// 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)));