summaryrefslogtreecommitdiff
path: root/contrib/chem/chem.pic
blob: 01a005493e055e567f7744d6600efa24d7d00246 (plain)
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
86
87
88
89
90
91
92
93
94
# macros for chem
	
# Source file position: <groff-source>/contrib/chem/chem.pic
# Installed position: <prefix>/share/groff/<version>/pic

# Copyright (C) 2006, 2008 Free Software Foundation, Inc.
# Written by Brian Kernighan <http://cm.bell-labs.com/cm/cs/who/bwk>,
# modified by Bernd Warken.

# This file is part of `chem', which is part of `groff'.

# `groff' is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# `groff' is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

########################################################################

pi = 3.141592654
deg = 57.29578
# cr = 0.08		# radius of invis circle at ring vertices (see cr[vh])
# crh = 0.16; crw = 0.12 # ht & wid of invis ellipse around atoms at ring vertices
# dav = 0.015		# vertical shift up for atoms in atom macro

# atom(text, wid, ht, carbon position, crh, crw, dav)
define atom { [
	T: $1 wid $2 ht $3-2*$7
	C: ellipse invis ht $5 wid $6 at T.w + ($4,$7)
	L: ellipse invis ht $5 wid $6 at T.w + (cwid/2,$7)
	R: ellipse invis ht $5 wid $6 at T.e + (-cwid/2,$7)
] }

# bond(length, angle in degrees, whatever)
define bond {
	line $3 by ($1) * sin(($2)/deg), ($1) * cos(($2)/deg)
}

# fancy bonds:  r, theta, from/at
define doublebond {
	line $3 invis by ($1) * sin(($2)/deg), ($1) * cos(($2)/deg)
	V1: last line.start; V2: last line.end; dx = V2.x-V1.x; dy = V2.y-V1.y
	norm = sqrt(dx*dx + dy*dy)
	ny = dx * .02 / norm
	nx = -dy * .02 / norm
	line from V1 + (nx,ny) to V2 + (nx,ny)
	line from V1 - (nx,ny) to V2 - (nx,ny)
	move to V2
}
define triplebond {
	line $3 invis by ($1) * sin(($2)/deg), ($1) * cos(($2)/deg)
	V1: last line.start; V2: last line.end; dx = V2.x-V1.x; dy = V2.y-V1.y
	norm = sqrt(dx*dx + dy*dy)
	ny = dx * .025 / norm
	nx = -dy * .025 / norm
	line from V1 + (nx,ny) to V2 + (nx,ny)
	line from V1 - (nx,ny) to V2 - (nx,ny)
	line from V1 to V2
	move to V2
}
define backbond {
	line $3 invis by ($1) * sin(($2)/deg), ($1) * cos(($2)/deg)
	V1: last line.start; V2: last line.end; dx = V2.x-V1.x; dy = V2.y-V1.y
	norm = sqrt(dx*dx + dy*dy)
	n = norm / .025
	ny = dx * .02 / norm
	nx = -dy * .02 / norm
	for i = 1 to n-1 do {
		XZ: i/n <V1,V2>
		line from XZ + (nx,ny) to XZ - (nx,ny)
	}
	move to V2
}
define frontbond {
	line $3 invis by ($1) * sin(($2)/deg), ($1) * cos(($2)/deg)
	V1: last line.start; V2: last line.end; dx = V2.x-V1.x; dy = V2.y-V1.y
	ah = arrowht; aw = arrowwid; ahead = arrowhead
	arrowht = sqrt(dx*dx + dy*dy)
	arrowwid = 0.05
	arrowhead = 7
	line <- from V1 to V2
	arrowht = ah; arrowwid = aw; arrowhead = ahead
}
### Emacs settings
# Local Variables:
# mode: Nroff
# End: