불안정한 측정 매크로

불안정한 측정 매크로

\measurement내 도면에 측정값을 추가할 수 있는 매크로를 만들었습니다 . 잘 작동하지만 레이블이 때때로 불안정합니다. 아래 예에서는 명령이 사실상 동일하더라도 측정 라벨이 다르게 회전됩니다. 라벨링을 제어하는 ​​더 나은 방법이 있어야 한다고 생각합니다. 누구든지 아이디어가 있나요?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\tikzset{myscale/.code={\edef\myscale{#1}\tikzset{scale=#1}}}
\def\myscale{1}

\newcommand{\measure}[4]{%
\pgfmathsetlengthmacro\mylength{8pt/\myscale}
\draw[very thin] #1 -- ($#1!\mylength!-90:#2$) coordinate (a) -- ($#1!\mylength+0.4*\mylength!-90:#2$);
\draw[very thin] #2 -- ($#2!\mylength!90:#1$) coordinate (b) -- ($#2!\mylength+0.4*\mylength!90:#1$);
\draw[very thin,<->,>=stealth] (a) -- (b) node[auto,sloped,#3] {#4};
}

\begin{document}

\begin{tikzpicture}[myscale=0.12]
\begin{scope}[rotate=20]

\draw[red] (0,0) -- (0,12);
\measure{(0,0)}{(0,12)}{midway,above,rotate=20,font=\small}{red}

\draw[blue] (0,12) -- (0,24);
\measure{(0,12)}{(0,24)}{midway,above,rotate=20,font=\small}{blue}

\end{scope}
\end{tikzpicture}

\end{document}

여기에 이미지 설명을 입력하세요

답변1

반올림을 제외한 수직선이 있고 20도 회전합니다. 반올림 정도에 따라 선이 왼쪽으로 조금 기울거나 오른쪽으로 조금 기울어지며 자연스럽게 노드가 뒤집히게 됩니다.

나는 당신이 무엇을 하려고 하는지, 또는 그것을 가장 잘 하는 방법을 조사하려고 시도하지 않았습니다. 어쩌면 다른 질문일 수도 있습니다.

대답은 다음과 같습니다.수직이 불안정해짐.

효과를 보려면 다음 코드를 사용해 보세요.

\documentclass[tikz, border=1cm]{standalone}
\tikzset{
nodetest/.pic={
\coordinate (c) at (1,10); %intermediate coordinate to create rounding
\draw (1,0) -- (c) node[auto, sloped, midway] {test};
}}
\begin{document}
\begin{tikzpicture}
\foreach \pos in {0.01,0.02,...,2} 
\pic[scale=\pos] at (10*\pos,0) {nodetest};
\end{tikzpicture}
\end{document}

(0,0)에서 (1,10)까지의 스케일링된 선:

노드 밴드가 있는 선의 삼각형

(2,0)에서 (1,10)까지의 스케일링된 선:

노드 밴드가 있는 선의 삼각형

(1,0)에서 (1,10)까지의 스케일링된 선:

불안정한 노드 밴드가 있는 선의 삼각형

중앙의 어두운 마디 띠가 수직선에 불안정한 것을 알 수 있습니다.

편집하다:

나는 당신이 원하는 것이 무엇인지 추측할 수 있을 뿐입니다. 다음은 첫 번째 좌표에서 두 번째 좌표까지 읽은 선 아래에 평행한 노드를 보여줍니다. 모든 면에서 안정적입니다.

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\foreach \ang in {0,20,...,340}{
\coordinate (a) at (\ang:1);
\coordinate (b) at (\ang:4);
\draw[Stealth-Stealth] (a) --node[sloped, auto, swap, allow upside down=true]{red} (b);
}
\end{tikzpicture}
\end{document}

라벨이 있는 이중 화살표 원

답변2

아마도 이것이 도움이 될 것입니다.tkz-euclide

여기에 이미지 설명을 입력하세요

MWE

\documentclass{article}
\usepackage{tkz-euclide}
\begin{document}
    

\begin{tikzpicture}[scale=1.2]
    \tkzDefPoints{0/0/A,-4/4/B}
    \tkzDefPointWith[linear,K=0.5](A,B)
    \tkzGetPoint{C}

    \tkzDrawSegment[red, very thick](A,C)
    \tkzDrawSegment[blue,very thick](B,C)
    \tkzDrawPoints[color=black](A,B,C)
    \tkzLabelPoints[above right=3pt](A,B,C)
    \tkzDrawSegment[style=red, dashed, dim={$10$,15pt,midway,font=\scriptsize, rotate=45}](A,C) 
    \tkzDrawSegment[style=blue, dashed, dim={$10$,15pt,midway,font=\scriptsize, rotate=45}](C,B) 
\end{tikzpicture}
\end{document}

관련 정보