
\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