一條線,我們有兩個區域,兩條線,我們有四個區域。我試過
\documentclass[tikz,12pt]{standalone}
\begin{document}
\begin{tikzpicture}
\path
(0,0) coordinate (O)
(-2,-2) coordinate (A)
(2,2) coordinate (B)
(2,-2) coordinate (C)
(-2,2) coordinate (D);
\node at (barycentric cs:A=1,C=1,B=1) {$1$};
\node at (barycentric cs:A=1,D=1,B=1) {$2$};
\draw (A) -- (B);
\end{tikzpicture}
\begin{tikzpicture}
\path
(0,0) coordinate (O)
(-2,-2) coordinate (A)
(2,2) coordinate (B)
(-4,-2) coordinate (C)
(4,2) coordinate (D);
\draw (A) -- (B) (C) -- (D);
\node at (barycentric cs:A=1,O=1,C=1) {$1$};
\node at (barycentric cs:B=1,O=1,C=1) {$2$};
\node at (barycentric cs:B=1,O=1,D=1) {$3$};
\node at (barycentric cs:A=1,O=1,D=1) {$4$};
\end{tikzpicture}
\end{document}
我知道,最大數$L_n$是$\dfrac{n^2+n+2}{2}$。如何自動繪製上面這張圖片 如何自動在這張圖片中加入數字?
答案1
這遠遠不是一個完整的答案。問題似乎是,給定行數n
,如何排列它們以使區域數達到其最大數(n^2+n+2)/2
。我認為需要具備以下幾個條件:
- 沒有兩條不同的直線是平行的。
- 在給定交點處相交的線不超過兩條。
使用這些指導原則,人們可以建立一張創建這種排列的圖片。
\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[pics/divi/.style={code={
\foreach \X [evaluate=\X as \Y using {360*\X/(#1+1-isodd(#1))}]
in {1,...,#1}
\draw[scale=1/#1] ({90+\Y}:#1/4)
++ ({180+\Y}:1+1.5*#1) -- ++ ({\Y}:2+3*#1);
}}]
\matrix {\pic {divi=1}; & \pic {divi=2}; \\
\pic {divi=3}; & \pic {divi=4}; \\
\pic {divi=5}; & \pic {divi=6}; \\
};
\end{tikzpicture}
\end{document}
我什至沒有嘗試輸入數字。
答案2
這提供了一個宏來計算三角形的內心。困難的部分是避免浮點溢出。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\incenter}[4]% #1-#3 = coordinate names for vertices, #4 = name of incenter
{\pgfscope
\pgfpathmoveto{\pgfpointanchor{#1}{center}}%
\pgfgetlastxy{\xa}{\ya}%
\pgfpathmoveto{\pgfpointanchor{#2}{center}}%
\pgfgetlastxy{\xb}{\yb}%
\pgfpathmoveto{\pgfpointanchor{#3}{center}}%
\pgfgetlastxy{\xc}{\yc}%
\pgfmathsetmacro{\a}{veclen(\xc-\xb,\yc-\yb)}%
\pgfmathsetmacro{\b}{veclen(\xc-\xa,\yc-\ya)}%
\pgfmathsetmacro{\c}{veclen(\xb-\xa,\yb-\ya)}%
\pgfmathsetmacro{\d}{\a+\b+\c}%
\pgfmathsetmacro{\a}{\a/\d}%
\pgfmathsetmacro{\b}{\b/\d}%
\pgfmathsetmacro{\c}{\c/\d}%
\pgfmathsetlengthmacro{\xo}{\a*\xa + \b*\xb + \c*\xc}%
\pgfmathsetlengthmacro{\yo}{\a*\ya + \b*\yb + \c*\yc}%
\pgfcoordinate{#4}{\pgfpoint{\xo}{\yo}}
\endpgfscope}
\begin{document}
\begin{tikzpicture}
\path
(0,0) coordinate (O)
(-2,-2) coordinate (A)
(2,2) coordinate (B)
(2,-2) coordinate (C)
(-2,2) coordinate (D);
\draw (A) -- (B);
\incenter{A}{C}{B}{O1}%
\node at (O1) {1};
\incenter{A}{D}{B}{O2}%
\node at (O2) {2};
\end{tikzpicture}
\begin{tikzpicture}
\path
(0,0) coordinate (O)
(-2,-2) coordinate (A)
(2,2) coordinate (B)
(-4,-2) coordinate (C)
(4,2) coordinate (D);
\draw (A) -- (B) (C) -- (D);
\incenter{A}{O}{C}{O1}%
\node at (O1) {1};
\incenter{B}{O}{C}{O2}%
\node at (O2) {2};
\incenter{B}{O}{D}{O3}%
\node at (O3) {3};
\incenter{A}{O}{D}{O4}%
\node at (O4) {4};
\end{tikzpicture}
\end{document}
答案3
繪製這些圖表很容易。下面的程式碼定義了一個宏\DividedPlanes
,
\DividedPlanes{5}
\DividedPlanes{6}
分別為 5 點和 6 點產生這些配置:
中的線\DividedPlanes{<n>}
是透過首先使用循環圍繞點 處的半徑圓\foreach
放置座標來繪製的。之後,透過迴圈遍歷 中的所有數字對(相當於點)來繪製線條。經過比我現在有時間更多的思考(這是一個工作日),應該可以標記這些區域(當奇數和偶數時,行為略有不同)。如果當地的貓科動物沒有打敗我的話,我可能會回到這個主題。n
2
2k\pi/n
k=1,2,...,n
{1,2,...,n}
n
這是代碼:
\documentclass{article}
\usepackage{tikz}
% allow an optional argument so that we can pass some optional
% style commands to the tikzpicture environment
% usage: \DividedPlanes[style]{n}
\newcommand\DividedPlanes[2][]{
\begin{tikzpicture}[#1]
% reserve some real estate for the image
\draw[white](-3,-3) rectangle (3,3);
\foreach \pt in {1,...,#2} {
% name coordinates (1), (2), ..., (#2)
\coordinate (\pt) at (\pt*360/#2:2);
}
\foreach \apt in {1,...,#2} {
\foreach \bpt in {1,...,#2} {
\ifnum\apt=\bpt\else
% draw a line when a and b are distinct
\draw[shorten >=-20,shorten <=-20](\apt)--(\bpt);
\fi
}
}
\end{tikzpicture}
}
\begin{document}
\DividedPlanes{2}
\DividedPlanes{3}
\DividedPlanes{4}
\DividedPlanes{5}
\DividedPlanes{6}
\end{document}