Imported Upstream version 1.22.4
[platform/upstream/groff.git] / contrib / chem / chem.pic
1 # macros for chem
2         
3 # Source file position: <groff-source>/contrib/chem/chem.pic
4 # Installed position: <prefix>/share/groff/<version>/pic
5
6 # Copyright (C) 2006-2018 Free Software Foundation, Inc.
7 # Written by Brian Kernighan <http://cm.bell-labs.com/cm/cs/who/bwk>,
8 # modified by Bernd Warken <groff-bernd.warken-72@web.de>.
9
10 # This file is part of 'chem', which is part of 'groff'.
11
12 # 'groff' is free software; you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License (GPL) version 2 as
14 # published by the Free Software Foundation.
15
16 # 'groff' is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 # General Public License for more details.
20
21 # The license text for GPL2 is available in the internet at
22 # <http://www.gnu.org/licenses/gpl-2.0.html>.
23
24 ########################################################################
25
26 pi = 3.141592654
27 deg = 57.29578
28 # cr = 0.08             # radius of invis circle at ring vertices (see cr[vh])
29 # crh = 0.16; crw = 0.12 # ht & wid of invis ellipse around atoms at ring vertices
30 # dav = 0.015           # vertical shift up for atoms in atom macro
31
32 # atom(text, wid, ht, carbon position, crh, crw, dav)
33 define atom { [
34         T: $1 wid $2 ht $3-2*$7
35         C: ellipse invis ht $5 wid $6 at T.w + ($4,$7)
36         L: ellipse invis ht $5 wid $6 at T.w + (cwid/2,$7)
37         R: ellipse invis ht $5 wid $6 at T.e + (-cwid/2,$7)
38 ] }
39
40 # bond(length, angle in degrees, whatever)
41 define bond {
42         line $3 by ($1) * sin(($2)/deg), ($1) * cos(($2)/deg)
43 }
44
45 # fancy bonds:  r, theta, from/at
46 define doublebond {
47         line $3 invis by ($1) * sin(($2)/deg), ($1) * cos(($2)/deg)
48         V1: last line.start; V2: last line.end; dx = V2.x-V1.x; dy = V2.y-V1.y
49         norm = sqrt(dx*dx + dy*dy)
50         ny = dx * .02 / norm
51         nx = -dy * .02 / norm
52         line from V1 + (nx,ny) to V2 + (nx,ny)
53         line from V1 - (nx,ny) to V2 - (nx,ny)
54         move to V2
55 }
56 define triplebond {
57         line $3 invis by ($1) * sin(($2)/deg), ($1) * cos(($2)/deg)
58         V1: last line.start; V2: last line.end; dx = V2.x-V1.x; dy = V2.y-V1.y
59         norm = sqrt(dx*dx + dy*dy)
60         ny = dx * .025 / norm
61         nx = -dy * .025 / norm
62         line from V1 + (nx,ny) to V2 + (nx,ny)
63         line from V1 - (nx,ny) to V2 - (nx,ny)
64         line from V1 to V2
65         move to V2
66 }
67 define backbond {
68         line $3 invis by ($1) * sin(($2)/deg), ($1) * cos(($2)/deg)
69         V1: last line.start; V2: last line.end; dx = V2.x-V1.x; dy = V2.y-V1.y
70         norm = sqrt(dx*dx + dy*dy)
71         n = norm / .025
72         ny = dx * .02 / norm
73         nx = -dy * .02 / norm
74         for i = 1 to n-1 do {
75                 XZ: i/n <V1,V2>
76                 line from XZ + (nx,ny) to XZ - (nx,ny)
77         }
78         move to V2
79 }
80 define frontbond {
81         line $3 invis by ($1) * sin(($2)/deg), ($1) * cos(($2)/deg)
82         V1: last line.start; V2: last line.end; dx = V2.x-V1.x; dy = V2.y-V1.y
83         ah = arrowht; aw = arrowwid; ahead = arrowhead
84         arrowht = sqrt(dx*dx + dy*dy)
85         arrowwid = 0.05
86         arrowhead = 7
87         line <- from V1 to V2
88         arrowht = ah; arrowwid = aw; arrowhead = ahead
89 }
90 ### Emacs settings
91 # Local Variables:
92 # mode: Nroff
93 # End: