1

I have the following TikZ:

\begin{tikzpicture}

\draw[fill=gray!50, dashed] 
([shift={(-0.5,0)}]0:0.5) arc[radius=0.5cm, start angle=0, end angle=45] 
-- ([shift={(0,0)}]102.5:0.383) arc[radius=0.383cm, start angle=102.5, end angle=67.5] 
-- ([shift={(0.5,0)}]135:0.5) arc[radius=0.5cm, start angle=135, end angle=180]  
-- cycle;

\end{tikzpicture}

It generates

cusp

I want this exact shape, except I want the arc that bounds the top to have a solid line instead of dashed. Can I do this in a single \draw command? If not, what's the easiest way to get this done?

5
  • Welcome! Please post a complete minimal example. That is much more useful than a mere fragment of code. But you cannot do this using a single \draw. Why is that important?
    – cfr
    Jul 9, 2016 at 23:47
  • 1
    A compilable document starts with \documentclass and ends \end{document}.
    – cfr
    Jul 9, 2016 at 23:53
  • 2
    Simplest probably is to draw over it with a solid arc in a subsequent draw command. Jul 10, 2016 at 0:31
  • @PeterGrill thanks, you're probably right. If you want to post that as an answer I'll accept it!
    – Twiffy
    Jul 10, 2016 at 1:45
  • 1
    Please use the official Stack Exchange interface for uploading images rather than self-hosting. This ensures that all images will always be accessible and won't expire. Jul 10, 2016 at 3:32

2 Answers 2

1

Simplest solution is probably just to draw over it:

enter image description here

Note:

  • I had to stretch the line by 0.18em for some reason. Made the line width slightly larger to hide the slight discrepancy cause but this stretch. As you know the code better you can remove the shorten <=-0.18em] and line width=0.57pt options and adjust the drawing.

Code:

\documentclass[tikz,border=10pt]{standalone}

\begin{document}
\begin{tikzpicture}

\draw[fill=gray!50, dashed] 
   ([shift={(-0.5,0)}]0:0.5)    arc[radius=0.5cm,   start angle=0,     end angle=45  ] 
-- ([shift={(0,0)}]102.5:0.383) arc[radius=0.383cm, start angle=102.5, end angle=67.5] 
-- ([shift={(0.5,0)}]135:0.5)   arc[radius=0.5cm,   start angle=135,   end angle=180 ]  
-- cycle;

\draw [red, line width=0.57pt, cap=round, shorten <=-0.18em]  % 
    (102.5:0.383) arc[radius=0.383cm, start angle=102.5, end angle=67.5]
    ;

\end{tikzpicture}
\end{document}
0

Here's an approach in Metapost for comparison.

enter image description here

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);
path shape;
shape = buildcycle(halfcircle shifted 1/2 left, 
                   halfcircle scaled  3/4,
                   halfcircle shifted 1/2 right) scaled 3cm;

fill shape withcolor 3/4 white;
draw subpath(0,1) of shape dashed evenly;
draw subpath(2,4) of shape withcolor .67 red;
draw subpath(5,6) of shape dashed evenly;
endfig;
end.

I've used the subpath (t,u) of p notation where t and u represent the desired "time" along path p.

It can be a little tricky to figure out where MetaPost thinks the points are along a path that is created by buildcycle, but this case is typical in that there are two points at each corner. To determine exactly which points I wanted, I used a temporary loop to label them all:

for i=1 upto length(shape): dotlabel.top(decimal i, point i of shape); endfor

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .