我目前正在为“几何与拓扑”创建讲义。现在我们到了欧几里得几何的部分,我经常遇到需要将线(不是线段,而是线)可视化的情况。
例如我有以下图片(代码在最后)
但PQ
应该是一条线,所以我需要“放大”线段PQ
。通常,我会像这样计算 PQ 方程
m = (P.y - Q.y)/(P.x - Q.x) -- mind the special case of P.x = Q.x
P.y = m * P.x + t
<=> t = P.y - m*P.x
然后我想补充两个帮助A
点B
:
(enlarge by 0.5)
A.x := P.x - 0.5
B.x := Q.x + 0.5
A.y = m*A.x + t
B.y = m*B.x + t
最后,我会画出A - P - Q - B
我的“放大线‘PQ’”。
但对于可以自动完成的任务来说,这对我来说似乎相当复杂。那么在 TikZ 中有没有办法放大线条?
\documentclass[varwidth=true, border=2pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\tikzstyle{point}=[circle,thick,draw=black,fill=black,inner sep=0pt,minimum width=4pt,minimum height=4pt]
\node (P)[point,label={[label distance=0cm]-90:$P$}] at (0,0) {};
\node (Q)[point,label={[label distance=0cm]-90:$Q$}] at (5,1) {};
\node (A)[point,label={[label distance=0cm]180:$\varphi_1(R)$}] at (2,2) {};
\node (B)[point,label={[label distance=0cm]190:$\varphi_2(R)$}] at (1,3) {};
\draw[very thick, enlarge] (P) edge node {} (Q);
\draw[very thick, red] (P) edge node {} (A);
\draw[very thick, red] (P) edge node {} (B);
\draw[very thick, green] (Q) edge node {} (A);
\draw[very thick, green] (Q) edge node {} (B);
\end{tikzpicture}
\end{document}
答案1
当使用tkz-euclide
构造图形时,可以使用 指示一条经过两点的线\tkzDrawLine(P,Q)
,而使用 绘制线段\tkzDrawSegment(P,Q)
:
\documentclass{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}
\tkzDefPoints{0/0/P, 5/1/Q, 2/2/Phi1, 1/3/Phi2}
\tkzDrawSegments[red](P,Phi1 P,Phi2)
\tkzDrawSegments[blue](Q,Phi1 Q,Phi2)
\tkzDrawLine(P,Q)
\tkzDrawPoints(P,Q,Phi1,Phi2)
\tkzLabelPoints[below](P,Q)
\tkzLabelPoint[above left](Phi1){$\varphi_1(R)$}
\tkzLabelPoint[above left](Phi2){$\varphi_2(R)$}
\end{tikzpicture}
\end{document}
答案2
解决方案
\documentclass[varwidth=true, border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\tikzstyle{point}=[circle,thick,draw=black,fill=black,inner sep=0pt,minimum width=4pt,minimum height=4pt]
\node (P)[point,label={[label distance=0cm]-90:$P$}] at (0,0) {};
\node (Q)[point,label={[label distance=0cm]-90:$Q$}] at (5,1) {};
\node (A)[point,label={[label distance=0cm]180:$\varphi_1(R)$}] at (2,2) {};
\node (B)[point,label={[label distance=0cm]190:$\varphi_2(R)$}] at (1,3) {};
\draw[very thick] (P) edge node {} (Q);
\draw[very thick, red] (P) edge node {} (A);
\draw[very thick, red] (P) edge node {} (B);
\draw[very thick, blue] (Q) edge node {} (A);
\draw[very thick, blue] (Q) edge node {} (B);
\draw[very thick] ($(P)!-1cm!(Q)$) -- ($(Q)!-1cm!(P)$);
\end{tikzpicture}
\end{document}
解释
关键是
\draw[very thick] ($(P)!-1cm!(Q)$) -- ($(Q)!-1cm!(P)$);
$(P)!-1cm!(Q)$
定义一个点,当您查看线 时,该点1cm
在 方向上更明显。 也是一样。这样,您就从两个方向“放大”了线。P
PQ
($(Q)!-1cm!(P)$)
PQ
1cm
图像
答案3
另一个解决方案是仅使用shorten >
and shorten <
:
\documentclass[varwidth=true, border=2pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\tikzstyle{point}=[circle,thick,draw=black,fill=black,inner sep=0pt,minimum width=4pt,minimum height=4pt]
\node (P)[point,label={[label distance=0cm]-90:$P$}] at (0,0) {};
\node (Q)[point,label={[label distance=0cm]-90:$Q$}] at (5,1) {};
\node (A)[point,label={[label distance=0cm]180:$\varphi_1(R)$}] at (2,2) {};
\node (B)[point,label={[label distance=0cm]190:$\varphi_2(R)$}] at (1,3) {};
\draw[very thick, shorten >=-1cm, shorten <=-1cm] (P) edge node {} (Q);
\draw[very thick, red] (P) edge node {} (A);
\draw[very thick, red] (P) edge node {} (B);
\draw[very thick, green] (Q) edge node {} (A);
\draw[very thick, green] (Q) edge node {} (B);
\path[use as bounding box] (-1,1) rectangle (6, 3.3);
\end{tikzpicture}
\end{document}
但请注意,TikZ 不会自动扩展边界框,这就是为什么我必须添加\path[use as bounding box] ...;
答案4
使用 PSTricks。
\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}[linejoin=1,linecap=1](8,6)
\pstGeonode
[
PointName={\varphi_2(R),\varphi_1(R),default},
PosAngle={180,180,-90},
PointNameSep={24pt,24pt,12pt},
](3,5.5){T}(4,3){B}(1,1){P}(7,2){Q}
\psline[linecolor=red](B)(P)(T)
\psline[linecolor=blue](B)(Q)(T)
\pcline[nodesep=-1](P)(Q)
\end{pspicture}
\end{document}