As you may or may not have found out, tori are difficult to code precisely on a 2D surface (because it is a projection from 3D). In that spirit, I drew your picture as it is, just by trial and error, finding the right lengths. It's definitely not a clean way to do it, but I think it works for difficult pictures like this. No extra TikZ
packages are needed. Here is the code:
\begin{tikzpicture}[rotate=180]
%Torus
\draw (0,0) ellipse (1.6 and .9);
%Hole
\begin{scope}[scale=.8]
\path[rounded corners=24pt] (-.9,0)--(0,.6)--(.9,0) (-.9,0)--(0,-.56)--(.9,0);
\draw[rounded corners=28pt] (-1.1,.1)--(0,-.6)--(1.1,.1);
\draw[rounded corners=24pt] (-.9,0)--(0,.6)--(.9,0);
\end{scope}
%Cut 1
\draw[densely dashed] (0,-.9) arc (270:90:.2 and .365);
\draw (0,-.9) arc (-90:90:.2 and .365);
%Cut 2
\draw (0,.9) arc (90:270:.2 and .348);
\draw[densely dashed] (0,.9) arc (90:-90:.2 and .348);
\end{tikzpicture}
This is the result:
Some things I am displeased with in my code:
I drew the hole with the lips going the other way before I realized you had it your way. So I just put [rotate=180]
at the beginning instead of making the code appropriate. Just delete that to flip it back.
Initially the hole was too small, but it had kind of the right curvature. So I just scaled the whole hole until it looked better, hence the {scope}[scale=.8]
part.
I think the two half-solid-half-dashed cuts should both be both going the same way, personal opinion. But it's your picture, so there you go. If you do want to do that, cut and paste [densely dotted]
from one to the other lines of the same cut.
Conclusion: I have a bad (but visually OK) solution for a simple (but code-wise difficult) drawing.
The curve drawn by a to[bend left]
is probably a bezier curve, and thus is not an arc nor a parabola. Unfortunately this syntas hides the control points used.
Even if the control points were known, they won't be useful for your problem, since basically you want to get another bezier curve parallel to a "segment" or portion of another given bezier curve. I have no idea of the equations that should be solved to find those control points.
But not all hope is lost. I had a crazy idea. Once a bezier path is computed by tikz, any of its intermediate points are available via [pos]
key, so it is possible to find a number of those points, between the desired start and end point, and connect all of them via straight lines. If the points are close enough, the straight segments will not be visible and they will look like a curve.
So this is the proof of concept:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\thispagestyle{empty}
\usetikzlibrary{calc}
\begin{tikzpicture}
% First, define nodes
\draw (0,0) node[circle, inner sep=0.8pt, fill=black, label={below:{$E$}}] (E) {};
\draw (5,0) node[circle, inner sep=0.8pt, fill=black, label={below:{$F$}}] (F) {};
% Draw the curved line. No to[bend] is allowed, only explicit control points
\draw (E) .. controls +(1.9,1) and +(-1.9,1).. (F);
% Now, repeat the same curve, shifted up, and define 20 inner points named
% p1, p2, p3, etc.. for positions 0.15, 0.16, 0.17, etc up to 0.35 inside that curve
\path ($(E)+(0,0.2)$) .. controls +(1.9,1) and +(-1.9,1) .. ($(F)+(0, 0.2)$)
{\foreach \t [count=\i] in {0.15,0.16,...,0.35} { coordinate[pos=\t] (p\i) } };
% Finally draw the "curve" (polygonal line indeed) through those 20 inner points
\draw[->>] (p1) { \foreach \i in {1,...,20} {-- (p\i) } };
% A second example, with the same ideas but different path
\draw[red] (E) .. controls +(2,-2) and +(-3,-1).. (F);
\path ($(E)+(0,0.2)$) .. controls +(2,-2) and +(-3,-1).. ($(F)+(0, 0.2)$)
{\foreach \t [count=\i] in {0.15,0.16,...,0.55} { coordinate[pos=\t] (p\i) } };
\draw[red, ->>] (p1) { \foreach \i in {1,...,40} {-- (p\i) } };
\end{tikzpicture}
\end{document}
This is the result:
Update
A little refinement can be done in above code. Instead of specifying the foreach
loop as from 0.15
to 0.55
in steps of 0.1
, it looks more natural to simply specify the desired number of inner points (i.e: the "resolution" of the parallel curve), and let to some other expression to compute the pos
for each of those points. This is done like this:
\path ..curve specification..
{\foreach \i in {1,...,40} { coordinate[pos=0.15+0.55*\i/40] (p\i) } };
So, in this example, 40 intermediate points are computed, and the formula for the pos
key specifies 0.15 and 0.55 as the extremes of the parallel curve.
However, this approach does not use a "true" parallel line. The curve used to compute the points is simply the same orginal curve, only shifted in the Y axis. This could work for smooth arcs which are mostly horizontal, but it will fail for parts of the curve where the tangent is not so horizontal. Consider for example:
\begin{tikzpicture}
% First, define nodes
\draw (0,0) node[circle, inner sep=0.8pt, fill=black, label={below:{$E$}}] (E) {};
\draw (5,2) node[circle, inner sep=0.8pt, fill=black, label={below:{$F$}}] (F) {};
\draw[red] (E) .. controls +(5,-3) and +(-4,1).. (F);
\path ($(E)+(0,0.2)$) .. controls +(5,-3) and +(-4,1).. ($(F)+(0,0.2)$)
{\foreach \i in {1,...,40} { coordinate[pos=0.15+0.75*\i/40] (p\i) } };
\draw[blue, ->>] (p1) { \foreach \i in {1,...,40} {-- (p\i) } };
\end{tikzpicture}
This produces:
It can be seen that the distance between the red and blue lines is not constant. How can this be solved?
The following idea works: instead of shifting the curve, compute the sequence of points (p1)
, (p2)
etc. on the original curve. But then, when drawing the parallel line, do not use those points, but points which are at a fixed distance (eg: 0.2cm) from each of these points in the direction perpendicular to the curve. This direction can be computed as the vector from current point (p_i)
to next point (p_j)
, rotated 90 degrees.
Fortunately, tikz has the interpolated coordinates expression which allows for this with a simple formula: ($(p\i)!0.2cm!90:(p\j)$)
.
So, using this idea:
\begin{tikzpicture}
% First, define nodes
\draw (0,0) node[circle, inner sep=0.8pt, fill=black, label={below:{$E$}}] (E) {};
\draw (5,2) node[circle, inner sep=0.8pt, fill=black, label={below:{$F$}}] (F) {};
% Draw curved path
\draw[red] (E) .. controls +(5,-3) and +(-4,1).. (F);
% Compute points on the same curve
\path (E) .. controls +(5,-3) and +(-4,1).. (F)
{\foreach \i in {1,...,40} { coordinate[pos=0.15+0.75*\i/40] (p\i) } };
% Draw parallel curve
% (note that first and last points are specified out of the loop)
\draw[blue, ->>] ($(p1)!.2cm!90:(p2)$)
{ \foreach \i [count=\j from 3] in {2,...,39} {-- ($(p\i)!.2cm!90:(p\j)$) } }
-- ($(p40)!.2cm!-90:(p39)$);
\end{tikzpicture}
And this gives a perfect result!
Best Answer
Well, if all you want to do is to have a smooth curve that changes to a dashed pattern inside the box, just draw two curves with the
to[in=...,out=...]
syntax and make sure that the angles match, i.e. thein
of the incoming curve and theout
of the outgoing curve have to differ by180
.