Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to make ellipse with eigenvectors and eigenvalues in tikz. I'm having tough time with managing my braces. I wonder if there is any analyticall approach to adjust braces. Thanks

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{shapes.geometric}
\pgfplotsset{compat=1.7}

\begin{document}

\begin{tikzpicture}
\draw[rotate=45, line width = 0.5mm] (0, 0) ellipse (4.5cm and 2.0cm);

\draw[line width = 0.5mm, dashed, ->] (-5, 0) -- (5, 0) node[right]{$X_{1}$};
\draw[line width = 0.5mm, dashed, ->] (0, -5) -- (0, 5) node[above]{$X_{2}$};
\draw[line width = 0.5mm, ->] (-4, -4) -- (4, 4) node[above right]{$e_1$};
\draw[line width = 0.5mm, ->] (3, -3) -- (-4, 4) node[above left]{$e_2$};
\draw [decorate, decoration = {brace, amplitude = 15pt, mirror, raise =4pt}, yshift = 0pt]
(3, 3.2) -- (0, 0) node [black, midway, xshift = -0.5cm, yshift = 0.8cm ] {$\frac{c}{\sqrt{\lambda_1}}$};

\draw [decorate, decoration = {brace, amplitude = 15pt, mirror, raise =4pt}, yshift = 0pt]
(-1.4, 1.4) -- (0, 0) node [black, midway, xshift = -0.9cm, yshift = -0.3cm ] {$\frac{c}{\sqrt{\lambda_2}}$};

\end{tikzpicture}

\end{document}

enter image description here

share|improve this question
1  
Could you be more specific about what the issue is? Do you mean that you don't want to manually specify the values for amplitude and raise? –  Jake Feb 18 '13 at 16:04
    
Thanks @jake for showing your interest in my problem. I just wonder if there is more analytical way to adjust the braces. You can see that the braces are not well aligned. So I want to adjust the braces with some mathematical formula. –  MYaseen208 Feb 18 '13 at 16:08
    
If you mean the position of the end points of the braces: You could just specify the coordinate in terms of the rotation and the semi-axis lengths with polar coordinates: \draw [decorate,...] (45:4.5) -- (0, 0) for the major semi-axis, and \draw [decorate,...] (45+90:2) for the minor semi-axis. Is that what you mean? –  Jake Feb 18 '13 at 16:12
1  
@MYaseen208 I propose you use the ellipse shape. Than you can use the anchors north, east and center to specify the braces’ start and end points without the need to adjust the coordinates (or even calculate them). –  Qrrbrbirlbel Feb 18 '13 at 16:12
    
Thanks @Qrrbrbirlbel for your comment. Would you mind to get more detail about ellipse? Might as an answer. –  MYaseen208 Feb 18 '13 at 16:14

3 Answers 3

up vote 6 down vote accepted

You have loaded the pgfplots package, although you did not use it. I have removed it and have loaded only TikZ instead (in this case by the class option tikz).

Use styles!

I have introduced a few. These are:

  • elli=<angle>:<x radius> and <y radius>

    The elli style results in a node in the shape of an ellipse with the assigned radii rotated by <angle>.

    The style also uses outer sep=0pt to move the anchors to the middle of the line.

  • elli node=<angle>

    The elli node style should be used for the nodes for the braces (the eigenvalues?). The not-drawn shape circle is used to place the node more precisely. This is done in two ways:

    1. The anchor is set to <angle>-90, so that the node is placed rectangular to the decorated line.

    2. The node is shifted in the opposite direction, <angle>+90 by the amount of the amplitude and the raise amount (the raise amount is not stored in a macro like the amplitude amount so I stored in manually with the addition to /pgf/decoration/raise).

    Take a look at this animation to see how you can overwrite the anchor to replace the node (I used this for the y eigenvalue). It may also needed to use the shift options of TikZ anyway.

    enter image description here

  • eigen={<amplitude>}{<raise>}

    This style does all bracing with the given values for the amplitude and the raise option. The default values are 15pt and 4pt (as in your example).

  • The styles axis and normal axis should be self-explanatory.

