縮放每張圖片的問題(角度 tikzlibrary)

縮放每張圖片的問題(角度 tikzlibrary)

大家好,我需要縮放 tikzpicture,所以我這樣做了,\begin{tikzpicture}[scale=<factor>]但圖片沒有相應縮放(根據 TikzManual 報導)第 18.2 節 Pic 文法)。我也想要縮放圖片,所以我嘗試了語法,\begin{tikzpicture}[scale=0.4,every pic/.style={transform shape}]但它不起作用。使用變換形狀作為每個圖片的選項,即,\pic[angle radius=5.3cm,transform shape]可以,但我不想在\pics 的每個選項上使用它。也許這只是角度庫的問題(我沒有嘗試使用其他圖片)。這是我的 MWE,這沒有按預期工作

    \documentclass[border=1cm]{standalone}
    \usepackage{tikz}
    \usetikzlibrary{calc,angles}
    \begin{document}
    %rotate vectors
\begin{tikzpicture}[vector/.style={thick,-stealth},scale=0.4,every pic/.style={transform shape}]
%drawing help lines
\newcommand*{\xmin}{-3}\newcommand*{\xmax}{4}
\newcommand*{\ymin}{-5}\newcommand*{\ymax}{1}
\draw[help lines](\xmin,\ymin)grid(\xmax,\ymax);
%vector coordinates and labels
\coordinate[label={above:$v$}] (O)at (0,0);
\coordinate (vec1)at (1,-2);
\coordinate (vec2)at(4,-1);
\draw[vector] (O)--(vec1)coordinate[label={[below]$u_1$}](u1);
%sum (vec1)+(vec2)  
\draw[vector,very thick,blue](O)--($(vec1)+(vec2)$)coordinate(u1+u2);
%rotated sum (u1)+(u2) -> u'1+u'2
\draw[vector,very thick,orange](O)--([rotate=-90]u1+u2)coordinate(u'1+u'2);
%rotated vectors 
\draw[red,vector] (0,0)--([rotate=-90]vec1)coordinate[label={[left]$u'_1$}](u'1); 
%
\draw[red,vector] (0,0)--([rotate=-90]vec2)coordinate[label={[below]$u'_2$}](u'2);
%angles between vectors by angles library, issue with angle radius=  
%default angle radius=1cm and it does not scale accordingly
\pic[draw=gray] {angle = u'1--O--u'2};  
% rotation traces 
\pic[draw=red,dashed,<-,angle radius=1.8cm]{angle=u'1--O--vec1}; 
\pic[draw=blue,dashed,<-,angle radius=5.3cm,]  {angle=u'1+u'2--O--u1+u2}; 
%vector sums labels 
\coordinate[label={below:$w$}]() at(u1+u2);
\coordinate[label={below:$w'$}] ()at(u'1+u'2);
  % outgoing vector scaled accordingly but I'd rather prefer not
    \path[draw,fill=white] (O)circle[radius=2pt];
    \path[fill] (O)circle[radius=1pt];
    \end{tikzpicture}\end{document}

應縮放虛線弧以適合箭頭

下面的一個工作正常,

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,angles}
\begin{document}
%
%rotate vectors
\begin{tikzpicture}[vector/.style={thick,-stealth},scale=0.4 ] %every pic/.append style={transform shape}
%drawing help lines
\newcommand*{\xmin}{-3}\newcommand*{\xmax}{4}
\newcommand*{\ymin}{-5}\newcommand*{\ymax}{1}
\draw[help lines](\xmin,\ymin)grid(\xmax,\ymax);
%vector coordinates and labels
\coordinate[label={above:$v$}] (O)at (0,0);
\coordinate (vec1)at (1,-2);
\coordinate (vec2)at(4,-1);
\draw[vector] (O)--(vec1)coordinate[label={[below]$u_1$}](u1);
%sum (vec1)+(vec2)  
\draw[vector,very thick,blue](O)--($(vec1)+(vec2)$)coordinate(u1+u2);
%rotated sum (u1)+(u2) -> u'1+u'2
\draw[vector,very thick,orange](O)--([rotate=-90]u1+u2)coordinate(u'1+u'2);
%rotated vectors 
\draw[red,vector] (0,0)--([rotate=-90]vec1)coordinate[label={[left]$u'_1$}](u'1); 
%
\draw[red,vector] (0,0)--([rotate=-90]vec2)coordinate[label={[below]$u'_2$}](u'2);
%angles between vectors by angles library, issue with angle radius=  
%default angle radius=1cm and it does not scale accordingly
\pic[transform shape,draw=gray] {angle = u'1--O--u'2};  
% rotation traces 
\pic[draw=red,dashed,<-,angle radius=1.8cm,transform shape]{angle=u'1--O--vec1}; 
\pic[transform shape,draw=blue,dashed,<-,angle radius=5.3cm,]  {angle=u'1+u'2--O--u1+u2}; 
%vector sums labels 
\coordinate[label={below:$w$}]() at(u1+u2);
\coordinate[label={below:$w'$}] ()at(u'1+u'2);

    % outgoing vector scaled accordingly but I'd rather prefer not
    \path[draw,fill=white] (O)circle[radius=2pt];
    \path[fill] (O)circle[radius=1pt];
\end{tikzpicture}
\end{document}

在此輸入影像描述

也許有更好的方法來實現這一點,我對此持開放態度,但我不會從頭開始更改我的程式碼。

我嘗試過every pic/.append style={transform shape}但沒有明顯的結果。作為副作用,半徑為傳出向量程式碼的最後幾行是縮放的,這是我不想要的。

答案1

由於您想要為每個 附加一個樣式\pic{angle},您可以設定pics/angle/.append style={/tikz/transform shape}(您需要明確聲明路徑,因為您位於\pic此處的「路徑目錄」內):

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, angles}

\begin{document}
%rotate vectors
\begin{tikzpicture}[
    vector/.style={thick,-stealth}, 
    scale=0.4, 
    pics/angle/.append style={/tikz/transform shape}
]
    %drawing help lines
    \newcommand*{\xmin}{-3}\newcommand*{\xmax}{4}
    \newcommand*{\ymin}{-5}\newcommand*{\ymax}{1}
    \draw[help lines] (\xmin,\ymin) grid (\xmax,\ymax);
    %vector coordinates and labels
    \coordinate[label={above:$v$}] (O) at (0,0);
    \coordinate (vec1) at (1,-2);
    \coordinate (vec2) at (4,-1);
    \draw[vector] (O) -- (vec1)
        coordinate[label={[below]$u_1$}] (u1);
    %sum (vec1)+(vec2)  
    \draw[vector,very thick,blue] (O)--($(vec1)+(vec2)$)
        coordinate (u1u2);
    %rotated sum (u1)+(u2) -> u'1+u'2
    \draw[vector,very thick,orange] (O)--([rotate=-90]u1u2)
        coordinate (u'1u'2);
    %rotated vectors 
    \draw[red,vector] (0,0) -- ([rotate=-90]vec1)
        coordinate[label={[left]$u'_1$}] (u'1);
    %
    \draw[red,vector] (0,0) -- ([rotate=-90]vec2)
        coordinate[label={[below]$u'_2$}] (u'2);
    %angles between vectors by angles library, issue with angle radius=  
    %default angle radius=1cm and it does not scale accordingly
    \pic[draw=gray] {angle={u'1--O--u'2}};
    % rotation traces 
    \pic[draw=red, dashed, <-, angle radius=1.8cm] {angle={u'1--O--vec1}};
    \pic[draw=blue, dashed, <-, angle radius=5.3cm] {angle={u'1u'2--O--u1u2}};
    %vector sums labels 
    \coordinate[label={below:$w$}] (w) at (u1u2);
    \coordinate[label={below:$w'$}] (w') at (u'1u'2);
    % outgoing vector scaled accordingly but I'd rather prefer not
    \path[draw, fill=white] (O) circle[radius=2pt];
    \path[fill] (O) circle[radius=1pt];
\end{tikzpicture}
\end{document}

在此輸入影像描述

我更改了一些座標名稱,因為我不確定+名稱中的 a 是個好主意。隨意遵守或不遵守這一點。


(O)如果您不希望縮放處的圓圈,請\pic從中建立一個。我們知道\pics 不受縮放影響,並且pics/angle/.append style={/tikz/transform shape}我們transform shape僅應用於\pic{angle}

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, angles}

\begin{document}
%rotate vectors
\begin{tikzpicture}[
    vector/.style={thick,-stealth}, 
    scale=0.4, 
    pics/angle/.append style={/tikz/transform shape},
    pics/origin/.style={
        code={
            \path[draw, fill=white] (0,0) circle[radius=2pt];
            \path[fill] (0,0) circle[radius=1pt];
        }
    }
]
    %drawing help lines
    \newcommand*{\xmin}{-3}\newcommand*{\xmax}{4}
    \newcommand*{\ymin}{-5}\newcommand*{\ymax}{1}
    \draw[help lines] (\xmin,\ymin) grid (\xmax,\ymax);
    %vector coordinates and labels
    \coordinate[label={above:$v$}] (O) at (0,0);
    \coordinate (vec1) at (1,-2);
    \coordinate (vec2) at (4,-1);
    \draw[vector] (O) -- (vec1)
        coordinate[label={[below]$u_1$}] (u1);
    %sum (vec1)+(vec2)  
    \draw[vector,very thick,blue] (O)--($(vec1)+(vec2)$)
        coordinate (u1u2);
    %rotated sum (u1)+(u2) -> u'1+u'2
    \draw[vector,very thick,orange] (O)--([rotate=-90]u1u2)
        coordinate (u'1u'2);
    %rotated vectors 
    \draw[red,vector] (0,0) -- ([rotate=-90]vec1)
        coordinate[label={[left]$u'_1$}] (u'1);
    %
    \draw[red,vector] (0,0) -- ([rotate=-90]vec2)
        coordinate[label={[below]$u'_2$}] (u'2);
    %angles between vectors by angles library, issue with angle radius=  
    %default angle radius=1cm and it does not scale accordingly
    \pic[draw=gray] {angle={u'1--O--u'2}};
    % rotation traces 
    \pic[draw=red, dashed, <-, angle radius=1.8cm] {angle={u'1--O--vec1}};
    \pic[draw=blue, dashed, <-, angle radius=5.3cm] {angle={u'1u'2--O--u1u2}};
    %vector sums labels 
    \coordinate[label={below:$w$}] (w) at (u1u2);
    \coordinate[label={below:$w'$}] (w') at (u'1u'2);
    % outgoing vector scaled accordingly but I'd rather prefer not
    \pic at (O) {origin};
\end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容