我有以下 MWE:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[>=stealth,thick]
% Grösse (Umkreisradius) des Achtecks
\pgfmathparse{3.5}\let\r\pgfmathresult
% Punkte erstellen
\foreach \a/\l in {0/A,1/B,2/C,3/D,4/E,5/F,6/G,7/H}
{
\pgfmathparse{\a*45+247.5}\let\b\pgfmathresult
\coordinate (\l) at (\b:\r);
\draw (\b:1.1*\r) node {$\l$};
}
\draw(A)--(B)--(C)--(D)--(E)--(F)--(G)--(H)--cycle;
\foreach \l in {A,B,C,D,E,F,G,H}
{
\filldraw[fill=white,draw=black] (\l) circle (1pt);
}
% Winkel von S = Winkel von B
\pgfmathparse{45+247.5}\let\ab\pgfmathresult
% Winkel von C
\pgfmathparse{45+\ab}\let\ac\pgfmathresult
% Y-Koordinate von S = r*sin(C)
\pgfmathparse{\r*sin(\ac)}\let\sy\pgfmathresult
\pgfmathparse{-\sy*tan(\ab-270)}\let\sx\pgfmathresult
\coordinate(S) at (\sx,\sy);
\draw[orange,shorten <=1pt,shorten >=1pt] (A) -- (D);
\draw[orange,shorten <=1pt,shorten >=1pt] (B) -- (F);
\filldraw[fill=white,draw=orange] (S) circle (1pt) node[anchor=west]{$S$};
\draw[red,shorten <=1pt,shorten >=1pt,->] (A) -- (H);
\draw[red,shorten <=1pt,shorten >=1pt,->] (A) -- (B);
\end{tikzpicture}
\end{document}
产生
现在我想改变代码,以便得到
添加的三角形的斜边角为 45 度,尖端角为 90 度。
答案1
有点神秘,但我想应该可以
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\def\zzz{2cm}
\draw (0,0) foreach \x[count=\xi from 0] in {A,...,H}{
node[label={[anchor=\xi*45+60,inner sep=0pt,outer sep=4pt]:\x},
draw,circle,fill=white,inner sep=1pt] (\x){}
--++(\xi*45:\zzz)
};
\draw[orange] (A) -- (D) (B) -- (F);
\draw (B) -- ($(A)!2!($(A)!(D)!(B)$)$) -- (D);
\end{tikzpicture}
\end{document}
答案2
您可以使用 tikz 来计算交叉点:
\documentclass[tikz, border=5pt]{standalone}
\begin{document}
\tikzset{every node/.style = {draw, circle, inner sep=1pt, fill=white}}
\begin{tikzpicture}[thick, >=stealth]
\def\zzz{3.5cm}
\draw (0,0) foreach \x[count=\xi from 0] in {A,...,H}{
node[label={[anchor=\xi*45+60,inner sep=0pt,outer sep=4pt]:\x}] (\x){}
--++(\xi*45:\zzz)
};
\draw[orange] (A) -- (D) (B) -- (F);
\draw[red, ->] (A) edge (H) (A) edge (B);
\draw (B) -- (intersection of E--D and A--B) -- (D);
\node[draw=orange, label=right:S] at (intersection of A--D and B--F) {};
\end{tikzpicture}
\end{document}
(感谢 percusse 对八边形代码的回答。)