How to draw an ellipse with FeynMF?

How to draw an ellipse with controllable parameters?

The formula for ellipse is (x^2)/(a^2) + (y^2)/(b^2) = 1. Parameters a and b are called semi-major and semi-minor axis, respectively. In other words, 2a is the width whereas 2b is the height of an ellipse.

• the main trick will be to parametrize the ellipse: x(t)=a*cos(t) and y(t)=b*sin(t) where 0\leq t\leq 2\pi; I don't know about feynmf, but this would be very easy in pgfplots or PSTricks; let me know if you'd like to see such a solution – cmhughes Dec 3 '12 at 17:29
• Definitely, I'd like to see such a solution. Not only will it be helpful in and of itself, but also will give us an idea how to implement the code into FeynMP. Thank you. – Laura Dec 3 '12 at 20:44

You can also use tikz directly, without parametrizations: the circle construction lets you specify the desired values as x radius and y radius; a little example:

\documentclass{article}
\usepackage{tikz}

\def\faxis{3cm}
\def\saxis{2cm}

\begin{document}

\begin{tikzpicture}
\draw[step=.5cm,gray!20,very thin] (-4,-5) grid (7,5);
\draw (-4,0) -- (7,0) coordinate (x axis);
\draw (0,-5) -- (0,5) coordinate (y axis);

\def\faxis{1cm}
\def\saxis{4cm}
\def\faxis{5cm}
\def\saxis{2cm}
\end{tikzpicture}

\end{document} • Right, this is analogous to the MetaPost code of Ellipse(expr a, b) where x -> a, and y -> b. – Mafra Dec 3 '12 at 23:03

If you parametrize the ellipse as, for example,

x(t)=a*cos(t)
y(t)=b*sin(t)

where 0\leq t\leq 2\pi, then you can use pgfplots to plot it \documentclass{standalone}
\usepackage{pgfplots}

% global settings int he preamble
\pgfplotsset{every axis/.append style={%
axis x line=middle,
axis y line=middle,
axis line style={<->}, % arrows on the axis
xlabel={$x$},          % default put x on x-axis
ylabel={$y$},          % default put y on y-axis
}
}

% change the arrows to stealth fighters (personal preference)
\tikzset{>=stealth}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
xmin=-5, xmax=5,
ymin=-5, ymax=5,
grid=major,
]
\end{axis}
\end{tikzpicture}

\end{document}

A whole host of options are available to you- have a look at the manual and the other questions on this site tagged with pgfplots for examples :)

Following the comments, you could define a and b as follows

\begin{tikzpicture}
\begin{axis}[
xmin=-5, xmax=5,
ymin=-5, ymax=5,
grid=major,
]
\def\a{3}
\def\b{5}
\end{axis}
\end{tikzpicture}
• Thank you so much cmhughes! Is it possible to have a and b defined somewhere to yield a full control? – Laura Dec 3 '12 at 21:09
• @Laura you're welcome :) see the update – cmhughes Dec 3 '12 at 22:31

How exactly do you want to use this ellipse?

In any case, you can modify the FeynMF sources in a similar way as in How to draw oval with FeynMP? (or use the mechanism pointed out by egreg in his comments).

Since FeynMF uses Metapost in the background you need to know how to obtain the ellipse first. Simply scale the circle with the parameters a and b (the code below can be compiled with mpost file.mp and it produces an EPS file.1)

u:=1cm;
beginfig(1);

def Ellipse(expr a, b) =
draw fullcircle scaled 1cm xscaled a yscaled b
enddef;

Ellipse(2,1);
endfig;
end;

The rescaled circle is mathematically equivalent to an ellipse.

EDIT: Using egreg's suggestion I defined an elliptical blob from within the latex file using \fmfcmd

\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{feynmp}
\setlength{\unitlength}{1mm}

\def\fmfblobEllipse#1#2#3{\fmfcmd{vblobEllipse ((#1), (#2), \fmfpfx{#3});}}

\begin{document}
\begin{center}
\begin{fmffile}{lower_blobE}
\begin{fmfgraph*}(50,70)
\fmfcmd{input vblobEllipse}
\fmfrightn{r}{1}
\fmfleftn{l}{1}
\fmftopn{t}{1}
\fmfblobEllipse{.5w}{.5}{v1}
\fmf{fermion}{l1,v1}
\fmf{fermion}{v1,r1}
\fmf{photon}{t1,v1}
\end{fmfgraph*}
\end{fmffile}
\end{center}
\end{document}

The file vblobEllipse.mp:

vardef vblobEllipse (expr bd, a) (text vl)=
forsuffixes $=vl: if not vexists$: venter $; fi vlist[vlookup$]decor.shape := fullcircle xscaled a;
vlist[vlookup $]decor.size := bd; vlist[vlookup$]decor.sty := "shaded";
endfor
enddef;

Where I defined only one parameter for the ellipse, since the overall scale does not matter for the shape.

This is the diagram one gets from the above: However if you need to use ellipses together with Feynman diagrams (in the sense of side-by-side, and not as being part of the diagram itself), you can generate one ellipse using mpost with the original code from above.

• the idea of x or y-scaling of a circle isn't sufficient for my purpose. I need exact ellipse with controllable parameters within the picture environment. Isn't there a way in FeynMF [or FeynMP] to draw any given function with a \fmfcmd? – Laura Dec 3 '12 at 20:42
• @Laura: Can you provide a MWE of what you want to do? Where do you want this ellipse to appear and why are you doing this from FeynMF instead of using MetaPost directly like above? I ask this because with the usual conventions for Feynman diagrams you never need to bother about ellipses at all... – Mafra Dec 3 '12 at 20:50
• Mafra, unfortunately I don't have MWE. I need an ellipse to use it along with other Feynman graphs; maybe together injunction, for various presentations. Also, I am very interested to see how one can draw a random function with \fmfcmd albeit by abusing the FeynMF :) – Laura Dec 3 '12 at 21:09
• Mafra, you said "The rescaled circle is mathematically equivalent to an ellipsis." Can you prove this claim? :) – Laura Dec 3 '12 at 23:24
• @Laura: I can prove that, but others have already written about it before: math.stackexchange.com/questions/79842/… – Mafra Dec 3 '12 at 23:30