有趣的是,这个网站没有关于线与平面相交的问题。在三维空间中,一条线穿过一个平面。在三维空间中寻找交点是一个非常重要的问题,但在 tikz-3dplot 中似乎很难。我有两个问题:1) 如何找到相交点;2) 如何将线隐藏在平面后面?
\tdplotsetmaincoords{45}{10}
\begin{tikzpicture}[scale=1,tdplot_main_coords,>=stealth',font=\scriptsize]
%plane
\draw[fill=gray!40,opacity=.8] (.5,-1.5,0) -- (4,-1.5,0) -- (4,1.5,0) -- (.5,1.5,0) -- cycle;
%points
\coordinate (or) at (2,1.5,-4);
\tdplotsetcoord{p}{5}{10}{0};
\tdplotsetcoord{oo}{0}{0}{0};
%line
\draw (or) -- (p);
%axis
\draw[->] (oo) -- +(.5,0,0) node[right]{$x$};
\draw[->] (oo) -- +(0,.5,0) node[right]{$y$};
\draw[->] (oo) -- +(0,0,.5) node[left]{$z$};
\end{tikzpicture}
答案1
你的平面位于 xy 平面,因此在这个平面上找到这个点非常简单。使用以下命令运行示例xelatex
\documentclass{standalone}
\usepackage{pst-solides3d}
\begin{document}
\psset{viewpoint=20 20 20 rtp2xyz,lightsrc=10 15 7,Decran=20}
\begin{pspicture}(-5,-5)(6,5)
\psSolid[object=line,args=4 3 -4 3 1 0]
\psSolid[object=new,
sommets=0.5 -2.5 0
4 -2.5 0
4 4.5 0
0.5 4.5 0,
faces={[0 1 2 3]},fillcolor=red!40]
\psSolid[object=line,args=2 -1 4 3 1 0]
\psSolid[object=point,args= 3 1 0]
\axesIIID(4,4,3)
\end{pspicture}
\end{document}
答案2
同样,如果平面是水平的,有一个非常简单的方法。Ti钾Z 可以找到两条线的交点:
\coordinate (I) at (intersection of A--B and C--D);
我定义了一个宏,它同时创建两个坐标:任何给定的点及其在 xy 平面上的投影。然后,线与平面的交点与线与其投影的交点相同。
\documentclass[tikz,border=1.618mm]{standalone}
\usetikzlibrary{3d,perspective}
\newcommand{\pointandprojection}[4]% x,y,z, name
{% creates a cooridinate A and its horizontal projection A-0
\coordinate (#4) at (#1,#2,#3);
\coordinate (#4-0) at (#1,#2,0);
}
\begin{document}
\begin{tikzpicture}[3d view={110}{30},line cap=round,line join=round]
% coordinates
\pointandprojection{-1.5}{-1}{2}{P};
\pointandprojection{1.5}{1.8}{-1}{Q};
\coordinate (I) at (intersection of P--Q and P-0--Q-0);
% line below plane
\draw[dashed,red] (Q-0) -- (Q);
\draw[red] (Q) -- (I);
% plane and x,y-axis
\draw[fill=gray!20,fill opacity=0.8,canvas is xy plane at z=0] (-2,-2) rectangle (2,2);
\draw[gray!50] (P-0) -- (Q-0);
\draw[-latex] (0,0,0) -- (3,0,0) node[left] {$x$};
\draw[-latex] (0,0,0) -- (0,3,0) node[right] {$y$};
% line above plane
\draw[dashed,red] (P-0) -- (P);
\draw[red] (P) -- (I);
% z-axis
\draw[-latex] (0,0,0) -- (0,0,3) node[above] {$z$};
% points
\foreach\i in {P,Q,I,P-0,Q-0}
\fill (\i) circle (0.25mm);
\end{tikzpicture}
\end{document}
答案3
我的解决方案不如 Herbert 的解决方案优雅,但它是使用 LuaLaTeX 给出的。
\documentclass{standalone}
\usepackage{tikz,tikz-3dplot,luacode}
\def\prPoint#1{\directlua{%
for i,v in ipairs(#1) do
tex.sprint(v)
if i\string~=3 then tex.sprint(",") end
end
}}
\begin{document}
\tdplotsetmaincoords{45}{10}
\begin{tikzpicture}[scale=1,tdplot_main_coords,>=stealth',font=\scriptsize]
\begin{luacode}
-----------
-- PLANE --
-----------
A = { .5,-1.5,0}
B = {4 ,-1.5,0}
C = {4 , 1.5,0}
AB = {B[1]-A[1],B[2]-A[2],B[3]-A[3]}
AC = {C[1]-A[1],C[2]-A[2],C[3]-A[3]}
plane_dir = {AB[2]*AC[3]-AB[3]*AC[2],
AB[3]*AC[1]-AB[1]*AC[3],
AB[1]*AC[2]-AB[2]*AC[1]}
local mod = math.sqrt(plane_dir[1]^2+plane_dir[2]^2+plane_dir[3]^2)
plane_dir = {plane_dir[1]/mod,plane_dir[2]/mod,plane_dir[3]/mod}
plane_d = -A[1]*(AB[2]*AC[3]-AB[3]*AC[2])+
A[2]*(AB[1]*AC[3]-AB[3]*AC[1])-
A[3]*(AB[1]*AC[2]-AB[2]*AC[1])
function plane(x,y)
return -(plane_dir[1]*x+plane_dir[2]*y+plane_d)/(plane_dir[3])
end
----------
-- LINE --
----------
D = {2, 1.5,-4}
E = {2,.3 , 1}
line_dir = {D[1]-E[1],D[2]-E[2],D[3]-E[3]}
local mod = math.sqrt(line_dir[1]^2+line_dir[2]^2+line_dir[3]^2)
line_dir = {line_dir[1]/mod,line_dir[2]/mod,line_dir[3]/mod}
function line(t)
return {E[1]+line_dir[1]*t,E[2]+line_dir[2]*t,E[3]+line_dir[3]*t}
end
------------------------
-- INTERSECTION POINT --
------------------------
t = -(plane_d+(plane_dir[1]*E[1]+plane_dir[2]*E[2]+plane_dir[3]*E[3]))/
(plane_dir[1]*line_dir[1]+plane_dir[2]*line_dir[2]+plane_dir[3]*line_dir[3])
int_point = line(t)
\end{luacode}
% Plane
\draw[fill=gray!80!](\prPoint{A})--
(\prPoint{B})--
(\prPoint{C})--
(\prPoint{{.5, 1.5,plane(.5,1.5)}})--
cycle;
% Points
\coordinate (or) at (2,1.5,-4);
\tdplotsetcoord{p}{5}{10}{0};
\tdplotsetcoord{oo}{0}{0}{0};
% Line
\draw (\prPoint{D})--(\prPoint{int_point});
\draw[red] (\prPoint{int_point})--(\prPoint{E});
% Axis
\draw[->] (oo) -- +(.5,0,0) node[right]{$x$};
\draw[->] (oo) -- +(0,.5,0) node[right]{$y$};
\draw[->] (oo) -- +(0,0,.5) node[left]{$z$};
\end{tikzpicture}
\end{document}
玩得开心!!