以下代码指示TikZ
绘制一个直角三角形 AQP,直角位于 Q 处。我将线段 AQ 的长度标记为 y。如何将字母 y 旋转 90 度以使其直立?我想从 A 到包含边 PQ 的线绘制一条垂直于 PA 的线段,并将该交点标记为 R。
\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}[dot/.style={fill,circle,inner sep=1.5pt}]
\path
(80:5) node [dot,label=above left:$A$]{} coordinate (A)
(80:7) coordinate (a)
(20:9) coordinate (B)
(20:11) coordinate (b)
(0:0) node[dot,label=below left:$P$]{} coordinate(P)
(-100:1)coordinate (e)
(-160:1) coordinate (f);
\path coordinate (Q)at($(P)!(A)!(B)$) node at (Q)[dot,label=below:$Q$]{} ;
\draw[<->] (a)--(e);
\draw[<->, name path=kline] (f)--(b) node[below right]{$k$}; % First line for intersection
\draw[purple!70!black,dashed] (A)--(Q);
\tkzMarkRightAngle(A,Q,P);
\draw ($(P)!3mm!90:(A)$)--($(A)!3mm!-90:(P)$)coordinate(u); % Note here the invisible point u, where uA is normal to pA at point A
\draw[|<->|] ($(P)!-7mm!90:(Q)$)--node[fill=white,sloped] {$x$} ($(Q)!-7mm!-90:(P)$);
\draw[|<->|] ($(Q)!-3mm!90:(A)$)--node[fill=white] {$y$} ($(A)!-3mm!-90:(Q)$);
\tkzMarkAngle[size=0.75cm,color=cyan,mark=||](B,P,A);
\tkzMarkAngle[size=1cm,color=cyan,mark=|](P,A,Q);
\path [name path=ARline] (u)--($(A)!-10cm!(u)$); % Second line for intersection
\path [name intersections={of = ARline and kline, by=R}];
\draw (A)--(R)node[dot,label=below:$R$]{};
\tkzMarkRightAngle(R,A,P);
\end{tikzpicture}
\end{document}
答案1
您的代码出现错误;我尝试通过猜测您要做什么来完善它:
代码:
\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}[dot/.style={fill,circle,inner sep=1.5pt}]
\path
(80:5) node [dot,label=above left:$A$]{} coordinate (A)
(80:7) coordinate (a)
(20:9) node [dot,label=below:$B$]{} coordinate (B)
(20:11) coordinate (b)
(0:0) node[dot,label=below left:$P$]{} coordinate(P)
(-100:1)coordinate (e)
(-160:1) coordinate (f);
\node[dot,label=below:$Q$] (Q) at ($(P)!(A)!(B)$) {};
\node[dot,label=above right:$R$] (R) at ($(P)!(Q)!(A)$) {};
\draw[<->] (a) -- (e);
\draw[<->] (b) -- (f);
\draw[purple!70!black,dashed] (A) -- (Q);
\draw[green!70!black,dashed] (Q) -- (R);
\tkzMarkRightAngle(A,Q,P);
\draw[|<->|] ($(P)!3mm!90:(A)$)--node[fill=white,sloped] {$r$} ($(A)!3mm!-90:(P)$);
\draw[|<->|] ($(P)!-7mm!90:(Q)$)--node[fill=white,sloped] {$x$} ($(Q)!-7mm!-90:(P)$);
\draw[|<->|] ($(Q)!-3mm!90:(A)$)--node[fill=white] {$y$} ($(A)!-3mm!-90:(Q)$);
\tkzMarkAngle[size=0.75cm,color=cyan,mark=||](B,P,A);
\tkzMarkAngle[size=1cm,color=cyan,mark=|](P,A,Q);
\end{tikzpicture}
\end{document}
答案2
这是 OP 最后一条评论中要求的内容:
\documentclass[10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}[dot/.style={fill,circle,inner sep=1.5pt},line width=.7pt]
\path
(80:5) node[dot,label=above left:$A$]{} coordinate (A)
(80:7) coordinate (a)
(20:9) coordinate (B)
(20:11) coordinate (b)
(0:0) node[dot,label=below left:$P$]{} coordinate(P)
(-100:1)coordinate (e)
(-160:1)coordinate (f)
($(P)!(A)!(B)$)node[dot,label=below:$Q$]{} coordinate(Q);
\path[name path=kline](f)--(b); % First line for intersection
\path[name path=ARline](A)--($(A)!10cm!90:(P)$); % A line normal to pA at point A in the east direction
\path [name intersections={of = ARline and kline, by=R}];
\draw (A)--(P)--(R)node[dot,label=below:$R$]{}--cycle;
\draw[purple!70!black,dashed] (A)--(Q);
\tkzMarkRightAngle(A,Q,P);
\tkzMarkAngle[size=0.75cm,color=cyan,mark=||](B,P,A);
\tkzMarkAngle[size=1cm,color=cyan,mark=|](P,A,Q);
\tkzMarkRightAngle(R,A,P);
\end{tikzpicture}
\end{document}
这使:
除了阅读综合用户手册(最新版本)之外,最好的学习方法TikZ
是研究其他人的代码。
答案3
也许这就是你想要的?
\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}[dot/.style={fill,circle,inner sep=1.5pt}]
\coordinate (Q) at (0,0);
\coordinate (A) at ($(Q)+(30:3)$);
\coordinate (P) at ($(Q)+(30+90:4)$);
\draw (A) -- (Q) -- (P) -- cycle;
\path (A) -- node [midway,sloped,above] {hypotenuse} (P);
\path (A) -- node [midway,sloped,below] {shorter leg} (Q);
\path (P) -- node [midway,sloped,below] {longer leg} (Q);
\tkzMarkRightAngle(A,Q,P);
\end{tikzpicture}
\end{document}
您似乎试图分配很多不同的坐标,但我很难看出您想要实现什么。但您问到如何标记边,所以我就这么做了。