2

I want to draw a curve which is solid over $0$ to $\rho_1$, but dashed (or dotted) thereafter. But, despite much experimentation, I can only get it solid all the time. Any thoughts appreciated.

\documentclass[a4paper,font=12]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,spy,positioning,snakes}
\usepackage{curves}
\usepackage{xcolor,colortbl}

\begin{document}

\begin{figure} \begin{center} \unitlength = 1mm \begin{picture}(70,70)(0,0) \put(0,0){\vector(1,0){70}} \put(0,0){\vector(0,1){70}} \put(25,0){\circle*{1.7}} \put(25,-4){${\rho}_1$} \put(-10,50){$m(0)$} { \curve(0,50, 25, 35, 50, 0) } \end{picture} \end{center} \end{figure}

\end{document}

enter image description here

leandriis
  • 62,593
cel
  • 21
  • see answer here: https://tex.stackexchange.com/questions/45275/tikz-get-values-for-predefined-dash-patterns/45276 – naphaneal Dec 26 '20 at 12:54
  • Thanks a lot. The problem is i want to have a curve which is part solid, part dashed. This link (though certainly helpful) doesn't seem to address that possibility if I'm not mistaken. – cel Dec 26 '20 at 13:34
  • 1
    You load TikZ but then use picture for your drawing. Are you interested in other drawing methods, such as TikZ, or does it have to be using the picture environment? – Andrew Stacey Jan 26 '21 at 08:12

3 Answers3

1

If you are happy to try lualatex, then you could use Metapost, like this:

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
numeric u; u = 1mm;
path xx, yy, ff;

xx = origin -- (70u, 0);
yy = xx rotated 90;
ff = ((0, 50) .. (25, 35) .. (50, 0)) scaled u;

draw subpath (0, 1) of ff withcolor 2/3 blue;
draw subpath (1, 2) of ff dashed withdots scaled 1/2 withcolor 2/3 blue;

drawarrow xx;
drawarrow yy;

dotlabel.lft("$m(0)$", point 0 of ff);
dotlabel.bot("$\rho_1$", (xpart point 1 of ff, 0));

endfig; \end{mplibcode} \end{document}

Compile this with lualatex...

enter image description here

Thruston
  • 42,268
1

This is an Asymptote solution for comparison. Here the functions times and subpath.

real[] times(path p, real x)

returns all intersection times of path p with the vertical line through (x,0);

path subpath(path p, real a, real b);

returns the subpath of p running from path time a to path time b, in the sense of point(path, real). If a > b, the direction of the subpath is reversed.

enter image description here

// http://asymptote.ualberta.ca/
unitsize(8mm);
real a=2;
path m=(0, 5) .. (2.5, 3.5) .. (5,0);
real[] t=times(m,a);
pair A=(a,0);
pair M=point(m,t[0]);
path m1=subpath(m,0,t[0]);
path m2=subpath(m,t[0],length(m));
draw(A--M,gray);
draw(m1,blue);
draw(m2,red+dashed);
dot(M,red);
dot("$a$",align=S,A);
dot(scale(.6)*"$m(0)$",align=W,point(m,0));
import graph;
axes("$x$","$y$",min=(-.5,-.5),max=(6,6),Arrow(TeXHead));
shipout(bbox(5mm,invisible));
Black Mild
  • 17,569
0

I thought to come up with a TikZ solution (as it's been a while since this was posted and there are now two non-picture solutions), but to do that I had to figure out what \curve was doing and that led me to the curves package which you are loading. In reading that, I discovered the \tagcurve command which omits the first and last segments of a \curve, so that they are used to define the curve but not render it. When applied to a \curve with only three defining points, it omits only the last segment. Since your curve only has three defining points this suggests a cunning strategy: use \tagcurve twice - once with the points in reverse - to draw each segment of your curve separately.

Now it may be that in your question you use a very simple example and that your real use-case has a much more complicated curve. But actually, this could be extended if you use \tagcurve instead of \curve throughout since the purpose of \tagcurve is to draw each segment as if it were part of a larger curve. So splitting a \tagcurve into shorter segments (with suitable repetition of the vertices either side of the break) should just produce a shorter segment of exactly the same curve.

So here's a picture version of what you're asking for.

\documentclass[a4paper,12pt]{article}
%\url{https://tex.stackexchange.com/q/576435/86}
\usepackage{curves}

\begin{document}

\begin{figure} \begin{center} \unitlength = 1mm \begin{picture}(70,70)(0,0) \put(0,0){\vector(1,0){70}} \put(0,0){\vector(0,1){70}} \put(25,0){\circle*{1.7}} \put(25,-4){${\rho}_1$} \put(-10,50){$m(0)$} { \curvedashes[1mm]{0.5,1.5} \tagcurve(0,50, 25, 35, 50, 0) } { \tagcurve(50,0, 25, 35, 0,50) } \end{picture} \end{center} \end{figure} \end{document}

A curve that becomes dashed half way along

Notes:

  1. This works because the point at which you want to switch behaviour (above rho) is one of your specified vertices along the curve.
  2. I would actually do this with TikZ. You are loading TikZ anyway, so the general argument for using the picture environment as a smaller footprint is spurious. And even if you were not, the flexibility from using a more powerful drawing package - whether TikZ or asymptote or pstricks - vastly outweighs that.
Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751