
給定兩條線,我想以某種方式連接它們,使連接線平滑。例如,考慮下圖:
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{arrows}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\coordinate (v1) at (0,0);
\coordinate (v2) at (2,0);
\coordinate (v3) at (4,2);
\coordinate (v4) at (4,4);
\draw[fill, black] (v1) circle[radius=1pt];
\draw[fill, black] (v2) circle[radius=1pt];
\draw[fill, black] (v3) circle[radius=1pt];
\draw[fill, black] (v4) circle[radius=1pt];
\draw (v1)--(v2);
\draw (v3)--(v4);
\draw (2,2) circle(2);
\end{tikzpicture}
\end{document}
實際上我只對連接兩條線的四分之一圓感興趣。但我有麻煩
- 刪除圓的其他 75%,更重要的是
- 如何計算這樣一條不垂直的線。
我嘗試使用\draw[bend left]
,但這並不總是能產生順利的連接。有誰知道更好的方法?
答案1
這正是該controls
命令的作用:透過貝塞爾曲線,無論這些線段是否垂直。此外,您還可以更改標量因子.5
、.8
、1.5
等來控制射擊力。
(A).. controls +(P) and +(Q) .. (B)
這相當於
(A).. controls (A)+(P) and (B)+(Q) .. (B)
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\path
(0,0) coordinate (v1) node[below]{$v_1$}
(1,2) coordinate (v2) node[left]{$v_2$}
(4,2) coordinate (v3) node[right]{$v_3$}
(3,4) coordinate (v4) node[above]{$v_4$}
;
\draw (v1)--(v2) (v3)--(v4);
\draw[red] (v2).. controls +($.5*(v2)-.5*(v1)$) and +($.8*(v3)-.8*(v4)$) .. (v3);
\foreach \p in {v1,v2,v3,v4}
\fill (\p) circle(2pt);
\end{tikzpicture}
\begin{tikzpicture}
\path
(0,0) coordinate (v1) node[below]{$v_1$}
(2,0) coordinate (v2) node[below]{$v_2$}
(4,2) coordinate (v3) node[right]{$v_3$}
(4,4) coordinate (v4) node[above]{$v_4$}
;
\draw (v1)--(v2) (v3)--(v4);
\draw[blue] (v2).. controls +($.5*(v2)-.5*(v1)$) and +($.8*(v3)-.8*(v4)$) .. (v3);
\foreach \p in {v1,v2,v3,v4}
\fill (\p) circle(2pt);
\end{tikzpicture}
\end{document}
答案2
您可以使用 鍵out
和in
。接受一個參數(一個角度),其工作原理基本上與 一樣bend left
,但您可以選擇在兩端效果最好的角度。
\documentclass[11pt,a4paper]{amsart}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{arrows}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\coordinate (v1) at (0,0);
\coordinate (v2) at (2,0);
\coordinate (v3) at (4,2);
\coordinate (v4) at (4,4);
\draw[fill, black] (v1) circle[radius=1pt];
\draw[fill, black] (v2) circle[radius=1pt];
\draw[fill, black] (v3) circle[radius=1pt];
\draw[fill, black] (v4) circle[radius=1pt];
\draw (v1)--(v2);
\draw (v3)--(v4);
\draw (2,0) to [out=0, in=270] (4,2);
\end{tikzpicture}
\end{document}
在這種特殊情況下,正如您所指出的,您也可以只插入圓弧。例如,如果將 TikZ 圖片的最後一行替換為,上例的輸出是相同的
\draw (2,0) arc [start angle=-90, end angle=0, radius=2];