This script provides methods that create
cgos as triangles. It uses code that is ported from
this c++ code and seems to be correct!
Here is the script. The last four lines show this in use, by making an ellipse and a toroid and loading them into pymol. This is done most easily by something like "cmd.load_cgo(makeEllipsoid(1, 1, 1, 2, 3, 4), 'ellipsoid')" which makes an ellipsoid at x, y, z = 1, 1, 1 and dimensions 2, 3, 4 and called 'ellipsoid'.
<source lang="python">
from pymol.cgo import BEGIN, COLOR, TRIANGLES, VERTEX, NORMAL, END
from pymol import cmd
def signOfFloat(f):
if f < 0: return -1
if f > 0: return 1
return 0
def sqC(v, n):
return signOfFloat(math.cos(v)) * math.pow(math.fabs(math.cos(v)), n)
def sqCT(v, n, alpha):
return alpha + sqC(v, n)
def sqS(v, n):
return signOfFloat(math.sin(v)) * math.pow(math.fabs(math.sin(v)), n)
def sqEllipsoid(x, y, z, a1, a2, a3, u, v, n, e):
x = a1 * sqC(u, n) * ..→