Solutions to the exercises of part 1

Printing the center of mass:

from Scientific.Geometry import Vector

a = Vector(0, 1, 0)
b = Vector(4.3, -2.4, 0.005)
c = Vector(-3.2, 5.1, -3.)

print (a+b+c)/3
A correct but very bad solution would be adding the three components separately.

Printing the angles:

from Scientific.Geometry import Vector

a = Vector(0, 1, 0)
b = Vector(4.3, -2.4, 0.005)
c = Vector(-3.2, 5.1, -3.)

print "Angle a-b-c:", (a-b).angle(c-b)
print "Angle c-a-b:", (c-a).angle(b-a)
print "Angle b-c-a:", (b-c).angle(a-c)
An easy way to check this program is to add up the angles; the sum must be pi.
Table of Contents