使用 pict2e 或类似工具绘制椭圆

使用 pict2e 或类似工具绘制椭圆
\usepackage{pict2e}

\usepackage{pstricks-add}

\usepackage{pst-node,pst-plot}

\psset{plotpoints=9,unit=3}

不知何故,根据各种人的建议,我把上面的代码行放在了我的\begin{document}行上方,我不确定这三个包的内容有什么区别,也不确定最后一个命令的作用,但我已经能够绘制一些我需要的简单图表,涉及某些位置的线条、点、圆圈和文本。

现在我想画一个椭圆。我可以指定长轴和短轴的端点,它们是水平和垂直的,而不是以某个奇怪的角度,我还可以在曲线上以对称模式指定四个点。

可以这样做吗?

答案1

使用pstricks,非常容易:

        \documentclass[a4paper]{article}
        \usepackage[utf8]{inputenc}
        \usepackage[T1]{fontenc}

        \pagestyle{empty}

        \usepackage[pdf, svgnames]{pstricks}%
        \usepackage{pstricks-add}

        \begin{document}

        \begin{pspicture}
        \psaxes{->}(0,0)(-6,-5)(7,5)
        \psclip{
        \psellipse[linewidth = 1.5pt, linecolor = Purple](1,-1)(4,3)}
        \psset{linestyle = dashed, linewidth = 0.6pt}
        \psline(1,-5)(1,7)\psline(-6,-1)(7,-1)
        \endpsclip
        \psEllipseTangents(1,-1)(4,3)(-2,3)
        \psline{*-*}(-2,3)(EllipseT1)
        \psline{*-*}(-2,3)(EllipseT2)
        \end{pspicture}

        \end{document} 

在此处输入图片描述

解释:\psellipse第一个参数是其中心坐标。第二个参数给出其水平和垂直半轴。要得到具有其他轴的椭圆,您必须围绕其中心旋转它。

至于psEllipseTangent宏,它允许从给定点绘制椭圆的切线;它有该点的坐标作为第三个参数。与椭圆的接触点是名为EllipseT1和 的节点EllipseT2

答案2

类似的解决方案,但加载的包较少:

\documentclass{article}

\usepackage{pstricks-add}


\begin{document}

\begin{pspicture}(-4.2,-2.2)(4.85,5.7)
  \psaxes{->}(0,0)(-4.2,-2.2)(4.5,5.3)[$x$,0][$y$,90]
  \psdot(2,4)
  \psellipse(0,0)(3,1.5)
  \psEllipseTangents(0,0)(3,1.5)(2,4)
 \psset{nodesep = -1cm, linecolor = blue}
  \pcline(2,4)(EllipseT1)
  \pcline(2,4)(EllipseT2)
  \psdots(EllipseT1)(EllipseT2)
  \uput[135](EllipseT1){$T_{1}$}
  \uput[45](EllipseT2){$T_{2}$}
\end{pspicture}

\end{document}

输出

答案3

tikz

\documentclass[svgnames,tikz,border=10pt]{standalone}
\begin{document}
  \begin{tikzpicture}
    \draw[very thick, -stealth] (-6,0) -- (6,0);
    \foreach \x in {-5,-4,-3,-2,-1,1,2,3,4,5}{
      \draw (\x,0.2) -- (\x,-0.2) node[below] {\x};
    }
    \draw[very thick, -stealth] (0,-6) -- (0,6);
    \foreach \y in {-5,-4,-3,-2,-1,1,2,3,4,5}{
      \draw (0.2,\y) -- (-0.2,\y) node[left] {\y};
    }
    \draw[very thick,Purple] (-1,3) arc [start angle=0,end angle=360,x radius = 2cm, y radius=1cm]node[circle,fill,pos=0.3,sloped,inner sep=2pt] (a){} node [circle,fill,pos=0.9,sloped,inner sep=2pt] (b) {};
   \draw[shorten <= -1cm, shorten >= -7cm] (a.west) -- (a.east);
   \draw[shorten <= -1cm, shorten >= -5cm] (b.west) -- (b.east);
  \end{tikzpicture}
