如何获取椭圆体的坐标(东、西、北)?(代码适用于矩形)

如何获取椭圆体的坐标(东、西、北)?(代码适用于矩形)

在此处输入图片描述

    \documentclass{report}
\usepackage{tikz}
\tikzset{add reference/.style={insert path={%
coordinate [pos=0,xshift=-0.5\pgflinewidth,yshift=-0.5\pgflinewidth] (#1 south west) 
coordinate [pos=1,xshift=0.5\pgflinewidth,yshift=0.5\pgflinewidth]   (#1 north east)
coordinate [pos=.5] (#1 center)                        
(#1 south west |- #1 north east)     coordinate (#1 north west)
(#1 center     |- #1 north east)     coordinate (#1 north)
(#1 center     |- #1 south west)     coordinate (#1 south)
(#1 south west -| #1 north east)     coordinate (#1 south east)
(#1 center     -| #1 south west)     coordinate (#1 west)
(#1 center     -| #1 north east)     coordinate (#1 east)   
}}}  
\begin{document}
\begin{tikzpicture}

    \draw (1,0) rectangle (6,3) [add reference=R1];  

    % to verify if the points are good:
    \tikzset{pt/.style={circle,fill=#1,inner sep=0mm,minimum size=4pt}}
    \node[pt=red]    at (R1 south west){};
    \node[pt=red]    at (R1 north west){};  
    \node[pt=red]    at (R1 north east){};
    \node[pt=red]    at (R1 south east){}; 
    \node[pt=black]  at (R1 center){};
    \node[pt=orange] at (R1 west){};
    \node[pt=orange] at (R1 south){};
    \node[pt=orange] at (R1 east){};
    \node[pt=orange] at (R1 north){};

\end{tikzpicture}

\begin{tikzpicture}

    \draw (1,0) ellipse (1 and 1.5) [add reference=E1];  

    % to verify if the points are good:
    \tikzset{pt/.style={circle,fill=#1,inner sep=0mm,minimum size=4pt}}
    \node[pt=red]    at (E1 south west){};
    \node[pt=red]    at (E1 north west){};  
    \node[pt=red]    at (E1 north east){};
    \node[pt=red]    at (E1 south east){}; 
    \node[pt=black]  at (E1 center){};
    \node[pt=orange] at (E1 west){};
    \node[pt=orange] at (E1 south){};
    \node[pt=orange] at (E1 east){};
    \node[pt=orange] at (E1 north){};

\end{tikzpicture}
\end{document}

答案1

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

    \node[xscale=2,draw,circle,text width=3cm,inner sep=0pt] (R1) {};

    \node[fill=red,circle,radius=2pt] at (R1.south west){};
    \node[fill=red,circle,radius=2pt] at (R1.north west){};  
    \node[fill=red,circle,radius=2pt] at (R1.north east){};
    \node[fill=red,circle,radius=2pt] at (R1.south east){}; 
    \node[fill=black,circle,radius=2pt] at (R1.center){};
    \node[fill=orange,circle,radius=2pt] at (R1.west){};
    \node[fill=orange,circle,radius=2pt] at (R1.south){};
    \node[fill=orange,circle,radius=2pt] at (R1.east){};
    \node[fill=orange,circle,radius=2pt] at (R1.north){};

\end{tikzpicture}
\end{document}

椭圆

答案2

您可以使用\node[some attributes] at (n.angle){};整数angle。您还可以使用 for 循环来绘制点。这是一个最小示例,可以轻松设置点的数量和颜色。

输出

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes}
\begin{document}
    \begin{tikzpicture}
        \node[draw,ellipse,minimum width=12em,minimum height=10em,inner sep=0pt] (n) {};
        \def\colours{{"red", "green", "blue", "orange"}}% Colours of points
        \pgfmathtruncatemacro{\numOfColours}{4} % Number of colours to use (4 or less in this case)
        \pgfmathtruncatemacro{\numOfPoints}{12} % Number of points to be plotted
        \pgfmathtruncatemacro{\shift}{90}% 0 = start plotting from right, 90 = start from top, ...
        \foreach \x in {1,...,\numOfPoints}{
            \pgfmathtruncatemacro{\ang}{(360/\numOfPoints) * \x + \shift}
            \pgfmathsetmacro{\c}{\colours[Mod(\x, \numOfColours)]}% Retrieving colour name from array
            \node[fill=\c, circle, inner sep=0pt, minimum size=5pt] at (n.\ang){};
        }
    \end{tikzpicture}
\end{document}

相关内容