Notes (Further Enhancements)

  • Rename the styles if you have more fitting names, say eigenvalue instead of elli node.

  • I noticed now that the mirror option is not taken into account for the placement of the elli node. Meaning that the nodes are always placed on the left side. This could be fixed quite easily.

  • I have used the ellipsoid node’s anchors to draw the lines e1 and e2. I am not entirely sure how long the lines should be. This is just one option of many to place lines relative to another object.

    The normal axes are not touched (except for the style).

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{
    shapes.geometric,
    decorations.pathreplacing
}
\tikzset{
    elli/.style args={#1:#2and#3}{
        draw,
        shape=ellipse,
        rotate=#1,
        minimum width=2*#2,
        minimum height=2*#3,
        outer sep=0pt,
    },
    /pgf/decoration/raise/.append code={
        \def\tikzdecorationsbrace{#1}
    },
    elli node/.style={
        circle,
        black,
        draw=none,
        midway,
        anchor=#1-90,
        inner sep=0pt,
        shift=(#1+90:\tikzdecorationsbrace+\pgfdecorationsegmentamplitude)
    },
    eigen/.style 2 args={
        decorate,
        decoration={
            brace,
            amplitude=#1,
            mirror,
            raise=#2,
        },
    },
    eigen/.default={15pt}{4pt},
    axis/.style={
        line width=.5mm,
        ->,
    },
    normal axis/.style={
        axis,
        dashed,
    }
}
\begin{document}

\begin{tikzpicture}
\node[elli=45:4.5cm and 2.0cm, line width = 0.5mm] at (0, 0) (e) {};

\draw[normal axis] (-5, 0) -- (5, 0) node[right] {$X_{1}$};
\draw[normal axis] (0, -5) -- (0, 5) node[above] {$X_{2}$};

\draw[axis] ([shift={(45:-5.5cm)}]    e.center) -- ([shift={(45:5.5cm)}]    e.center) node[above right] {$e_1$};
\draw[axis] ([shift={(90+45:-5.5cm)}] e.center) -- ([shift={(90+45:5.5cm)}] e.center) node[above left]  {$e_2$};


\draw[red,eigen] (e.east) -- (e.center) 
    node[elli node=45] {$\frac{c}{\sqrt{\lambda_1}}$};

\draw[red,eigen] (e.north) -- (e.center) 
    node[elli node=45+90, anchor=-15] {$\frac{c}{\sqrt{\lambda_2}}$};
\end{tikzpicture}
\end{document}

Output

enter image description here

share|improve this answer

You should use scope environment to draw all the stuff that will rotate, and place the coordinate for the non rotating text.

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}
\begin{tikzpicture}
\begin{scope}[remember picture,rotate=45]
    \coordinate (O) at (0,0);
    \coordinate (A) at (4.5,0);
    \coordinate (B) at (0,2);
    % draw ellipse
    \draw[line width = 0.5mm] (O) ellipse (4.5cm and 2.0cm);
    % draw axis
    \draw[line width = 0.5mm, ->] (-5, 0) -- (5, 0) coordinate[right] (e1);
    \draw[line width = 0.5mm, ->] (0, -5) -- (0, 5) coordinate[above] (e2);
    % calculate brace points for major axis
    \path (O) -- (A) coordinate[pos=.02] (a1) coordinate[pos=.98] (a2);
    \draw[decorate, decoration = {brace, amplitude = 15pt, mirror, raise =4pt}, yshift = 0pt]
        (a2) -- (a1) coordinate[midway] (tl1);
    \coordinate (l1) at ([yshift=1cm]tl1);
    % calculate brace points for minor axis
    \path (O) -- (B) coordinate[pos=.05] (b1) coordinate[pos=.95] (b2);
    \draw[decorate, decoration = {brace, amplitude = 15pt, mirror, raise =4pt}, yshift = 0pt]
        (b2) -- (b1) coordinate[midway] (tl2);
    \coordinate (l2) at ([xshift=-.9cm]tl2);
\end{scope}
\draw[line width = 0.5mm, dashed, ->] (-5, 0) -- (5, 0) node[right]{$X_{1}$};
\draw[line width = 0.5mm, dashed, ->] (0, -5) -- (0, 5) node[above]{$X_{2}$};
\node[anchor=south west] at (e1) {$e_1$};
\node[anchor=south east] at (e2) {$e_2$};
\node[anchor=south west] at (l1) {$\frac{c}{\sqrt{\lambda_1}}$};
\node[anchor=south east] at ([xshift=.1cm]l2) {$\frac{c}{\sqrt{\lambda_2}}$};   
\end{tikzpicture}
\end{document}

Edit: modifications as suggested

result

share|improve this answer
    
@egreg is it better? –  Lionel MANSUY Feb 18 '13 at 16:32
    
Better indeed; the minor axis label conflicts with the dashed axis, so it has to be offset as you do. The braces could be a bit shorter to make their end points visible. –  egreg Feb 18 '13 at 16:39
    
@egreg: edit as suggested; is there a mean to use the x value of coordinate A as input for the major axis? –  Lionel MANSUY Feb 18 '13 at 16:50
    
Oh, I don't know. I was just making suggestions based on the figure's appearance. Only from a reader's point of view, I'd say. –  egreg Feb 18 '13 at 16:57

enter image description here

\documentclass[pstricks,border=3pt]{standalone}
\usepackage{pst-plot,pst-node,amsmath}

\pstVerb
{
    /PtCm {72.27 div 2.54 mul} def
    /Radius 11 def
}
\psset
{
    dimen=middle,
    nodesep=2pt,
    linearc=5pt,
    arm=4pt,
}

\begin{document}
\begin{pspicture}(-3.75,-3.75)(4,4)
\psaxes[labels=none,ticks=none,arrowinset=0,linestyle=dashed]{->}(0,0)(-3.75,-3.75)(3.25,3.5)[$X_1$,0][$X_2$,90]
\rput{45}(0,0){
        \psaxes[labels=none,ticks=none,arrowinset=0]{->}(0,0)(-3.5,-3.5)(3.5,3.5)
            [{\rput{*0}(5pt,0){$e_1$}},0]
            [{\rput{*0}(0,5pt){$e_2$}},90]
        \psellipse[dimen=middle](0,0)(3,1.5)
        \psset{linecolor=gray,angleA=90,angleB=270}
        \pcdiag(0,0)(1.5,12pt)
        \pcdiag(3,0)(1.5,12pt)
        \rput{*0}(!Radius PtCm 100 PtoC exch 1.5 add exch 12 PtCm add){$\tfrac{c}{\sqrt{\lambda_1}}$}
        \psset{angleA=180,angleB=0}
        \pcdiag(0,1.5)(-12pt,0.75)
        \pcdiag(0,0)(-12pt,0.75)
        \rput*{*0}(!Radius PtCm 200 PtoC exch 12 PtCm sub exch 0.75 add){$\tfrac{c}{\sqrt{\lambda_2}}$}
}
\end{pspicture}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.