\end{document}

在此处输入图片描述

答案4

在此处输入图片描述

一种Asymptote解决方案,利用更简单的单位圆作为基础来获取椭圆的切点。该过程getTangentPoints使用两个输入参数计算两个切点:transform tr用于将原点处的单位圆转换为ellipse,以及 a pair T- 点的坐标。

%
% ell.tex :
%
\documentclass[10pt,a4paper]{article}
\usepackage{lmodern}
\usepackage{subcaption}
\usepackage[inline]{asymptote}
\begin{asydef}
import graph;
import fontsize;
defaultpen(fontsize(9pt));

pair O=(0,0);

pen linepen=deepblue+0.8bp;
pen tanpen=orange+0.8bp;
pen graypen=gray+0.6bp;

pair[] getTangentPoints(transform tr, pair T){
  assert(!inside(tr*Circle(O,1),T)
    ,"*** The point is not outside of the ellipse ***");
  pair[] p=new pair[2];   
  pair tmp1, tmp2;
  transform tphi;
  tmp1=tr^(-1)*T;
  tphi=rotate(-degrees(dir(tmp1)));
  tmp2=tphi*tmp1;
  p[0]=(1/tmp2.x,sqrt(1-1/tmp2.x^2));
  p[1]=(p[0].x,-p[0].y);
  return tr*tphi^(-1)*p;
}
\end{asydef}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
%
\begin{document}
%
\begin{figure}
\captionsetup[subfigure]{justification=centering}
    \centering
      \begin{subfigure}{0.45\textwidth}
\begin{asy}
size(70mm);
real a=2, b=0.618a;

pair T0=(1.5,-2);

transform tr=shift(1.3,-0.5)*rotate(20)*scale(a,b);
guide Ellipse=tr*Circle(O,1);

pair[] T=getTangentPoints(tr,T0);

xaxis(RightTicks(OmitTick(0),Step=1,step=0.5));
yaxis( LeftTicks(OmitTick(0),Step=1,step=0.5));

draw(Ellipse,linepen);
draw(tr*(N--S),graypen);draw(tr*(E--W),graypen);
draw(T0--(T[0]+dir(T[0]-T0)),tanpen);
draw(T0--(T[1]+dir(T[1]-T0)),tanpen);

dot(T0--T[0]--tr*O--T[1],UnFill);

label("$T_0$",T0,T0-tr*O);
label("$T_1$",T[0],T[0]-tr*O);
label("$T_2$",T[1],T[1]-tr*O);

\end{asy}
%
\caption{}
\label{fig:1a}
\end{subfigure}
%
\begin{subfigure}{0.45\textwidth}
\begin{asy}
size(70mm);
real a=3, b=0.2a;

pair T0=(4,0.9);

transform tr=shift(0.3,-1.5)*rotate(-35)*scale(a,b);
guide Ellipse=tr*Circle(O,1);

pair[] T=getTangentPoints(tr,T0);

xaxis(RightTicks(OmitTick(0),Step=1,step=0.5));
yaxis( LeftTicks(OmitTick(0),Step=1,step=0.5));

draw(Ellipse,linepen);
draw(tr*(N--S),graypen);draw(tr*(E--W),graypen);
draw(T0--(T[0]+dir(T[0]-T0)),tanpen);
draw(T0--(T[1]+dir(T[1]-T0)),tanpen);

dot(T0--T[0]--tr*O--T[1],UnFill);

label("$T_0$",T0,T0-tr*O);
label("$T_1$",T[0],T[0]-tr*O);
label("$T_2$",T[1],T[1]-tr*O);
\end{asy}
%
\caption{}
\label{fig:1b}
\end{subfigure}
\caption{}
\label{fig:1}
\end{figure}
%
\end{document}
%
% Process:
%
% pdflatex ell.tex
% asy ell-*.asy
% pdflatex ell.tex

相关内容