tikz:命名路径的端点

tikz:命名路径的端点

我有一个简单的 tikzsketch,它绘制一个相对于三角形中心并垂直于其一条边的矢量。

在此处输入图片描述

我想在草图中的蓝色箭头尖端绘制另一条路径(矢量)。我想我要做的是命名路径末端的坐标,但不确定如何执行此操作的语法。

如何在计算路径中捕获/命名坐标?

\documentclass[border=20pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{intersections, calc,through,backgrounds}

\begin{document}

    \begin{tikzpicture}[scale=2]
    
        % Coordinates for a triangle
        \coordinate (P) at ($(0,0) + (rand,rand)$);
        \coordinate (Q) at ($(2,-2) + .5*(rand, rand)$);
        \coordinate (R) at ($(-2, -2) + .5*(rand, rand)$);
        
        \coordinate (O) at (barycentric cs:P=1,Q=1,R=1) ;
        
        %projection of O on PQ 
        %use this for the intersection point for the vector below
        \coordinate (E) at ($(P)!(O)!(Q)$);
       
        % Vector perpendicular to edge PQ and located at O
        % I would like to get the coordinate at the tip of this vector
        \draw[->, blue] let 
                \p1 = ($(P)-(Q)$)
            in
                (O)--node[midway, sloped, above]{$\vec{A}$}node[above,at end]{${\color{black}S}$}++($(O)!sqrt(\x1*\x1+\y1*\y1)!(E)-(O)$);
    
        
        %\fill[red](S)circle(2pt)
        
        \draw[thin] (P) -- (Q) -- (R) --cycle;
    \end{tikzpicture}
\end{document}

答案1

我认为我已经在你第一个问题中回答过这个问题了。

在下一行中:您可以在绘制点 S 之前
(O)--node[midway, sloped, above]{$\vec{A}$}node[above,at end]{${\color{black}S}$}++($(O)!sqrt(\x1*\x1+\y1*\y1)!(E)-(O)$);
添加。coordinate[at end](S)

然后你得到:
(O)--node[midway, sloped, above]{$\vec{A}$} coordinate[at end](S) node[above,at end]{${\color{black}S}$}++($(O)!sqrt(\x1*\x1+\y1*\y1)!(E)-(O)$);

答案2

在此处输入图片描述

\documentclass[border=20pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{intersections, calc,through,backgrounds}

\begin{document}

    \begin{tikzpicture}[scale=2]
    
        % Coordinates for a triangle
        \coordinate (P) at ($(0,0) + (rand,rand)$);
        \coordinate (Q) at ($(2,-2) + .5*(rand, rand)$);
        \coordinate (R) at ($(-2, -2) + .5*(rand, rand)$);
        
        \coordinate (O) at (barycentric cs:P=1,Q=1,R=1) ;
        
        %projection of O on PQ 
        %use this for the intersection point for the vector below
        \coordinate (E) at ($(P)!(O)!(Q)$);
       
        % Vector perpendicular to edge PQ and located at O
        % I would like to get the coordinate at the tip of this vector
        \draw[->, blue] let 
                \p1 = ($(P)-(Q)$)
            in
                (O)--
                node[midway, sloped, above]{$\vec{A}$}
                coordinate[at end, label=aux, fill=red, circle, inner sep=0.5pt ]
                ++(
                    $(O)!sqrt(\x1*\x1+\y1*\y1)!(E)-(O)$
                    );
    
        
%        \fill[red](aux)circle(2pt)
        
        \draw[thin] (P) -- (Q) -- (R) --cycle;
    \end{tikzpicture}
\end{document}

相关内容