# macros for chem
	
# Source file position: <groff-source>/contrib/chem/chem.pic
# Installed position: <prefix>/share/groff/<version>/pic

# Copyright (C) 2006-2014 Free Software Foundation, Inc.
# Written by Brian Kernighan <http://cm.bell-labs.com/cm/cs/who/bwk>,
# modified by Bernd Warken <groff-bernd.warken-72@web.de>.

# 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 (GPL) version 2 as
# published by the Free Software Foundation.

# `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.

# The license text for GPL2 is available in the internet at
# <http://www.gnu.org/licenses/gpl-2.0.html>.

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

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:
