forked from skulumani/2018_JGCD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dumbbell.tikz
86 lines (73 loc) · 2.81 KB
/
dumbbell.tikz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
%% helper macros
\newcommand\pgfmathsinandcos[3]{%
\pgfmathsetmacro#1{sin(#3)}%
\pgfmathsetmacro#2{cos(#3)}%
}
\newcommand\LongitudePlane[3][current plane]{%
\pgfmathsinandcos\sinEl\cosEl{#2} % elevation
\pgfmathsinandcos\sint\cost{#3} % azimuth
\tikzset{#1/.style={cm={\cost,\sint*\sinEl,0,\cosEl,(0,0)}}}
}
\newcommand\LatitudePlane[3][current plane]{%
\pgfmathsinandcos\sinEl\cosEl{#2} % elevation
\pgfmathsinandcos\sint\cost{#3} % latitude
\pgfmathsetmacro\yshift{\cosEl*\sint}
\tikzset{#1/.style={cm={\cost,0,0,\cost*\sinEl,(0,\yshift)}}} %
}
\newcommand\DrawLongitudeCircle[4][1]{
\LongitudePlane{\angEl}{#2}
\tikzset{current plane/.prefix style={scale=#1}}
% angle of "visibility"
\pgfmathsetmacro\angVis{
atan(sin(#2)*cos(\angEl)/sin(\angEl))} %
\draw[shift={(#3, #4)}][current plane]
(\angVis:1) arc (\angVis:\angVis+180:1);
\draw[shift={(#3, #4)}][current plane,dashed]
(\angVis-180:1)arc(\angVis-180:\angVis:1);
}
\newcommand\DrawLatitudeCircle[4][1]{
\LatitudePlane{\angEl}{#2}
\tikzset{current plane/.prefix style={scale=#1}}
\pgfmathsetmacro\sinVis{
sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}
% angle of "visibility"
\pgfmathsetmacro\angVis{
asin(min(1,max(\sinVis,-1)))}
\draw[shift={(#3, #4)}][current plane]
(\angVis:1) arc (\angVis:-\angVis-180:1);
\draw[shift={(#3, #4)}][current plane,dashed]
(180-\angVis:1)arc(180-\angVis:\angVis:1);
}
%% document-wide tikz options and styles
\tikzset{%
>=latex, % option for nice arrows
inner sep=0pt,%
outer sep=2pt,%
mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=3pt,
fill=black,circle}%
}
\tikzsetnextfilename{dumbbell}
\begin{tikzpicture}[scale=0.8] % "THE GLOBE" showcase
\def\R{2} % sphere radius
\def\angEl{35} % elevation angle
\def\angAz{-105} % azimuth angle
\def\length{4} % distance from COM to M_1
\def\opacity{0.2}
% centers of the masses
\coordinate (m1) at (\length, 0);
\coordinate (m2) at (-\length, 0);
\draw [ thick, dashed, -Latex] (m2) -- ($ (m1) + (3, 0) $) node [below right] {$b_1$};
\draw [thick, dashed, -Latex] (0, 0) -- (0, \R) node [above right] {$b_2$};
% TODO Make a macro to draw a sphere at a sphefic point
\filldraw[ball color=blue, opacity=\opacity] (m1) circle (\R);
\foreach \t in {-45, 0, 45} { \DrawLatitudeCircle[\R]{\t}{\length}{0} }
\foreach \t in {-30, -60,...,-150} { \DrawLongitudeCircle[\R]{\t}{\length}{0} }
\filldraw[ball color=blue, opacity=\opacity] (m2) circle (\R);
\foreach \t in {-60,-30,...,60} { \DrawLatitudeCircle[\R]{\t}{-\length}{0} }
\foreach \t in {-5,-35,...,-175} { \DrawLongitudeCircle[\R]{\t}{-\length}{0} }
% draw from origin to center of m1
\draw[thick,-Latex] node [below right] {$\zeta$} (0, 0) -- (m1);
\draw[thick,-Latex] (m1) -- ++(30:\R) node [above right] {$\eta$};
% draw the radiaii of each mass
% \draw[thick,-Latex] (m1) -- ++(130:\R) node [above right] {$r_1$};
\end{tikzpicture}